about summary refs log tree commit diff stats
path: root/Archipelago/client.gd
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-04-14 11:32:40 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-04-14 11:32:40 -0400
commitdeab7140f9415f0f5fea9240a291b976e507593f (patch)
tree1ce784f6b89bd6560fff3367a9ffe3891e6edfe8 /Archipelago/client.gd
parentce9cc1c0ef41d342802798cad51d6dbe6ae49fe4 (diff)
downloadlingo-archipelago-deab7140f9415f0f5fea9240a291b976e507593f.tar.gz
lingo-archipelago-deab7140f9415f0f5fea9240a291b976e507593f.tar.bz2
lingo-archipelago-deab7140f9415f0f5fea9240a291b976e507593f.zip
Created rudimentary message display
It shows when the player sends a location or receives an item. Currently it just shows IDs instead of names. We need to download all data packages so that we can read the names. We are also currently queueing a message when we send a location, which isn't the best because if that location turns out to contain an item for us, we'll get two messages. It would be better to hold off until we receive a PrintJSON message describing the location that was sent out.

We also now cache the ID of the most recently processed item, so that on relaunch we know which items are new and should be announced.
Diffstat (limited to 'Archipelago/client.gd')
-rw-r--r--Archipelago/client.gd61
1 files changed, 57 insertions, 4 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index e8f9bba..be0ef2d 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd
@@ -30,10 +30,12 @@ var _mentioned_doors = []
30var _painting_ids_by_item = {} 30var _painting_ids_by_item = {}
31var _mentioned_paintings = [] 31var _mentioned_paintings = []
32var _panel_ids_by_location = {} 32var _panel_ids_by_location = {}
33var _localdata_file = ""
33 34
34var _map_loaded = false 35var _map_loaded = false
35var _held_items = [] 36var _held_items = []
36var _held_locations = [] 37var _held_locations = []
38var _last_new_item = -1
37var _tower_floors = 0 39var _tower_floors = 0
38 40
39signal client_connected 41signal client_connected
@@ -135,6 +137,18 @@ func _on_data():
135 if _slot_data.has("panel_ids_by_location_id"): 137 if _slot_data.has("panel_ids_by_location_id"):
136 _panel_ids_by_location = _slot_data["panel_ids_by_location_id"] 138 _panel_ids_by_location = _slot_data["panel_ids_by_location_id"]
137 139
140 _localdata_file = "user://archipelago/%s_%d" % [_seed, _slot]
141 var ap_file = File.new()
142 if ap_file.file_exists(_localdata_file):
143 ap_file.open(_localdata_file, File.READ)
144 var localdata = ap_file.get_var(true)
145 ap_file.close()
146
147 if localdata.size() > 0:
148 _last_new_item = localdata[0]
149 else:
150 _last_new_item = -1
151
138 requestSync() 152 requestSync()
139 153
140 emit_signal("client_connected") 154 emit_signal("client_connected")
@@ -150,11 +164,19 @@ func _on_data():
150 _tower_floors = 0 164 _tower_floors = 0
151 _held_items = [] 165 _held_items = []
152 166
167 var i = 0
153 for item in message["items"]: 168 for item in message["items"]:
154 if _map_loaded: 169 if _map_loaded:
155 processItem(item["item"]) 170 processItem(item["item"], message["index"] + i, item["player"])
156 else: 171 else:
157 _held_items.append(item["item"]) 172 _held_items.append(
173 {
174 "item": item["item"],
175 "index": message["index"] + i,
176 "from": item["player"]
177 }
178 )
179 i += 1
158 180
159 181
160func _process(_delta): 182func _process(_delta):
@@ -181,6 +203,23 @@ func saveSettings():
181 file.close() 203 file.close()
182 204
183 205
206func saveLocaldata():
207 # Save the MW/slot specific settings to disk.
208 var dir = Directory.new()
209 var path = "user://archipelago"
210 if dir.dir_exists(path):
211 pass
212 else:
213 dir.make_dir(path)
214
215 var file = File.new()
216 file.open(_localdata_file, File.WRITE)
217
218 var data = [_last_new_item]
219 file.store_var(data, true)
220 file.close()
221
222
184func getSaveFileName(): 223func getSaveFileName():
185 return "zzAP_%s_%d" % [_seed, _slot] 224 return "zzAP_%s_%d" % [_seed, _slot]
186 225
@@ -229,6 +268,9 @@ func requestSync():
229func sendLocation(loc_id): 268func sendLocation(loc_id):
230 if _map_loaded: 269 if _map_loaded:
231 sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}]) 270 sendMessage([{"cmd": "LocationChecks", "locations": [loc_id]}])
271
272 var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages")
273 messages_node.showMessage("Sent %d" % loc_id)
232 else: 274 else:
233 _held_locations.append(loc_id) 275 _held_locations.append(loc_id)
234 276
@@ -240,7 +282,7 @@ func completedGoal():
240func mapFinishedLoading(): 282func mapFinishedLoading():
241 if !_map_loaded: 283 if !_map_loaded:
242 for item in _held_items: 284 for item in _held_items:
243 processItem(item) 285 processItem(item["item"], item["index"], item["from"])
244 286
245 sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}]) 287 sendMessage([{"cmd": "LocationChecks", "locations": _held_locations}])
246 288
@@ -249,7 +291,7 @@ func mapFinishedLoading():
249 _held_locations = [] 291 _held_locations = []
250 292
251 293
252func processItem(item): 294func processItem(item, index, from):
253 global._print(item) 295 global._print(item)
254 296
255 var stringified = String(item) 297 var stringified = String(item)
@@ -270,6 +312,17 @@ func processItem(item):
270 processItem(_item_name_to_id[subitem_name]) 312 processItem(_item_name_to_id[subitem_name])
271 _tower_floors += 1 313 _tower_floors += 1
272 314
315 # Show a message about the item if it's new.
316 if index > _last_new_item:
317 _last_new_item = index
318 saveLocaldata()
319
320 var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages")
321 if from == _slot:
322 messages_node.showMessage("Found %d" % item)
323 else:
324 messages_node.showMessage("Received %d from %d" % [item, from])
325
273 326
274func doorIsVanilla(door): 327func doorIsVanilla(door):
275 return !_mentioned_doors.has(door) 328 return !_mentioned_doors.has(door)