about summary refs log tree commit diff stats
path: root/apworld/client/client.gd
diff options
context:
space:
mode:
Diffstat (limited to 'apworld/client/client.gd')
-rw-r--r--apworld/client/client.gd69
1 files changed, 63 insertions, 6 deletions
diff --git a/apworld/client/client.gd b/apworld/client/client.gd index a23e85a..c149482 100644 --- a/apworld/client/client.gd +++ b/apworld/client/client.gd
@@ -24,6 +24,9 @@ var _received_items = {}
24var _slot_data = {} 24var _slot_data = {}
25var _accessible_locations = [] 25var _accessible_locations = []
26var _accessible_worldports = [] 26var _accessible_worldports = []
27var _goal_accessible = false
28var _latched_doors = []
29var _hinted_locations = []
27 30
28signal could_not_connect 31signal could_not_connect
29signal connect_status 32signal connect_status
@@ -33,10 +36,13 @@ signal location_scout_received(location_id, item_name, player_name, flags, for_s
33signal text_message_received(message) 36signal text_message_received(message)
34signal item_sent_notification(message) 37signal item_sent_notification(message)
35signal hint_received(message) 38signal hint_received(message)
39signal door_latched(id)
36signal accessible_locations_updated 40signal accessible_locations_updated
37signal checked_locations_updated 41signal checked_locations_updated
42signal ignored_locations_updated(locations)
38signal checked_worldports_updated 43signal checked_worldports_updated
39signal keyboard_update_received 44signal keyboard_update_received
45signal hinted_locations_updated
40 46
41 47
42func _init(): 48func _init():
@@ -61,6 +67,7 @@ func _reset_state():
61 _checked_worldports = [] 67 _checked_worldports = []
62 _accessible_locations = [] 68 _accessible_locations = []
63 _accessible_worldports = [] 69 _accessible_worldports = []
70 _goal_accessible = false
64 71
65 72
66func disconnect_from_ap(): 73func disconnect_from_ap():
@@ -106,7 +113,7 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
106 113
107 _checked_locations = [] 114 _checked_locations = []
108 for location in message["checked_locations"]: 115 for location in message["checked_locations"]:
109 _checked_locations.append(int(message["checked_locations"])) 116 _checked_locations.append(int(location))
110 117
111 client_connected.emit(_slot_data) 118 client_connected.emit(_slot_data)
112 119
@@ -156,11 +163,7 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
156 elif cmd == "LocationInfo": 163 elif cmd == "LocationInfo":
157 for loc in message["locations"]: 164 for loc in message["locations"]:
158 location_scout_received.emit( 165 location_scout_received.emit(
159 int(loc["id"]), 166 int(loc["id"]), loc["item"], loc["player"], int(loc["flags"]), int(loc["self"])
160 loc["item"],
161 loc["player"],
162 int(loc["flags"]),
163 int(loc["for_self"])
164 ) 167 )
165 168
166 elif cmd == "AccessibleLocations": 169 elif cmd == "AccessibleLocations":
@@ -174,6 +177,8 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
174 for port_id in message["worldports"]: 177 for port_id in message["worldports"]:
175 _accessible_worldports.append(int(port_id)) 178 _accessible_worldports.append(int(port_id))
176 179
180 _goal_accessible = bool(message.get("goal", false))
181
177 accessible_locations_updated.emit() 182 accessible_locations_updated.emit()
178 183
179 elif cmd == "UpdateKeyboard": 184 elif cmd == "UpdateKeyboard":
@@ -183,6 +188,35 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
183 188
184 keyboard_update_received.emit(updates) 189 keyboard_update_received.emit(updates)
185 190
191 elif cmd == "PathReply":
192 var textclient = global.get_node("Textclient")
193 textclient.display_logical_path(
194 message["type"], int(message.get("id", null)), message["path"]
195 )
196
197 elif cmd == "UpdateLatches":
198 for id in message["latches"]:
199 var iid = int(id)
200 if not _latched_doors.has(iid):
201 _latched_doors.append(iid)
202
203 door_latched.emit(iid)
204
205 elif cmd == "SetIgnoredLocations":
206 var locs = []
207 for id in message["locations"]:
208 locs.append(int(id))
209
210 ignored_locations_updated.emit(locs)
211
212 elif cmd == "UpdateHintedLocations":
213 for id in message["locations"]:
214 var iid = int(id)
215 if !_hinted_locations.has(iid):
216 _hinted_locations.append(iid)
217
218 hinted_locations_updated.emit()
219
186 220
187func connectToServer(server, un, pw): 221func connectToServer(server, un, pw):
188 sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}]) 222 sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}])
@@ -249,6 +283,29 @@ func checkWorldport(port_id):
249 sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}]) 283 sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}])
250 284
251 285
286func latchDoor(id):
287 if not _latched_doors.has(id):
288 _latched_doors.append(id)
289
290 sendMessage([{"cmd": "LatchDoor", "door": id}])
291
292
293func getLogicalPath(object_type, object_id):
294 var msg = {"cmd": "GetPath", "type": object_type}
295 if object_id != null:
296 msg["id"] = object_id
297
298 sendMessage([msg])
299
300
301func addIgnoredLocation(loc_id):
302 sendMessage([{"cmd": "IgnoreLocation", "id": loc_id}])
303
304
305func removeIgnoredLocation(loc_id):
306 sendMessage([{"cmd": "UnignoreLocation", "id": loc_id}])
307
308
252func sendQuit(): 309func sendQuit():
253 sendMessage([{"cmd": "Quit"}]) 310 sendMessage([{"cmd": "Quit"}])
254 311