about summary refs log tree commit diff stats
path: root/apworld/client/source_runtime.gd
blob: 146587afa5b72a955d2cf10decae1f9ac448e9d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
extends Node

var source_path


func _init(path):
	source_path = path


func path_exists(path):
	return FileAccess.file_exists("%s/%s" % [source_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