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 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 apworld/client/apworld_runtime.gd (limited to 'apworld/client/apworld_runtime.gd') 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 -- cgit 1.4.1