From 5b597cf055be236a2d605e186e7803c595623a66 Mon Sep 17 00:00:00 2001 From: Nordup Date: Mon, 27 Mar 2023 01:32:15 +0300 Subject: [PATCH] load global_script_class_cache --- project/project.godot | 4 +-- .../{gate_config.gd => config_gate.gd} | 4 ++- .../scripts/loading/config_global_script.gd | 28 +++++++++++++++++++ .../{pack_config.gd => config_godot.gd} | 16 +---------- .../the_gates/scripts/loading/gate_loader.gd | 15 +++++----- .../the_gates/scripts/loading/pack_loader.gd | 15 ++++++---- project/the_gates/scripts/resources/gate.gd | 4 ++- .../scripts/resources/gate_events.gd | 1 + 8 files changed, 56 insertions(+), 31 deletions(-) rename project/the_gates/scripts/loading/{gate_config.gd => config_gate.gd} (78%) create mode 100644 project/the_gates/scripts/loading/config_global_script.gd rename project/the_gates/scripts/loading/{pack_config.gd => config_godot.gd} (80%) diff --git a/project/project.godot b/project/project.godot index 55b0f8b..e51eb0a 100644 --- a/project/project.godot +++ b/project/project.godot @@ -13,7 +13,7 @@ config_version=5 config/name="TheGates" config/description="Building new Internet" run/main_scene="res://the_gates/scenes/app.tscn" -config/features=PackedStringArray("4.1") +config/features=PackedStringArray("4.0") config/icon="res://the_gates/icons/icon_64.png" config/windows_native_icon="res://the_gates/icons/icon.ico" @@ -55,7 +55,7 @@ pointing/emulate_touch_from_mouse=true [rendering] -textures/canvas_textures/default_texture_filter=2 driver/threads/thread_model=2 textures/default_filters/anisotropic_filtering_level=1 anti_aliasing/quality/use_taa=true +textures/canvas_textures/default_texture_filter=2 diff --git a/project/the_gates/scripts/loading/gate_config.gd b/project/the_gates/scripts/loading/config_gate.gd similarity index 78% rename from project/the_gates/scripts/loading/gate_config.gd rename to project/the_gates/scripts/loading/config_gate.gd index b13a89e..4a25799 100644 --- a/project/the_gates/scripts/loading/gate_config.gd +++ b/project/the_gates/scripts/loading/config_gate.gd @@ -1,10 +1,11 @@ extends ConfigBase -class_name GateConfig +class_name ConfigGate var title: String var description: String var image_url: String var godot_config_url: String +var global_script_class_url: String var resource_pack_url: String const section = "gate" @@ -16,4 +17,5 @@ func _init(path: String, base_url: String) -> void: description = get_string(section, "description") image_url = Url.join(base_url, get_string(section, "image")) godot_config_url = Url.join(base_url, get_string(section, "godot_config")) + global_script_class_url = Url.join(base_url, get_string(section, "global_script_class")) resource_pack_url = Url.join(base_url, get_string(section, "resource_pack")) diff --git a/project/the_gates/scripts/loading/config_global_script.gd b/project/the_gates/scripts/loading/config_global_script.gd new file mode 100644 index 0000000..d31d8d8 --- /dev/null +++ b/project/the_gates/scripts/loading/config_global_script.gd @@ -0,0 +1,28 @@ +extends ConfigBase +class_name ConfigGlobalScript + +# for unloading +var scripts + + +func _init(path: String) -> void: + super._init(path) + + +func load_config() -> void: + load_global_classes() + + +func unload_config() -> void: + unload_global_classes() + + +func load_global_classes() -> void: + scripts = get_value("", "list") + if scripts == null: return + for script in scripts: CppExposed.add_global_class(script) + + +func unload_global_classes() -> void: + if scripts == null: return + for script in scripts: CppExposed.remove_global_class(script) diff --git a/project/the_gates/scripts/loading/pack_config.gd b/project/the_gates/scripts/loading/config_godot.gd similarity index 80% rename from project/the_gates/scripts/loading/pack_config.gd rename to project/the_gates/scripts/loading/config_godot.gd index 8a7a8d2..c98f44e 100644 --- a/project/the_gates/scripts/loading/pack_config.gd +++ b/project/the_gates/scripts/loading/config_godot.gd @@ -1,10 +1,9 @@ extends ConfigBase -class_name PackConfig +class_name ConfigGodot var scene_path: String # for unloading -var scripts var autoloads var actions @@ -15,29 +14,16 @@ func _init(path: String) -> void: func load_config() -> void: - load_global_classes() load_autoloads() load_input_map() load_settings() func unload_config() -> void: - unload_global_classes() unload_autoloads() unload_input_map() -func load_global_classes() -> void: - scripts = get_value("", "_global_script_classes") - if scripts == null: return - for script in scripts: CppExposed.add_global_class(script) - - -func unload_global_classes() -> void: - if scripts == null: return - for script in scripts: CppExposed.remove_global_class(script) - - func load_autoloads() -> void: autoloads = get_section_keys("autoload") if autoloads == null: return diff --git a/project/the_gates/scripts/loading/gate_loader.gd b/project/the_gates/scripts/loading/gate_loader.gd index 4099ee4..d2472cd 100644 --- a/project/the_gates/scripts/loading/gate_loader.gd +++ b/project/the_gates/scripts/loading/gate_loader.gd @@ -2,7 +2,7 @@ extends Node @export var gate_events: GateEvents -var g_config: GateConfig +var c_gate: ConfigGate func _ready() -> void: @@ -14,13 +14,14 @@ func load_gate(config_url: String) -> void: Debug.logr("======== " + config_url + " ========") var config_path: String = await FileDownloader.download(config_url) - g_config = GateConfig.new(config_path, config_url) + c_gate = ConfigGate.new(config_path, config_url) - var image_path = await FileDownloader.download(g_config.image_url) - var gate = Gate.create(config_url, g_config.title, g_config.description, - image_path, "", "") + var image_path = await FileDownloader.download(c_gate.image_url) + var gate = Gate.create(config_url, c_gate.title, c_gate.description, + image_path, "", "", "") gate_events.gate_info_loaded_emit(gate) - gate.godot_config = await FileDownloader.download(g_config.godot_config_url) - gate.resource_pack = await FileDownloader.download(g_config.resource_pack_url) + gate.godot_config = await FileDownloader.download(c_gate.godot_config_url) + gate.global_script_class = await FileDownloader.download(c_gate.global_script_class_url) + gate.resource_pack = await FileDownloader.download(c_gate.resource_pack_url) gate_events.gate_loaded_emit(gate) diff --git a/project/the_gates/scripts/loading/pack_loader.gd b/project/the_gates/scripts/loading/pack_loader.gd index e647b6d..8e46af0 100644 --- a/project/the_gates/scripts/loading/pack_loader.gd +++ b/project/the_gates/scripts/loading/pack_loader.gd @@ -5,7 +5,8 @@ class_name PackLoader @export var scenes_parent: Node var gate: Gate -var p_config: PackConfig +var c_g_script: ConfigGlobalScript +var c_godot: ConfigGodot func _ready() -> void: @@ -17,10 +18,13 @@ func load_pack(_gate: Gate) -> void: var success = ProjectSettings.load_resource_pack(gate.resource_pack) if not success: Debug.logerr("cannot load pck"); return - p_config = PackConfig.new(gate.godot_config) - p_config.load_config() + c_g_script = ConfigGlobalScript.new(gate.global_script_class) + c_godot = ConfigGodot.new(gate.godot_config) - var scene = load(p_config.scene_path) + c_g_script.load_config() # Loading order is important + c_godot.load_config() + + var scene = load(c_godot.scene_path) scenes_parent.add_child(scene.instantiate()) gate_events.gate_entered_emit() @@ -32,7 +36,8 @@ func unload_pack() -> void: if not success: Debug.logerr("cannot unload pck") else: Debug.logr("\nunloaded " + gate.resource_pack + "\n") - if p_config != null: p_config.unload_config() + if c_godot != null: c_godot.unload_config() + if c_g_script != null: c_g_script.unload_config() func _exit_tree() -> void: diff --git a/project/the_gates/scripts/resources/gate.gd b/project/the_gates/scripts/resources/gate.gd index 2ab6ddd..344f08a 100644 --- a/project/the_gates/scripts/resources/gate.gd +++ b/project/the_gates/scripts/resources/gate.gd @@ -8,16 +8,18 @@ class_name Gate @export var description: String @export_file("*.png", "*.jpg") var image: String var godot_config: String +var global_script_class: String var resource_pack: String static func create(_url: String, _title: String, _description: String, - _image: String, _godot_config: String, _resource_pack: String) -> Gate: + _image: String, _godot_config: String, _global_script_class: String, _resource_pack: String) -> Gate: var gate = Gate.new() gate.url = _url gate.title = _title gate.description = _description gate.image = _image gate.godot_config = _godot_config + gate.global_script_class = _global_script_class gate.resource_pack = _resource_pack return gate diff --git a/project/the_gates/scripts/resources/gate_events.gd b/project/the_gates/scripts/resources/gate_events.gd index 3bb82e0..7dcf4ec 100644 --- a/project/the_gates/scripts/resources/gate_events.gd +++ b/project/the_gates/scripts/resources/gate_events.gd @@ -32,4 +32,5 @@ func gate_entered_emit() -> void: func exit_gate_emit() -> void: current_gate_url = "" + current_gate = null exit_gate.emit()