diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-09-25 14:14:22 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-09-25 14:14:22 -0400 |
commit | cb2eca4fed1eb3692eaa13715f65ebcaf8472b64 (patch) | |
tree | 7d11ad1db462c0af4de9da02bde8e44899e0e282 /apworld/client/apworld_runtime.gd | |
parent | 72b9d1f0952aee6e72b9478118dc99e08ff1fa54 (diff) | |
download | lingo2-archipelago-cb2eca4fed1eb3692eaa13715f65ebcaf8472b64.tar.gz lingo2-archipelago-cb2eca4fed1eb3692eaa13715f65ebcaf8472b64.tar.bz2 lingo2-archipelago-cb2eca4fed1eb3692eaa13715f65ebcaf8472b64.zip |
Client can be run from zipped apworld now
Diffstat (limited to 'apworld/client/apworld_runtime.gd')
-rw-r--r-- | apworld/client/apworld_runtime.gd | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ | |||
1 | extends Node | ||
2 | |||
3 | var apworld_reader | ||
4 | |||
5 | |||
6 | func _init(path): | ||
7 | apworld_reader = ZIPReader.new() | ||
8 | apworld_reader.open(path) | ||
9 | |||
10 | |||
11 | func _get_true_path(path): | ||
12 | if path.begins_with("../"): | ||
13 | return "lingo2/%s" % path.substr(3) | ||
14 | else: | ||
15 | return "lingo2/client/%s" % path | ||
16 | |||
17 | |||
18 | func load_script(path): | ||
19 | var true_path = _get_true_path(path) | ||
20 | |||
21 | var script = GDScript.new() | ||
22 | script.source_code = apworld_reader.read_file(true_path).get_string_from_utf8() | ||
23 | script.reload() | ||
24 | |||
25 | return script | ||
26 | |||
27 | |||
28 | func read_path(path): | ||
29 | var true_path = _get_true_path(path) | ||
30 | return apworld_reader.read_file(true_path) | ||
31 | |||
32 | |||
33 | func load_script_as_scene(path, scene_name): | ||
34 | var script = load_script(path) | ||
35 | var instance = script.new() | ||
36 | instance.name = scene_name | ||
37 | |||
38 | get_tree().unload_current_scene() | ||
39 | _load_scene.call_deferred(instance) | ||
40 | |||
41 | |||
42 | func _load_scene(instance): | ||
43 | get_tree().get_root().add_child(instance) | ||
44 | get_tree().current_scene = instance | ||