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.gd77
1 files changed, 63 insertions, 14 deletions
diff --git a/apworld/client/client.gd b/apworld/client/client.gd index 67edf29..a23e85a 100644 --- a/apworld/client/client.gd +++ b/apworld/client/client.gd
@@ -18,9 +18,12 @@ var _seed = ""
18var _team = 0 18var _team = 0
19var _slot = 0 19var _slot = 0
20var _checked_locations = [] 20var _checked_locations = []
21var _checked_worldports = []
21var _received_indexes = [] 22var _received_indexes = []
22var _received_items = {} 23var _received_items = {}
23var _slot_data = {} 24var _slot_data = {}
25var _accessible_locations = []
26var _accessible_worldports = []
24 27
25signal could_not_connect 28signal could_not_connect
26signal connect_status 29signal connect_status
@@ -30,6 +33,10 @@ signal location_scout_received(location_id, item_name, player_name, flags, for_s
30signal text_message_received(message) 33signal text_message_received(message)
31signal item_sent_notification(message) 34signal item_sent_notification(message)
32signal hint_received(message) 35signal hint_received(message)
36signal accessible_locations_updated
37signal checked_locations_updated
38signal checked_worldports_updated
39signal keyboard_update_received
33 40
34 41
35func _init(): 42func _init():
@@ -51,6 +58,9 @@ func _reset_state():
51 _should_process = false 58 _should_process = false
52 _received_items = {} 59 _received_items = {}
53 _received_indexes = [] 60 _received_indexes = []
61 _checked_worldports = []
62 _accessible_locations = []
63 _accessible_worldports = []
54 64
55 65
56func disconnect_from_ap(): 66func disconnect_from_ap():
@@ -92,15 +102,34 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
92 _gen_version = message["generator_version"] 102 _gen_version = message["generator_version"]
93 _team = message["team"] 103 _team = message["team"]
94 _slot = message["slot"] 104 _slot = message["slot"]
95 _checked_locations = message["checked_locations"]
96 _slot_data = message["slot_data"] 105 _slot_data = message["slot_data"]
97 106
107 _checked_locations = []
108 for location in message["checked_locations"]:
109 _checked_locations.append(int(message["checked_locations"]))
110
98 client_connected.emit(_slot_data) 111 client_connected.emit(_slot_data)
99 112
100 elif cmd == "ConnectionRefused": 113 elif cmd == "ConnectionRefused":
101 could_not_connect.emit(message["text"]) 114 could_not_connect.emit(message["text"])
102 global._print("Connection to AP refused") 115 global._print("Connection to AP refused")
103 116
117 elif cmd == "UpdateLocations":
118 for location in message["locations"]:
119 var lint = int(location)
120 if not _checked_locations.has(lint):
121 _checked_locations.append(lint)
122
123 checked_locations_updated.emit()
124
125 elif cmd == "UpdateWorldports":
126 for port_id in message["worldports"]:
127 var lint = int(port_id)
128 if not _checked_worldports.has(lint):
129 _checked_worldports.append(lint)
130
131 checked_worldports_updated.emit()
132
104 elif cmd == "ItemReceived": 133 elif cmd == "ItemReceived":
105 for item in message["items"]: 134 for item in message["items"]:
106 var index = int(item["index"]) 135 var index = int(item["index"])
@@ -134,6 +163,26 @@ func _on_web_socket_server_message_received(_peer_id: int, packet: String) -> vo
134 int(loc["for_self"]) 163 int(loc["for_self"])
135 ) 164 )
136 165
166 elif cmd == "AccessibleLocations":
167 _accessible_locations.clear()
168 _accessible_worldports.clear()
169
170 for loc in message["locations"]:
171 _accessible_locations.append(int(loc))
172
173 if "worldports" in message:
174 for port_id in message["worldports"]:
175 _accessible_worldports.append(int(port_id))
176
177 accessible_locations_updated.emit()
178
179 elif cmd == "UpdateKeyboard":
180 var updates = {}
181 for k in message["updates"]:
182 updates[k] = int(message["updates"][k])
183
184 keyboard_update_received.emit(updates)
185
137 186
138func connectToServer(server, un, pw): 187func connectToServer(server, un, pw):
139 sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}]) 188 sendMessage([{"cmd": "Connect", "server": server, "player": un, "password": pw}])
@@ -179,19 +228,6 @@ func sendLocations(loc_ids):
179 sendMessage([{"cmd": "LocationChecks", "locations": loc_ids}]) 228 sendMessage([{"cmd": "LocationChecks", "locations": loc_ids}])
180 229
181 230
182func setValue(key, value, operation = "replace"):
183 sendMessage(
184 [
185 {
186 "cmd": "Set",
187 "key": "Lingo2_%d_%s" % [_slot, key],
188 "want_reply": false,
189 "operations": [{"operation": operation, "value": value}]
190 }
191 ]
192 )
193
194
195func say(textdata): 231func say(textdata):
196 sendMessage([{"cmd": "Say", "text": textdata}]) 232 sendMessage([{"cmd": "Say", "text": textdata}])
197 233
@@ -204,6 +240,19 @@ func scoutLocations(loc_ids):
204 sendMessage([{"cmd": "LocationScouts", "locations": loc_ids}]) 240 sendMessage([{"cmd": "LocationScouts", "locations": loc_ids}])
205 241
206 242
243func updateKeyboard(updates):
244 sendMessage([{"cmd": "UpdateKeyboard", "keyboard": updates}])
245
246
247func checkWorldport(port_id):
248 if not _checked_worldports.has(port_id):
249 sendMessage([{"cmd": "CheckWorldport", "port_id": port_id}])
250
251
252func sendQuit():
253 sendMessage([{"cmd": "Quit"}])
254
255
207func hasItem(item_id): 256func hasItem(item_id):
208 return _received_items.has(item_id) 257 return _received_items.has(item_id)
209 258