diff options
Diffstat (limited to 'apworld/client/manager.gd')
| -rw-r--r-- | apworld/client/manager.gd | 167 |
1 files changed, 161 insertions, 6 deletions
| diff --git a/apworld/client/manager.gd b/apworld/client/manager.gd index 5b731d2..8c981f9 100644 --- a/apworld/client/manager.gd +++ b/apworld/client/manager.gd | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | extends Node | 1 | extends Node |
| 2 | 2 | ||
| 3 | const MOD_VERSION = 7 | ||
| 4 | |||
| 5 | var SCRIPT_client | 3 | var SCRIPT_client |
| 6 | var SCRIPT_keyboard | 4 | var SCRIPT_keyboard |
| 7 | var SCRIPT_locationListener | 5 | var SCRIPT_locationListener |
| @@ -30,6 +28,9 @@ var _item_locks = {} | |||
| 30 | var _inverse_item_locks = {} | 28 | var _inverse_item_locks = {} |
| 31 | var _held_letters = {} | 29 | var _held_letters = {} |
| 32 | var _letters_setup = false | 30 | var _letters_setup = false |
| 31 | var _already_connected = false | ||
| 32 | var _ignored_locations = [] | ||
| 33 | var _map_scripts = {} | ||
| 33 | 34 | ||
| 34 | const kSHUFFLE_LETTERS_VANILLA = 0 | 35 | const kSHUFFLE_LETTERS_VANILLA = 0 |
| 35 | const kSHUFFLE_LETTERS_UNLOCKED = 1 | 36 | const kSHUFFLE_LETTERS_UNLOCKED = 1 |
| @@ -45,10 +46,30 @@ const kCYAN_DOOR_BEHAVIOR_H2 = 0 | |||
| 45 | const kCYAN_DOOR_BEHAVIOR_DOUBLE_LETTER = 1 | 46 | const kCYAN_DOOR_BEHAVIOR_DOUBLE_LETTER = 1 |
| 46 | const kCYAN_DOOR_BEHAVIOR_ITEM = 2 | 47 | const kCYAN_DOOR_BEHAVIOR_ITEM = 2 |
| 47 | 48 | ||
| 48 | var apworld_version = [0, 0] | 49 | const kEndingNameByVictoryValue = { |
| 50 | 0: "GRAY", | ||
| 51 | 1: "PURPLE", | ||
| 52 | 2: "MINT", | ||
| 53 | 3: "BLACK", | ||
| 54 | 4: "BLUE", | ||
| 55 | 5: "CYAN", | ||
| 56 | 6: "RED", | ||
| 57 | 7: "PLUM", | ||
| 58 | 8: "ORANGE", | ||
| 59 | 9: "GOLD", | ||
| 60 | 10: "YELLOW", | ||
| 61 | 11: "GREEN", | ||
| 62 | 12: "WHITE", | ||
| 63 | } | ||
| 64 | |||
| 65 | var apworld_version = [0, 0, 0] | ||
| 49 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 | 66 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 |
| 50 | var daedalus_roof_access = false | 67 | var daedalus_roof_access = false |
| 68 | var enable_gift_maps = [] | ||
| 69 | var enable_icarus = false | ||
| 70 | var endings_requirement = 0 | ||
| 51 | var keyholder_sanity = false | 71 | var keyholder_sanity = false |
| 72 | var masteries_requirement = 0 | ||
| 52 | var port_pairings = {} | 73 | var port_pairings = {} |
| 53 | var shuffle_control_center_colors = false | 74 | var shuffle_control_center_colors = false |
| 54 | var shuffle_doors = false | 75 | var shuffle_doors = false |
| @@ -60,6 +81,8 @@ var strict_cyan_ending = false | |||
| 60 | var strict_purple_ending = false | 81 | var strict_purple_ending = false |
| 61 | var victory_condition = -1 | 82 | var victory_condition = -1 |
| 62 | 83 | ||
| 84 | var color_by_material_path = {} | ||
| 85 | |||
| 63 | signal could_not_connect | 86 | signal could_not_connect |
| 64 | signal connect_status | 87 | signal connect_status |
| 65 | signal ap_connected | 88 | signal ap_connected |
| @@ -97,6 +120,20 @@ func _init(): | |||
| 97 | if data.size() > 6: | 120 | if data.size() > 6: |
| 98 | show_minimap = data[6] | 121 | show_minimap = data[6] |
| 99 | 122 | ||
| 123 | # We need to create a mapping from material paths to the original colors of | ||
| 124 | # those materials. We force reload the materials, overwriting any custom | ||
| 125 | # textures, and create the mapping. We then reload the textures in case the | ||
| 126 | # player had a custom one enabled. | ||
| 127 | var directory = DirAccess.open("res://assets/materials") | ||
| 128 | for material_name in directory.get_files(): | ||
| 129 | var material = ResourceLoader.load( | ||
| 130 | "res://assets/materials/" + material_name, "", ResourceLoader.CACHE_MODE_REPLACE | ||
| 131 | ) | ||
| 132 | |||
| 133 | color_by_material_path[material.resource_path] = Color(material.albedo_color) | ||
| 134 | |||
| 135 | settings.load_user_textures() | ||
| 136 | |||
| 100 | 137 | ||
| 101 | func _ready(): | 138 | func _ready(): |
| 102 | client = SCRIPT_client.new() | 139 | client = SCRIPT_client.new() |
| @@ -109,7 +146,10 @@ func _ready(): | |||
| 109 | client.hint_received.connect(_process_hint_received) | 146 | client.hint_received.connect(_process_hint_received) |
| 110 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) | 147 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) |
| 111 | client.checked_locations_updated.connect(_on_checked_locations_updated) | 148 | client.checked_locations_updated.connect(_on_checked_locations_updated) |
| 149 | client.ignored_locations_updated.connect(_on_ignored_locations_updated) | ||
| 150 | client.hinted_locations_updated.connect(_on_hinted_locations_updated) | ||
| 112 | client.checked_worldports_updated.connect(_on_checked_worldports_updated) | 151 | client.checked_worldports_updated.connect(_on_checked_worldports_updated) |
| 152 | client.door_latched.connect(_on_door_latched) | ||
| 113 | 153 | ||
| 114 | client.could_not_connect.connect(_client_could_not_connect) | 154 | client.could_not_connect.connect(_client_could_not_connect) |
| 115 | client.connect_status.connect(_client_connect_status) | 155 | client.connect_status.connect(_client_connect_status) |
| @@ -164,6 +204,7 @@ func connectToServer(): | |||
| 164 | _location_scouts = {} | 204 | _location_scouts = {} |
| 165 | _letters_setup = false | 205 | _letters_setup = false |
| 166 | _held_letters = {} | 206 | _held_letters = {} |
| 207 | _already_connected = false | ||
| 167 | 208 | ||
| 168 | client.connectToServer(ap_server, ap_user, ap_pass) | 209 | client.connectToServer(ap_server, ap_user, ap_pass) |
| 169 | 210 | ||
| @@ -173,6 +214,11 @@ func getSaveFileName(): | |||
| 173 | 214 | ||
| 174 | 215 | ||
| 175 | func disconnect_from_ap(): | 216 | func disconnect_from_ap(): |
| 217 | _already_connected = false | ||
| 218 | |||
| 219 | var effects = global.get_node("Effects") | ||
| 220 | effects.set_connection_lost(false) | ||
| 221 | |||
| 176 | client.disconnect_from_ap() | 222 | client.disconnect_from_ap() |
| 177 | 223 | ||
| 178 | 224 | ||
| @@ -216,6 +262,12 @@ func _process_item(item, amount): | |||
| 216 | if player != null: | 262 | if player != null: |
| 217 | player.evaluate_solvability.emit() | 263 | player.evaluate_solvability.emit() |
| 218 | 264 | ||
| 265 | if item_id == gamedata.objects.get_special_ids()["A Job Well Done"]: | ||
| 266 | update_job_well_done_sign() | ||
| 267 | |||
| 268 | if item_id == gamedata.objects.get_special_ids()["Numbers"] and global.map == "the_fuzzy": | ||
| 269 | global.allow_numbers = true | ||
| 270 | |||
| 219 | # Show a message about the item if it's new. | 271 | # Show a message about the item if it's new. |
| 220 | if int(item["index"]) > _last_new_item: | 272 | if int(item["index"]) > _last_new_item: |
| 221 | _last_new_item = int(item["index"]) | 273 | _last_new_item = int(item["index"]) |
| @@ -326,7 +378,7 @@ func _on_accessible_locations_updated(): | |||
| 326 | func _on_checked_locations_updated(): | 378 | func _on_checked_locations_updated(): |
| 327 | var textclient_node = global.get_node("Textclient") | 379 | var textclient_node = global.get_node("Textclient") |
| 328 | if textclient_node != null: | 380 | if textclient_node != null: |
| 329 | textclient_node.update_locations() | 381 | textclient_node.update_locations(false) |
| 330 | 382 | ||
| 331 | 383 | ||
| 332 | func _on_checked_worldports_updated(): | 384 | func _on_checked_worldports_updated(): |
| @@ -336,15 +388,60 @@ func _on_checked_worldports_updated(): | |||
| 336 | textclient_node.update_worldports() | 388 | textclient_node.update_worldports() |
| 337 | 389 | ||
| 338 | 390 | ||
| 391 | func _on_ignored_locations_updated(locations): | ||
| 392 | _ignored_locations = locations | ||
| 393 | |||
| 394 | var textclient_node = global.get_node("Textclient") | ||
| 395 | if textclient_node != null: | ||
| 396 | textclient_node.update_locations() | ||
| 397 | |||
| 398 | |||
| 399 | func _on_hinted_locations_updated(): | ||
| 400 | var textclient_node = global.get_node("Textclient") | ||
| 401 | if textclient_node != null: | ||
| 402 | textclient_node.update_locations() | ||
| 403 | |||
| 404 | |||
| 405 | func _on_door_latched(door_id): | ||
| 406 | var gamedata = global.get_node("Gamedata") | ||
| 407 | if gamedata.get_door_map_name(door_id) != global.map: | ||
| 408 | return | ||
| 409 | |||
| 410 | var receivers = gamedata.get_door_receivers(door_id) | ||
| 411 | var scene = get_tree().get_root().get_node_or_null("scene") | ||
| 412 | if scene != null: | ||
| 413 | for receiver in receivers: | ||
| 414 | var rnode = scene.get_node_or_null(receiver) | ||
| 415 | if rnode != null: | ||
| 416 | rnode.handleTriggered() | ||
| 417 | |||
| 418 | |||
| 339 | func _client_could_not_connect(message): | 419 | func _client_could_not_connect(message): |
| 340 | could_not_connect.emit(message) | 420 | could_not_connect.emit(message) |
| 341 | 421 | ||
| 422 | if global.loaded: | ||
| 423 | var effects = global.get_node("Effects") | ||
| 424 | effects.set_connection_lost(true) | ||
| 425 | |||
| 426 | var messages = global.get_node("Messages") | ||
| 427 | messages.showMessage("Connection to multiworld lost.") | ||
| 428 | |||
| 342 | 429 | ||
| 343 | func _client_connect_status(message): | 430 | func _client_connect_status(message): |
| 344 | connect_status.emit(message) | 431 | connect_status.emit(message) |
| 345 | 432 | ||
| 346 | 433 | ||
| 347 | func _client_connected(slot_data): | 434 | func _client_connected(slot_data): |
| 435 | var effects = global.get_node("Effects") | ||
| 436 | effects.set_connection_lost(false) | ||
| 437 | |||
| 438 | if _already_connected: | ||
| 439 | var messages = global.get_node("Messages") | ||
| 440 | messages.showMessage("Reconnected to multiworld!") | ||
| 441 | return | ||
| 442 | |||
| 443 | _already_connected = true | ||
| 444 | |||
| 348 | var gamedata = global.get_node("Gamedata") | 445 | var gamedata = global.get_node("Gamedata") |
| 349 | 446 | ||
| 350 | _localdata_file = "user://archipelago_data/%s_%d" % [client._seed, client._slot] | 447 | _localdata_file = "user://archipelago_data/%s_%d" % [client._seed, client._slot] |
| @@ -367,7 +464,11 @@ func _client_connected(slot_data): | |||
| 367 | # Read slot data. | 464 | # Read slot data. |
| 368 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) | 465 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) |
| 369 | daedalus_roof_access = bool(slot_data.get("daedalus_roof_access", false)) | 466 | daedalus_roof_access = bool(slot_data.get("daedalus_roof_access", false)) |
| 467 | enable_gift_maps = slot_data.get("enable_gift_maps", []) | ||
| 468 | enable_icarus = bool(slot_data.get("enable_icarus", false)) | ||
| 469 | endings_requirement = int(slot_data.get("endings_requirement", 0)) | ||
| 370 | keyholder_sanity = bool(slot_data.get("keyholder_sanity", false)) | 470 | keyholder_sanity = bool(slot_data.get("keyholder_sanity", false)) |
| 471 | masteries_requirement = int(slot_data.get("masteries_requirement", 0)) | ||
| 371 | shuffle_control_center_colors = bool(slot_data.get("shuffle_control_center_colors", false)) | 472 | shuffle_control_center_colors = bool(slot_data.get("shuffle_control_center_colors", false)) |
| 372 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) | 473 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) |
| 373 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) | 474 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) |
| @@ -379,14 +480,19 @@ func _client_connected(slot_data): | |||
| 379 | victory_condition = int(slot_data.get("victory_condition", 0)) | 480 | victory_condition = int(slot_data.get("victory_condition", 0)) |
| 380 | 481 | ||
| 381 | if slot_data.has("version"): | 482 | if slot_data.has("version"): |
| 382 | apworld_version = [int(slot_data["version"][0]), int(slot_data["version"][1])] | 483 | var version_msg = slot_data["version"] |
| 484 | apworld_version = [int(version_msg[0]), int(version_msg[1]), 0] | ||
| 485 | if version_msg.size() > 2: | ||
| 486 | apworld_version[2] = int(version_msg[2]) | ||
| 383 | 487 | ||
| 384 | port_pairings.clear() | 488 | port_pairings.clear() |
| 385 | if slot_data.has("port_pairings"): | 489 | if slot_data.has("port_pairings"): |
| 386 | var raw_pp = slot_data.get("port_pairings") | 490 | var raw_pp = slot_data.get("port_pairings") |
| 387 | 491 | ||
| 388 | for p1 in raw_pp.keys(): | 492 | for p1 in raw_pp.keys(): |
| 389 | port_pairings[int(p1)] = int(raw_pp[p1]) | 493 | port_pairings[gamedata.port_id_by_ap_id[int(p1)]] = gamedata.port_id_by_ap_id[int( |
| 494 | raw_pp[p1] | ||
| 495 | )] | ||
| 390 | 496 | ||
| 391 | # Set up item locks. | 497 | # Set up item locks. |
| 392 | _item_locks = {} | 498 | _item_locks = {} |
| @@ -462,6 +568,9 @@ func start_batching_locations(): | |||
| 462 | 568 | ||
| 463 | 569 | ||
| 464 | func send_location(loc_id): | 570 | func send_location(loc_id): |
| 571 | if client._checked_locations.has(loc_id): | ||
| 572 | return | ||
| 573 | |||
| 465 | if _batch_locations: | 574 | if _batch_locations: |
| 466 | _held_locations.append(loc_id) | 575 | _held_locations.append(loc_id) |
| 467 | else: | 576 | else: |
| @@ -560,3 +669,49 @@ func _process_key_item(key, level): | |||
| 560 | level += 1 | 669 | level += 1 |
| 561 | 670 | ||
| 562 | keyboard.collect_remote_letter(key, level) | 671 | keyboard.collect_remote_letter(key, level) |
| 672 | |||
| 673 | |||
| 674 | func update_job_well_done_sign(): | ||
| 675 | if global.map != "daedalus": | ||
| 676 | return | ||
| 677 | |||
| 678 | var gamedata = global.get_node("Gamedata") | ||
| 679 | var job_item = gamedata.objects.get_special_ids()["A Job Well Done"] | ||
| 680 | var jobs_done = client.getItemAmount(job_item) | ||
| 681 | |||
| 682 | var sign2 = get_tree().get_root().get_node_or_null("scene/Meshes/Miscellaneous/sign2") | ||
| 683 | var sign3 = get_tree().get_root().get_node_or_null("scene/Meshes/Miscellaneous/sign3") | ||
| 684 | |||
| 685 | if sign2 != null and sign3 != null: | ||
| 686 | if jobs_done == 0: | ||
| 687 | sign2.text = "what are you doing" | ||
| 688 | sign3.text = "?" | ||
| 689 | elif jobs_done == 1: | ||
| 690 | sign2.text = "a job well done" | ||
| 691 | sign3.text = "is its own reward" | ||
| 692 | else: | ||
| 693 | sign2.text = "%d jobs well done" % jobs_done | ||
| 694 | sign3.text = "are their own reward" | ||
| 695 | |||
| 696 | sign2.get_node("MeshInstance3D").mesh.text = sign2.text | ||
| 697 | sign3.get_node("MeshInstance3D").mesh.text = sign3.text | ||
| 698 | |||
| 699 | |||
| 700 | func toggle_ignored_location(loc_id): | ||
| 701 | if loc_id in _ignored_locations: | ||
| 702 | client.removeIgnoredLocation(loc_id) | ||
| 703 | else: | ||
| 704 | client.addIgnoredLocation(loc_id) | ||
| 705 | |||
| 706 | |||
| 707 | func get_map_script(map_name): | ||
| 708 | if !_map_scripts.has(map_name): | ||
| 709 | var runtime = global.get_node("Runtime") | ||
| 710 | var script_path = "maps/%s.gd" % map_name | ||
| 711 | if runtime.path_exists(script_path): | ||
| 712 | var script = runtime.load_script(script_path) | ||
| 713 | _map_scripts[map_name] = script.new() | ||
| 714 | else: | ||
| 715 | _map_scripts[map_name] = null | ||
| 716 | |||
| 717 | return _map_scripts[map_name] | ||
