diff options
Diffstat (limited to 'apworld/client/manager.gd')
| -rw-r--r-- | apworld/client/manager.gd | 118 |
1 files changed, 116 insertions, 2 deletions
| diff --git a/apworld/client/manager.gd b/apworld/client/manager.gd index 9212233..8c981f9 100644 --- a/apworld/client/manager.gd +++ b/apworld/client/manager.gd | |||
| @@ -29,6 +29,8 @@ var _inverse_item_locks = {} | |||
| 29 | var _held_letters = {} | 29 | var _held_letters = {} |
| 30 | var _letters_setup = false | 30 | var _letters_setup = false |
| 31 | var _already_connected = false | 31 | var _already_connected = false |
| 32 | var _ignored_locations = [] | ||
| 33 | var _map_scripts = {} | ||
| 32 | 34 | ||
| 33 | const kSHUFFLE_LETTERS_VANILLA = 0 | 35 | const kSHUFFLE_LETTERS_VANILLA = 0 |
| 34 | const kSHUFFLE_LETTERS_UNLOCKED = 1 | 36 | const kSHUFFLE_LETTERS_UNLOCKED = 1 |
| @@ -63,7 +65,11 @@ const kEndingNameByVictoryValue = { | |||
| 63 | var apworld_version = [0, 0, 0] | 65 | var apworld_version = [0, 0, 0] |
| 64 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 | 66 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 |
| 65 | 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 | ||
| 66 | var keyholder_sanity = false | 71 | var keyholder_sanity = false |
| 72 | var masteries_requirement = 0 | ||
| 67 | var port_pairings = {} | 73 | var port_pairings = {} |
| 68 | var shuffle_control_center_colors = false | 74 | var shuffle_control_center_colors = false |
| 69 | var shuffle_doors = false | 75 | var shuffle_doors = false |
| @@ -75,6 +81,8 @@ var strict_cyan_ending = false | |||
| 75 | var strict_purple_ending = false | 81 | var strict_purple_ending = false |
| 76 | var victory_condition = -1 | 82 | var victory_condition = -1 |
| 77 | 83 | ||
| 84 | var color_by_material_path = {} | ||
| 85 | |||
| 78 | signal could_not_connect | 86 | signal could_not_connect |
| 79 | signal connect_status | 87 | signal connect_status |
| 80 | signal ap_connected | 88 | signal ap_connected |
| @@ -112,6 +120,20 @@ func _init(): | |||
| 112 | if data.size() > 6: | 120 | if data.size() > 6: |
| 113 | show_minimap = data[6] | 121 | show_minimap = data[6] |
| 114 | 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 | |||
| 115 | 137 | ||
| 116 | func _ready(): | 138 | func _ready(): |
| 117 | client = SCRIPT_client.new() | 139 | client = SCRIPT_client.new() |
| @@ -124,7 +146,10 @@ func _ready(): | |||
| 124 | client.hint_received.connect(_process_hint_received) | 146 | client.hint_received.connect(_process_hint_received) |
| 125 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) | 147 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) |
| 126 | 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) | ||
| 127 | 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) | ||
| 128 | 153 | ||
| 129 | client.could_not_connect.connect(_client_could_not_connect) | 154 | client.could_not_connect.connect(_client_could_not_connect) |
| 130 | client.connect_status.connect(_client_connect_status) | 155 | client.connect_status.connect(_client_connect_status) |
| @@ -237,6 +262,12 @@ func _process_item(item, amount): | |||
| 237 | if player != null: | 262 | if player != null: |
| 238 | player.evaluate_solvability.emit() | 263 | player.evaluate_solvability.emit() |
| 239 | 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 | |||
| 240 | # Show a message about the item if it's new. | 271 | # Show a message about the item if it's new. |
| 241 | if int(item["index"]) > _last_new_item: | 272 | if int(item["index"]) > _last_new_item: |
| 242 | _last_new_item = int(item["index"]) | 273 | _last_new_item = int(item["index"]) |
| @@ -347,7 +378,7 @@ func _on_accessible_locations_updated(): | |||
| 347 | func _on_checked_locations_updated(): | 378 | func _on_checked_locations_updated(): |
| 348 | var textclient_node = global.get_node("Textclient") | 379 | var textclient_node = global.get_node("Textclient") |
| 349 | if textclient_node != null: | 380 | if textclient_node != null: |
| 350 | textclient_node.update_locations() | 381 | textclient_node.update_locations(false) |
| 351 | 382 | ||
| 352 | 383 | ||
| 353 | func _on_checked_worldports_updated(): | 384 | func _on_checked_worldports_updated(): |
| @@ -357,6 +388,34 @@ func _on_checked_worldports_updated(): | |||
| 357 | textclient_node.update_worldports() | 388 | textclient_node.update_worldports() |
| 358 | 389 | ||
| 359 | 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 | |||
| 360 | func _client_could_not_connect(message): | 419 | func _client_could_not_connect(message): |
| 361 | could_not_connect.emit(message) | 420 | could_not_connect.emit(message) |
| 362 | 421 | ||
| @@ -405,7 +464,11 @@ func _client_connected(slot_data): | |||
| 405 | # Read slot data. | 464 | # Read slot data. |
| 406 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) | 465 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) |
| 407 | 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)) | ||
| 408 | 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)) | ||
| 409 | 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)) |
| 410 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) | 473 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) |
| 411 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) | 474 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) |
| @@ -427,7 +490,9 @@ func _client_connected(slot_data): | |||
| 427 | var raw_pp = slot_data.get("port_pairings") | 490 | var raw_pp = slot_data.get("port_pairings") |
| 428 | 491 | ||
| 429 | for p1 in raw_pp.keys(): | 492 | for p1 in raw_pp.keys(): |
| 430 | 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 | )] | ||
| 431 | 496 | ||
| 432 | # Set up item locks. | 497 | # Set up item locks. |
| 433 | _item_locks = {} | 498 | _item_locks = {} |
| @@ -503,6 +568,9 @@ func start_batching_locations(): | |||
| 503 | 568 | ||
| 504 | 569 | ||
| 505 | func send_location(loc_id): | 570 | func send_location(loc_id): |
| 571 | if client._checked_locations.has(loc_id): | ||
| 572 | return | ||
| 573 | |||
| 506 | if _batch_locations: | 574 | if _batch_locations: |
| 507 | _held_locations.append(loc_id) | 575 | _held_locations.append(loc_id) |
| 508 | else: | 576 | else: |
| @@ -601,3 +669,49 @@ func _process_key_item(key, level): | |||
| 601 | level += 1 | 669 | level += 1 |
| 602 | 670 | ||
| 603 | 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] | ||
