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 21:06:25 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-04-14 21:06:25 -0400
commit63b533abf71de77eec7e0f9f0781dd687fd1ae40 (patch)
treef784dbbdcb48ccc989ad5e8975480018d1eebc37 /Archipelago/client.gd
parentdeab7140f9415f0f5fea9240a291b976e507593f (diff)
downloadlingo-archipelago-63b533abf71de77eec7e0f9f0781dd687fd1ae40.tar.gz
lingo-archipelago-63b533abf71de77eec7e0f9f0781dd687fd1ae40.tar.bz2
lingo-archipelago-63b533abf71de77eec7e0f9f0781dd687fd1ae40.zip
Receiving items shows the right name now
(Sending checks doesn't)
Diffstat (limited to 'Archipelago/client.gd')
-rw-r--r--Archipelago/client.gd76
1 files changed, 46 insertions, 30 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index be0ef2d..335871e 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd
@@ -11,9 +11,10 @@ var _client = WebSocketClient.new()
11var _last_state = WebSocketPeer.STATE_CLOSED 11var _last_state = WebSocketPeer.STATE_CLOSED
12var _should_process = false 12var _should_process = false
13 13
14var _datapackage_checksum = "" 14var _datapackages = {}
15var _item_name_to_id = {} 15var _item_id_to_name = {} # All games
16var _location_name_to_id = {} 16var _item_name_to_id = {} # LINGO only
17var _location_name_to_id = {} # LINGO only
17 18
18const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd") 19const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd")
19 20
@@ -58,11 +59,9 @@ func _init():
58 if data.size() > 2: 59 if data.size() > 2:
59 ap_pass = data[2] 60 ap_pass = data[2]
60 if data.size() > 3: 61 if data.size() > 3:
61 _datapackage_checksum = data[3] 62 _datapackages = data[3]
62 if data.size() > 4: 63
63 _item_name_to_id = data[4] 64 processDatapackages()
64 if data.size() > 5:
65 _location_name_to_id = data[5]
66 65
67 66
68func _ready(): 67func _ready():
@@ -96,22 +95,26 @@ func _on_data():
96 95
97 if cmd == "RoomInfo": 96 if cmd == "RoomInfo":
98 _seed = message["seed_name"] 97 _seed = message["seed_name"]
99 if message["datapackage_checksums"].has("Lingo"):
100 if _datapackage_checksum != message["datapackage_checksums"]["Lingo"]:
101 requestDatapackage()
102 else:
103 connectToRoom()
104
105 elif cmd == "DataPackage":
106 if message["data"]["games"].has("Lingo"):
107 var lingo_pkg = message["data"]["games"]["Lingo"]
108 _datapackage_checksum = lingo_pkg["checksum"]
109 _item_name_to_id = lingo_pkg["item_name_to_id"]
110 _location_name_to_id = lingo_pkg["location_name_to_id"]
111 saveSettings()
112 98
99 var needed_games = []
100 for game in message["datapackage_checksums"].keys():
101 if (
102 !_datapackages.has(game)
103 or _datapackages[game]["checksum"] != message["datapackage_checksums"][game]
104 ):
105 needed_games.append(game)
106
107 if !needed_games.empty():
108 requestDatapackages(needed_games)
109 else:
113 connectToRoom() 110 connectToRoom()
114 111
112 elif cmd == "DataPackage":
113 _datapackages = message["data"]["games"]
114 saveSettings()
115 processDatapackages()
116 connectToRoom()
117
115 elif cmd == "Connected": 118 elif cmd == "Connected":
116 _authenticated = true 119 _authenticated = true
117 _team = message["team"] 120 _team = message["team"]
@@ -196,9 +199,7 @@ func saveSettings():
196 var file = File.new() 199 var file = File.new()
197 file.open("user://settings/archipelago", File.WRITE) 200 file.open("user://settings/archipelago", File.WRITE)
198 201
199 var data = [ 202 var data = [ap_server, ap_user, ap_pass, _datapackages]
200 ap_server, ap_user, ap_pass, _datapackage_checksum, _item_name_to_id, _location_name_to_id
201 ]
202 file.store_var(data, true) 203 file.store_var(data, true)
203 file.close() 204 file.close()
204 205
@@ -239,8 +240,19 @@ func sendMessage(msg):
239 _client.get_peer(1).put_packet(payload.to_utf8()) 240 _client.get_peer(1).put_packet(payload.to_utf8())
240 241
241 242
242func requestDatapackage(): 243func requestDatapackages(games):
243 sendMessage([{"cmd": "GetDataPackage", "games": ["Lingo"]}]) 244 sendMessage([{"cmd": "GetDataPackage", "games": games}])
245
246
247func processDatapackages():
248 _item_id_to_name = {}
249 for package in _datapackages.values():
250 for name in package["item_name_to_id"].keys():
251 _item_id_to_name[package["item_name_to_id"][name]] = name
252
253 if _datapackages.has("Lingo"):
254 _item_name_to_id = _datapackages["Lingo"]["item_name_to_id"]
255 _location_name_to_id = _datapackages["Lingo"]["location_name_to_id"]
244 256
245 257
246func connectToRoom(): 258func connectToRoom():
@@ -309,19 +321,23 @@ func processItem(item, index, from):
309 if _item_name_to_id["Progressive Orange Tower"] == item and _tower_floors < orange_tower.size(): 321 if _item_name_to_id["Progressive Orange Tower"] == item and _tower_floors < orange_tower.size():
310 var subitem_name = "Orange Tower - %s Floor" % orange_tower[_tower_floors] 322 var subitem_name = "Orange Tower - %s Floor" % orange_tower[_tower_floors]
311 global._print(subitem_name) 323 global._print(subitem_name)
312 processItem(_item_name_to_id[subitem_name]) 324 processItem(_item_name_to_id[subitem_name], null)
313 _tower_floors += 1 325 _tower_floors += 1
314 326
315 # Show a message about the item if it's new. 327 # Show a message about the item if it's new.
316 if index > _last_new_item: 328 if index != null and index > _last_new_item:
317 _last_new_item = index 329 _last_new_item = index
318 saveLocaldata() 330 saveLocaldata()
319 331
332 var item_name = "Unknown"
333 if _item_id_to_name.has(item):
334 item_name = _item_id_to_name[item]
335
320 var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages") 336 var messages_node = get_tree().get_root().get_node("Spatial/AP_Messages")
321 if from == _slot: 337 if from == _slot:
322 messages_node.showMessage("Found %d" % item) 338 messages_node.showMessage("Found %s" % item_name)
323 else: 339 else:
324 messages_node.showMessage("Received %d from %d" % [item, from]) 340 messages_node.showMessage("Received %s from %d" % [item_name, from])
325 341
326 342
327func doorIsVanilla(door): 343func doorIsVanilla(door):