From cb2eca4fed1eb3692eaa13715f65ebcaf8472b64 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 25 Sep 2025 14:14:22 -0400 Subject: Client can be run from zipped apworld now --- apworld/client/apworld_runtime.gd | 44 +++++++++ apworld/client/main.gd | 62 ++++++------- apworld/client/pauseMenu.gd | 2 +- apworld/client/run_from_apworld.tscn | 30 ++++++ apworld/client/run_from_source.tscn | 3 +- apworld/client/settings_screen.gd | 153 +++++++++++++++++++++++++++++++ apworld/client/settings_screen.tscn | 173 ----------------------------------- apworld/client/source_runtime.gd | 16 +++- 8 files changed, 275 insertions(+), 208 deletions(-) create mode 100644 apworld/client/apworld_runtime.gd create mode 100644 apworld/client/run_from_apworld.tscn create mode 100644 apworld/client/settings_screen.gd delete mode 100644 apworld/client/settings_screen.tscn (limited to 'apworld/client') diff --git a/apworld/client/apworld_runtime.gd b/apworld/client/apworld_runtime.gd new file mode 100644 index 0000000..faf8e0c --- /dev/null +++ b/apworld/client/apworld_runtime.gd @@ -0,0 +1,44 @@ +extends Node + +var apworld_reader + + +func _init(path): + apworld_reader = ZIPReader.new() + apworld_reader.open(path) + + +func _get_true_path(path): + if path.begins_with("../"): + return "lingo2/%s" % path.substr(3) + else: + return "lingo2/client/%s" % path + + +func load_script(path): + var true_path = _get_true_path(path) + + var script = GDScript.new() + script.source_code = apworld_reader.read_file(true_path).get_string_from_utf8() + script.reload() + + return script + + +func read_path(path): + var true_path = _get_true_path(path) + return apworld_reader.read_file(true_path) + + +func load_script_as_scene(path, scene_name): + var script = load_script(path) + var instance = script.new() + instance.name = scene_name + + get_tree().unload_current_scene() + _load_scene.call_deferred(instance) + + +func _load_scene(instance): + get_tree().get_root().add_child(instance) + get_tree().current_scene = instance diff --git a/apworld/client/main.gd b/apworld/client/main.gd index a31eb89..cff92bc 100644 --- a/apworld/client/main.gd +++ b/apworld/client/main.gd @@ -22,59 +22,59 @@ func _ready(): # Create the global AP manager, if it doesn't already exist. if not global.has_node("Archipelago"): - var ap_script = runtime.load_path("manager.gd") + var ap_script = runtime.load_script("manager.gd") var ap_instance = ap_script.new() ap_instance.name = "Archipelago" - ap_instance.SCRIPT_client = runtime.load_path("client.gd") - ap_instance.SCRIPT_keyboard = runtime.load_path("keyboard.gd") - ap_instance.SCRIPT_locationListener = runtime.load_path("locationListener.gd") - ap_instance.SCRIPT_minimap = runtime.load_path("minimap.gd") - ap_instance.SCRIPT_uuid = runtime.load_path("vendor/uuid.gd") - ap_instance.SCRIPT_victoryListener = runtime.load_path("victoryListener.gd") + ap_instance.SCRIPT_client = runtime.load_script("client.gd") + ap_instance.SCRIPT_keyboard = runtime.load_script("keyboard.gd") + ap_instance.SCRIPT_locationListener = runtime.load_script("locationListener.gd") + ap_instance.SCRIPT_minimap = runtime.load_script("minimap.gd") + ap_instance.SCRIPT_uuid = runtime.load_script("vendor/uuid.gd") + ap_instance.SCRIPT_victoryListener = runtime.load_script("victoryListener.gd") global.add_child(ap_instance) # Let's also inject any scripts we need to inject now. - installScriptExtension(runtime.load_path("animationListener.gd")) - installScriptExtension(runtime.load_path("collectable.gd")) - installScriptExtension(runtime.load_path("door.gd")) - installScriptExtension(runtime.load_path("keyHolder.gd")) - installScriptExtension(runtime.load_path("keyHolderChecker.gd")) - installScriptExtension(runtime.load_path("keyHolderResetterListener.gd")) - installScriptExtension(runtime.load_path("painting.gd")) - installScriptExtension(runtime.load_path("panel.gd")) - installScriptExtension(runtime.load_path("pauseMenu.gd")) - installScriptExtension(runtime.load_path("player.gd")) - installScriptExtension(runtime.load_path("saver.gd")) - installScriptExtension(runtime.load_path("teleport.gd")) - installScriptExtension(runtime.load_path("teleportListener.gd")) - installScriptExtension(runtime.load_path("visibilityListener.gd")) - installScriptExtension(runtime.load_path("worldport.gd")) - installScriptExtension(runtime.load_path("worldportListener.gd")) - - var proto_script = runtime.load_path("../generated/proto.gd") - var gamedata_script = runtime.load_path("gamedata.gd") + installScriptExtension(runtime.load_script("animationListener.gd")) + installScriptExtension(runtime.load_script("collectable.gd")) + installScriptExtension(runtime.load_script("door.gd")) + installScriptExtension(runtime.load_script("keyHolder.gd")) + installScriptExtension(runtime.load_script("keyHolderChecker.gd")) + installScriptExtension(runtime.load_script("keyHolderResetterListener.gd")) + installScriptExtension(runtime.load_script("painting.gd")) + installScriptExtension(runtime.load_script("panel.gd")) + installScriptExtension(runtime.load_script("pauseMenu.gd")) + installScriptExtension(runtime.load_script("player.gd")) + installScriptExtension(runtime.load_script("saver.gd")) + installScriptExtension(runtime.load_script("teleport.gd")) + installScriptExtension(runtime.load_script("teleportListener.gd")) + installScriptExtension(runtime.load_script("visibilityListener.gd")) + installScriptExtension(runtime.load_script("worldport.gd")) + installScriptExtension(runtime.load_script("worldportListener.gd")) + + var proto_script = runtime.load_script("../generated/proto.gd") + var gamedata_script = runtime.load_script("gamedata.gd") var gamedata_instance = gamedata_script.new(proto_script) gamedata_instance.load(runtime.read_path("../generated/data.binpb")) gamedata_instance.name = "Gamedata" global.add_child(gamedata_instance) - var messages_script = runtime.load_path("messages.gd") + var messages_script = runtime.load_script("messages.gd") var messages_instance = messages_script.new() messages_instance.name = "Messages" - messages_instance.SCRIPT_rainbowText = runtime.load_path("rainbowText.gd") + messages_instance.SCRIPT_rainbowText = runtime.load_script("rainbowText.gd") global.add_child(messages_instance) - var textclient_script = runtime.load_path("textclient.gd") + var textclient_script = runtime.load_script("textclient.gd") var textclient_instance = textclient_script.new() textclient_instance.name = "Textclient" global.add_child(textclient_instance) - var compass_overlay_script = runtime.load_path("compass_overlay.gd") + var compass_overlay_script = runtime.load_script("compass_overlay.gd") var compass_overlay_instance = compass_overlay_script.new() compass_overlay_instance.name = "Compass" - compass_overlay_instance.SCRIPT_compass = runtime.load_path("compass.gd") + compass_overlay_instance.SCRIPT_compass = runtime.load_script("compass.gd") global.add_child(compass_overlay_instance) var ap = global.get_node("Archipelago") diff --git a/apworld/client/pauseMenu.gd b/apworld/client/pauseMenu.gd index 448f690..8bc12c6 100644 --- a/apworld/client/pauseMenu.gd +++ b/apworld/client/pauseMenu.gd @@ -39,7 +39,7 @@ func _main_menu(): musicPlayer.stop() var runtime = global.get_node("Runtime") - get_tree().change_scene_to_packed(runtime.load_path("settings_screen.tscn")) + runtime.load_script_as_scene.call_deferred("settings_screen.gd", "settings_screen") func _toggle_compass(): diff --git a/apworld/client/run_from_apworld.tscn b/apworld/client/run_from_apworld.tscn new file mode 100644 index 0000000..11373e0 --- /dev/null +++ b/apworld/client/run_from_apworld.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=11 format=2] + +[sub_resource id=2 type="GDScript"] +script/source = "extends Node2D + + +func _ready(): + var args = OS.get_cmdline_user_args() + var apworld_path = args[0] + + var zip_reader = ZIPReader.new() + zip_reader.open(apworld_path) + + var runtime_script = GDScript.new() + runtime_script.source_code = zip_reader.read_file(\"lingo2/client/apworld_runtime.gd\").get_string_from_utf8() + runtime_script.reload() + + zip_reader.close() + + var runtime = runtime_script.new(apworld_path) + runtime.name = \"Runtime\" + + global.add_child(runtime) + + runtime.load_script_as_scene.call_deferred(\"settings_screen.gd\", \"settings_screen\") + +" + +[node name="loader" type="Node2D"] +script = SubResource( 2 ) diff --git a/apworld/client/run_from_source.tscn b/apworld/client/run_from_source.tscn index b710677..59a914d 100644 --- a/apworld/client/run_from_source.tscn +++ b/apworld/client/run_from_source.tscn @@ -14,8 +14,7 @@ func _ready(): global.add_child(runtime) - var settings_screen = runtime.load_path(\"settings_screen.tscn\") - get_tree().change_scene_to_packed(settings_screen) + runtime.load_script_as_scene.call_deferred(\"settings_screen.gd\", \"settings_screen\") " diff --git a/apworld/client/settings_screen.gd b/apworld/client/settings_screen.gd new file mode 100644 index 0000000..b430b17 --- /dev/null +++ b/apworld/client/settings_screen.gd @@ -0,0 +1,153 @@ +extends Node + + +func _ready(): + var theme = preload("res://assets/themes/baseUI.tres") + + var simple_style_box = StyleBoxFlat.new() + simple_style_box.bg_color = Color(0, 0, 0, 0) + + var panel = Panel.new() + panel.name = "Panel" + panel.offset_right = 1920.0 + panel.offset_bottom = 1080.0 + add_child(panel) + + var title = Label.new() + title.name = "title" + title.offset_left = 0.0 + title.offset_top = 75.0 + title.offset_right = 1920.0 + title.offset_bottom = 225.0 + title.text = "ARCHIPELAGO" + title.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + title.theme = theme + panel.add_child(title) + + var connect_button = Button.new() + connect_button.name = "connect_button" + connect_button.offset_left = 255.0 + connect_button.offset_top = 875.0 + connect_button.offset_right = 891.0 + connect_button.offset_bottom = 1025.0 + connect_button.add_theme_color_override("font_color_hover", Color(1, 0.501961, 0, 1)) + connect_button.text = "CONNECT" + connect_button.theme = theme + panel.add_child(connect_button) + + var quit_button = Button.new() + quit_button.name = "quit_button" + quit_button.offset_left = 1102.0 + quit_button.offset_top = 875.0 + quit_button.offset_right = 1738.0 + quit_button.offset_bottom = 1025.0 + quit_button.add_theme_color_override("font_color_hover", Color(1, 0, 0, 1)) + quit_button.text = "QUIT" + quit_button.theme = theme + panel.add_child(quit_button) + + var credit2 = Label.new() + credit2.name = "credit2" + credit2.offset_left = -105.0 + credit2.offset_top = 346.0 + credit2.offset_right = 485.0 + credit2.offset_bottom = 410.0 + credit2.add_theme_stylebox_override("normal", simple_style_box) + credit2.text = "SERVER" + credit2.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + credit2.theme = theme + panel.add_child(credit2) + + var credit3 = Label.new() + credit3.name = "credit3" + credit3.offset_left = -105.0 + credit3.offset_top = 519.0 + credit3.offset_right = 485.0 + credit3.offset_bottom = 583.0 + credit3.add_theme_stylebox_override("normal", simple_style_box) + credit3.text = "PLAYER" + credit3.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + credit3.theme = theme + panel.add_child(credit3) + + var credit4 = Label.new() + credit4.name = "credit4" + credit4.offset_left = -105.0 + credit4.offset_top = 704.0 + credit4.offset_right = 485.0 + credit4.offset_bottom = 768.0 + credit4.add_theme_stylebox_override("normal", simple_style_box) + credit4.text = "PASSWORD" + credit4.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + credit4.theme = theme + panel.add_child(credit4) + + var credit5 = Label.new() + credit5.name = "credit5" + credit5.offset_left = 1239.0 + credit5.offset_top = 422.0 + credit5.offset_right = 1829.0 + credit5.offset_bottom = 486.0 + credit5.add_theme_stylebox_override("normal", simple_style_box) + credit5.text = "OPTIONS" + credit5.theme = theme + panel.add_child(credit5) + + var server_box = LineEdit.new() + server_box.name = "server_box" + server_box.offset_left = 502.0 + server_box.offset_top = 295.0 + server_box.offset_right = 1144.0 + server_box.offset_bottom = 445.0 + server_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + server_box.caret_blink = true + panel.add_child(server_box) + + var player_box = LineEdit.new() + player_box.name = "player_box" + player_box.offset_left = 502.0 + player_box.offset_top = 477.0 + player_box.offset_right = 1144.0 + player_box.offset_bottom = 627.0 + player_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + player_box.caret_blink = true + panel.add_child(player_box) + + var password_box = LineEdit.new() + password_box.name = "password_box" + password_box.offset_left = 502.0 + password_box.offset_top = 659.0 + password_box.offset_right = 1144.0 + password_box.offset_bottom = 809.0 + password_box.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + password_box.caret_blink = true + panel.add_child(password_box) + + var accept_dialog = AcceptDialog.new() + accept_dialog.name = "AcceptDialog" + accept_dialog.offset_right = 83.0 + accept_dialog.offset_bottom = 58.0 + panel.add_child(accept_dialog) + + var version_mismatch = ConfirmationDialog.new() + version_mismatch.name = "VersionMismatch" + version_mismatch.offset_right = 83.0 + version_mismatch.offset_bottom = 58.0 + panel.add_child(version_mismatch) + + var connection_history = MenuButton.new() + connection_history.name = "connection_history" + connection_history.offset_left = 1239.0 + connection_history.offset_top = 276.0 + connection_history.offset_right = 1829.0 + connection_history.offset_bottom = 372.0 + connection_history.text = "connection history" + connection_history.flat = false + panel.add_child(connection_history) + + var runtime = global.get_node("Runtime") + var main_script = runtime.load_script("main.gd") + var main_node = main_script.new() + main_node.name = "Main" + add_child(main_node) diff --git a/apworld/client/settings_screen.tscn b/apworld/client/settings_screen.tscn deleted file mode 100644 index 63d5dbe..0000000 --- a/apworld/client/settings_screen.tscn +++ /dev/null @@ -1,173 +0,0 @@ -[gd_scene load_steps=11 format=2] - -[ext_resource path="res://images/unchecked.png" type="Texture" id=7] -[ext_resource path="res://images/checked.png" type="Texture" id=8] -[ext_resource type="Theme" uid="uid://7w454egydi41" path="res://assets/themes/baseUI.tres" id="2_g4bvn"] - -[sub_resource type="StyleBoxFlat" id=1] -bg_color = Color( 0, 0, 0, 0 ) - -[sub_resource type="StyleBoxFlat" id=2] -bg_color = Color( 1, 1, 1, 1 ) -border_width_left = 1 -border_width_top = 1 -border_width_right = 1 -border_width_bottom = 1 -border_color = Color( 1, 1, 0, 1 ) -border_blend = true -corner_radius_top_left = 3 -corner_radius_top_right = 3 -corner_radius_bottom_right = 3 -corner_radius_bottom_left = 3 -expand_offset_left = 5.0 -expand_offset_right = 5.0 -expand_offset_top = 5.0 -expand_offset_bottom = 5.0 - -[sub_resource id=4 type="GDScript"] -script/source = "extends Node2D - - -func _ready(): - var runtime = global.get_node(\"Runtime\") - var main_script = runtime.load_path(\"main.gd\") - var main_node = main_script.new() - main_node.name = \"Main\" - add_child(main_node) - -" - -[node name="settings_screen" type="Node2D"] -script = SubResource( 4 ) - -[node name="Panel" type="Panel" parent="."] -offset_right = 1920.0 -offset_bottom = 1080.0 - -[node name="title" parent="Panel" type="Label"] -offset_left = 0.0 -offset_top = 75.0 -offset_right = 1920.0 -offset_bottom = 225.0 -text = "ARCHIPELAGO" -valign = 1 -horizontal_alignment = 1 -theme = ExtResource("2_g4bvn") - -[node name="credit" parent="Panel" type="Label"] -visible = false -offset_left = 1278.0 -offset_top = 974.0 -offset_right = 1868.0 -offset_bottom = 1034.0 -text = "Brenton Wildes" -theme = ExtResource("2_g4bvn") - -[node name="connect_button" parent="Panel" type="Button"] -offset_left = 255.0 -offset_top = 875.0 -offset_right = 891.0 -offset_bottom = 1025.0 -custom_colors/font_color_hover = Color( 1, 0.501961, 0, 1 ) -text = "CONNECT" -theme = ExtResource("2_g4bvn") - -[node name="quit_button" parent="Panel" type="Button"] -offset_left = 1102.0 -offset_top = 875.0 -offset_right = 1738.0 -offset_bottom = 1025.0 -custom_colors/font_color_hover = Color( 1, 0, 0, 1 ) -text = "QUIT" -theme = ExtResource("2_g4bvn") - -[node name="credit2" parent="Panel" type="Label"] -offset_left = -105.0 -offset_top = 346.0 -offset_right = 485.0 -offset_bottom = 410.0 -custom_styles/normal = SubResource( 1 ) -text = "SERVER" -align = 2 -theme = ExtResource("2_g4bvn") - -[node name="credit5" parent="Panel" type="Label"] -offset_left = 1239.0 -offset_top = 422.0 -offset_right = 1829.0 -offset_bottom = 486.0 -custom_styles/normal = SubResource( 1 ) -text = "OPTIONS" -theme = ExtResource("2_g4bvn") - -[node name="credit3" parent="Panel" type="Label"] -offset_left = -105.0 -offset_top = 519.0 -offset_right = 485.0 -offset_bottom = 583.0 -custom_styles/normal = SubResource( 1 ) -text = "PLAYER" -align = 2 -theme = ExtResource("2_g4bvn") - -[node name="credit4" parent="Panel" type="Label"] -offset_left = -105.0 -offset_top = 704.0 -offset_right = 485.0 -offset_bottom = 768.0 -custom_styles/normal = SubResource( 1 ) -text = "PASSWORD" -align = 2 -theme = ExtResource("2_g4bvn") - -[node name="server_box" type="LineEdit" parent="Panel"] -offset_left = 502.0 -offset_top = 295.0 -offset_right = 1144.0 -offset_bottom = 445.0 -custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) -custom_colors/cursor_color = Color( 0, 0, 0, 1 ) -custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_styles/focus = SubResource( 2 ) -align = 1 -caret_blink = true - -[node name="player_box" type="LineEdit" parent="Panel"] -offset_left = 502.0 -offset_top = 477.0 -offset_right = 1144.0 -offset_bottom = 627.0 -custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) -custom_colors/cursor_color = Color( 0, 0, 0, 1 ) -custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_styles/focus = SubResource( 2 ) -align = 1 -caret_blink = true - -[node name="password_box" type="LineEdit" parent="Panel"] -offset_left = 502.0 -offset_top = 659.0 -offset_right = 1144.0 -offset_bottom = 809.0 -custom_colors/selection_color = Color( 0.482353, 0, 0, 1 ) -custom_colors/cursor_color = Color( 0, 0, 0, 1 ) -custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_styles/focus = SubResource( 2 ) -align = 1 -caret_blink = true - -[node name="AcceptDialog" type="AcceptDialog" parent="Panel"] -offset_right = 83.0 -offset_bottom = 58.0 - -[node name="VersionMismatch" type="ConfirmationDialog" parent="Panel"] -offset_right = 83.0 -offset_bottom = 58.0 - -[node name="connection_history" type="MenuButton" parent="Panel"] -offset_left = 1239.0 -offset_top = 276.0 -offset_right = 1829.0 -offset_bottom = 372.0 -text = "connection history" -flat = false diff --git a/apworld/client/source_runtime.gd b/apworld/client/source_runtime.gd index fbb7009..35428ea 100644 --- a/apworld/client/source_runtime.gd +++ b/apworld/client/source_runtime.gd @@ -7,9 +7,23 @@ func _init(path): source_path = path -func load_path(path): +func load_script(path): return ResourceLoader.load("%s/%s" % [source_path, path]) func read_path(path): return FileAccess.get_file_as_bytes("%s/%s" % [source_path, path]) + + +func load_script_as_scene(path, scene_name): + var script = load_script(path) + var instance = script.new() + instance.name = scene_name + + get_tree().unload_current_scene() + _load_scene.call_deferred(instance) + + +func _load_scene(instance): + get_tree().get_root().add_child(instance) + get_tree().current_scene = instance -- cgit 1.4.1