diff options
Diffstat (limited to 'Archipelago/client.gd')
| -rw-r--r-- | Archipelago/client.gd | 61 |
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 = [] | |||
| 30 | var _painting_ids_by_item = {} | 30 | var _painting_ids_by_item = {} |
| 31 | var _mentioned_paintings = [] | 31 | var _mentioned_paintings = [] |
| 32 | var _panel_ids_by_location = {} | 32 | var _panel_ids_by_location = {} |
| 33 | var _localdata_file = "" | ||
| 33 | 34 | ||
| 34 | var _map_loaded = false | 35 | var _map_loaded = false |
| 35 | var _held_items = [] | 36 | var _held_items = [] |
| 36 | var _held_locations = [] | 37 | var _held_locations = [] |
| 38 | var _last_new_item = -1 | ||
| 37 | var _tower_floors = 0 | 39 | var _tower_floors = 0 |
| 38 | 40 | ||
| 39 | signal client_connected | 41 | signal 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 | ||
| 160 | func _process(_delta): | 182 | func _process(_delta): |
| @@ -181,6 +203,23 @@ func saveSettings(): | |||
| 181 | file.close() | 203 | file.close() |
| 182 | 204 | ||
| 183 | 205 | ||
| 206 | func 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 | |||
| 184 | func getSaveFileName(): | 223 | func getSaveFileName(): |
| 185 | return "zzAP_%s_%d" % [_seed, _slot] | 224 | return "zzAP_%s_%d" % [_seed, _slot] |
| 186 | 225 | ||
| @@ -229,6 +268,9 @@ func requestSync(): | |||
| 229 | func sendLocation(loc_id): | 268 | func 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(): | |||
| 240 | func mapFinishedLoading(): | 282 | func 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 | ||
| 252 | func processItem(item): | 294 | func 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 | ||
| 274 | func doorIsVanilla(door): | 327 | func doorIsVanilla(door): |
| 275 | return !_mentioned_doors.has(door) | 328 | return !_mentioned_doors.has(door) |
