diff options
Diffstat (limited to 'apworld/client/manager.gd')
| -rw-r--r-- | apworld/client/manager.gd | 142 |
1 files changed, 140 insertions, 2 deletions
| diff --git a/apworld/client/manager.gd b/apworld/client/manager.gd index a5b9db0..8c981f9 100644 --- a/apworld/client/manager.gd +++ b/apworld/client/manager.gd | |||
| @@ -28,6 +28,9 @@ var _item_locks = {} | |||
| 28 | var _inverse_item_locks = {} | 28 | 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 | ||
| 32 | var _ignored_locations = [] | ||
| 33 | var _map_scripts = {} | ||
| 31 | 34 | ||
| 32 | const kSHUFFLE_LETTERS_VANILLA = 0 | 35 | const kSHUFFLE_LETTERS_VANILLA = 0 |
| 33 | const kSHUFFLE_LETTERS_UNLOCKED = 1 | 36 | const kSHUFFLE_LETTERS_UNLOCKED = 1 |
| @@ -62,7 +65,11 @@ const kEndingNameByVictoryValue = { | |||
| 62 | var apworld_version = [0, 0, 0] | 65 | var apworld_version = [0, 0, 0] |
| 63 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 | 66 | var cyan_door_behavior = kCYAN_DOOR_BEHAVIOR_H2 |
| 64 | 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 | ||
| 65 | var keyholder_sanity = false | 71 | var keyholder_sanity = false |
| 72 | var masteries_requirement = 0 | ||
| 66 | var port_pairings = {} | 73 | var port_pairings = {} |
| 67 | var shuffle_control_center_colors = false | 74 | var shuffle_control_center_colors = false |
| 68 | var shuffle_doors = false | 75 | var shuffle_doors = false |
| @@ -74,6 +81,8 @@ var strict_cyan_ending = false | |||
| 74 | var strict_purple_ending = false | 81 | var strict_purple_ending = false |
| 75 | var victory_condition = -1 | 82 | var victory_condition = -1 |
| 76 | 83 | ||
| 84 | var color_by_material_path = {} | ||
| 85 | |||
| 77 | signal could_not_connect | 86 | signal could_not_connect |
| 78 | signal connect_status | 87 | signal connect_status |
| 79 | signal ap_connected | 88 | signal ap_connected |
| @@ -111,6 +120,20 @@ func _init(): | |||
| 111 | if data.size() > 6: | 120 | if data.size() > 6: |
| 112 | show_minimap = data[6] | 121 | show_minimap = data[6] |
| 113 | 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 | |||
| 114 | 137 | ||
| 115 | func _ready(): | 138 | func _ready(): |
| 116 | client = SCRIPT_client.new() | 139 | client = SCRIPT_client.new() |
| @@ -123,7 +146,10 @@ func _ready(): | |||
| 123 | client.hint_received.connect(_process_hint_received) | 146 | client.hint_received.connect(_process_hint_received) |
| 124 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) | 147 | client.accessible_locations_updated.connect(_on_accessible_locations_updated) |
| 125 | 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) | ||
| 126 | 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) | ||
| 127 | 153 | ||
| 128 | client.could_not_connect.connect(_client_could_not_connect) | 154 | client.could_not_connect.connect(_client_could_not_connect) |
| 129 | client.connect_status.connect(_client_connect_status) | 155 | client.connect_status.connect(_client_connect_status) |
| @@ -178,6 +204,7 @@ func connectToServer(): | |||
| 178 | _location_scouts = {} | 204 | _location_scouts = {} |
| 179 | _letters_setup = false | 205 | _letters_setup = false |
| 180 | _held_letters = {} | 206 | _held_letters = {} |
| 207 | _already_connected = false | ||
| 181 | 208 | ||
| 182 | client.connectToServer(ap_server, ap_user, ap_pass) | 209 | client.connectToServer(ap_server, ap_user, ap_pass) |
| 183 | 210 | ||
| @@ -187,6 +214,11 @@ func getSaveFileName(): | |||
| 187 | 214 | ||
| 188 | 215 | ||
| 189 | 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 | |||
| 190 | client.disconnect_from_ap() | 222 | client.disconnect_from_ap() |
| 191 | 223 | ||
| 192 | 224 | ||
| @@ -230,6 +262,12 @@ func _process_item(item, amount): | |||
| 230 | if player != null: | 262 | if player != null: |
| 231 | player.evaluate_solvability.emit() | 263 | player.evaluate_solvability.emit() |
| 232 | 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 | |||
| 233 | # Show a message about the item if it's new. | 271 | # Show a message about the item if it's new. |
| 234 | if int(item["index"]) > _last_new_item: | 272 | if int(item["index"]) > _last_new_item: |
| 235 | _last_new_item = int(item["index"]) | 273 | _last_new_item = int(item["index"]) |
| @@ -340,7 +378,7 @@ func _on_accessible_locations_updated(): | |||
| 340 | func _on_checked_locations_updated(): | 378 | func _on_checked_locations_updated(): |
| 341 | var textclient_node = global.get_node("Textclient") | 379 | var textclient_node = global.get_node("Textclient") |
| 342 | if textclient_node != null: | 380 | if textclient_node != null: |
| 343 | textclient_node.update_locations() | 381 | textclient_node.update_locations(false) |
| 344 | 382 | ||
| 345 | 383 | ||
| 346 | func _on_checked_worldports_updated(): | 384 | func _on_checked_worldports_updated(): |
| @@ -350,15 +388,60 @@ func _on_checked_worldports_updated(): | |||
| 350 | textclient_node.update_worldports() | 388 | textclient_node.update_worldports() |
| 351 | 389 | ||
| 352 | 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 | |||
| 353 | func _client_could_not_connect(message): | 419 | func _client_could_not_connect(message): |
| 354 | could_not_connect.emit(message) | 420 | could_not_connect.emit(message) |
| 355 | 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 | |||
| 356 | 429 | ||
| 357 | func _client_connect_status(message): | 430 | func _client_connect_status(message): |
| 358 | connect_status.emit(message) | 431 | connect_status.emit(message) |
| 359 | 432 | ||
| 360 | 433 | ||
| 361 | 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 | |||
| 362 | var gamedata = global.get_node("Gamedata") | 445 | var gamedata = global.get_node("Gamedata") |
| 363 | 446 | ||
| 364 | _localdata_file = "user://archipelago_data/%s_%d" % [client._seed, client._slot] | 447 | _localdata_file = "user://archipelago_data/%s_%d" % [client._seed, client._slot] |
| @@ -381,7 +464,11 @@ func _client_connected(slot_data): | |||
| 381 | # Read slot data. | 464 | # Read slot data. |
| 382 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) | 465 | cyan_door_behavior = int(slot_data.get("cyan_door_behavior", 0)) |
| 383 | 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)) | ||
| 384 | 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)) | ||
| 385 | 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)) |
| 386 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) | 473 | shuffle_doors = bool(slot_data.get("shuffle_doors", false)) |
| 387 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) | 474 | shuffle_gallery_paintings = bool(slot_data.get("shuffle_gallery_paintings", false)) |
| @@ -403,7 +490,9 @@ func _client_connected(slot_data): | |||
| 403 | var raw_pp = slot_data.get("port_pairings") | 490 | var raw_pp = slot_data.get("port_pairings") |
| 404 | 491 | ||
| 405 | for p1 in raw_pp.keys(): | 492 | for p1 in raw_pp.keys(): |
| 406 | 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 | )] | ||
| 407 | 496 | ||
| 408 | # Set up item locks. | 497 | # Set up item locks. |
| 409 | _item_locks = {} | 498 | _item_locks = {} |
| @@ -479,6 +568,9 @@ func start_batching_locations(): | |||
| 479 | 568 | ||
| 480 | 569 | ||
| 481 | func send_location(loc_id): | 570 | func send_location(loc_id): |
| 571 | if client._checked_locations.has(loc_id): | ||
| 572 | return | ||
| 573 | |||
| 482 | if _batch_locations: | 574 | if _batch_locations: |
| 483 | _held_locations.append(loc_id) | 575 | _held_locations.append(loc_id) |
| 484 | else: | 576 | else: |
| @@ -577,3 +669,49 @@ func _process_key_item(key, level): | |||
| 577 | level += 1 | 669 | level += 1 |
| 578 | 670 | ||
| 579 | 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] | ||
