From f02b92a82df2b7b207b9777acaecb14bc15473a6 Mon Sep 17 00:00:00 2001 From: Russell Matney Date: Fri, 22 Nov 2024 18:02:33 -0500 Subject: [PATCH] feat: reload metsys editor maps by selecting game scene Attaches MetSys' main database node to the MetSysPlugin, and references the plugin from the autoload. This lets us call MetSys.plugin.main.force_reload() when switching metsys game contexts. Now reloading the metsys view just by selecting the main game scene! --- addons/MetroidvaniaSystem/MetSysPlugin.gd | 3 ++ .../Scripts/MetroidvaniaSystem.gd | 2 ++ src/dino/modes/vania/Vania.gd | 33 +++++++++++++++---- src/dino/vania/VaniaGame.gd | 5 +-- src/games/hatbot/HatBotGame.gd | 5 +-- src/games/shirt/ShirtGame.gd | 5 +-- 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/addons/MetroidvaniaSystem/MetSysPlugin.gd b/addons/MetroidvaniaSystem/MetSysPlugin.gd index 5c98b5593..40925660a 100644 --- a/addons/MetroidvaniaSystem/MetSysPlugin.gd +++ b/addons/MetroidvaniaSystem/MetSysPlugin.gd @@ -64,6 +64,9 @@ func _enter_tree() -> void: get_singleton().settings.theme_changed.connect(func(): prev_theme_state.clear()) + # DINO addition - support calling plugin.main functions in @tool scripts! + get_singleton().plugin = self + func _exit_tree() -> void: main.queue_free() diff --git a/addons/MetroidvaniaSystem/Scripts/MetroidvaniaSystem.gd b/addons/MetroidvaniaSystem/Scripts/MetroidvaniaSystem.gd index cf0b103e6..93f5acddb 100644 --- a/addons/MetroidvaniaSystem/Scripts/MetroidvaniaSystem.gd +++ b/addons/MetroidvaniaSystem/Scripts/MetroidvaniaSystem.gd @@ -24,6 +24,8 @@ enum { R, ## Right border. U, ## Top border. } +var plugin + var settings: MetSysSettings ## The size of a map cell. Automatically set to the size of [member MapTheme.center_texture]. Read only. var CELL_SIZE: Vector2 diff --git a/src/dino/modes/vania/Vania.gd b/src/dino/modes/vania/Vania.gd index f6df7cea5..ec242f91f 100644 --- a/src/dino/modes/vania/Vania.gd +++ b/src/dino/modes/vania/Vania.gd @@ -3,18 +3,39 @@ class_name Vania ## static ############################################# -## NOTE this doesn't completely work yet! -static func reset_metsys_context(metsys_settings): - Log.info("resetting MetSys context") +static func reset_metsys_context(game, metsys_settings): + # only run if the settings actually change + if MetSys.settings == metsys_settings: + Log.info("skipping MetSys reset, in same context", game) + return + Log.info("resetting MetSys context", game) MetSys.settings = metsys_settings # this is typically already connected U._connect(MetSys.settings.theme_changed, MetSys._update_theme) MetSys._update_theme() - var MapData = load("res://addons/MetroidvaniaSystem/Scripts/MapData.gd") - MetSys.map_data = MapData.new() - MetSys.map_data.load_data() + if Engine.is_editor_hint() and MetSys.plugin != null: + var db_main = MetSys.plugin.main + if db_main: + # calls Database/Main.tscn.reload_map() + db_main.reload_map() + else: + Log.warn("Metsys/Database/Main node not found, could not reset metsys context", db_main) + else: + # non-editor map data reload + # TODO be sure the minimap updates as expected + + # this bit from Database/Manage.tscn.force_reload() + MetSys.map_data = MetSys.MapData.new() + MetSys.map_data.load_data() + for group in MetSys.map_data.cell_groups.values(): + var i: int = 0 + while i < group.size(): + if MetSys.map_data.get_cell_at(group[i]): + i += 1 + else: + group.remove_at(i) ## vars ##################################################3 diff --git a/src/dino/vania/VaniaGame.gd b/src/dino/vania/VaniaGame.gd index 36867e5c3..ac41f95dc 100644 --- a/src/dino/vania/VaniaGame.gd +++ b/src/dino/vania/VaniaGame.gd @@ -82,10 +82,7 @@ func all_rooms_visited(): ## enter_tree ####################################################### func _enter_tree(): - # if Engine.is_editor_hint(): - # return - - Vania.reset_metsys_context(vania_metsys_settings) + Vania.reset_metsys_context(self, vania_metsys_settings) ## exit_tree ####################################################### diff --git a/src/games/hatbot/HatBotGame.gd b/src/games/hatbot/HatBotGame.gd index fec938407..bc62049b4 100644 --- a/src/games/hatbot/HatBotGame.gd +++ b/src/games/hatbot/HatBotGame.gd @@ -9,10 +9,7 @@ class_name HatBotGame @export var player_entity: DinoPlayerEntity func _enter_tree(): - # if Engine.is_editor_hint(): - # return - - Vania.reset_metsys_context(hatbot_metsys_settings) + Vania.reset_metsys_context(self, hatbot_metsys_settings) func _exit_tree(): for m in modules: diff --git a/src/games/shirt/ShirtGame.gd b/src/games/shirt/ShirtGame.gd index 156e3dcfd..cc5d2b7af 100644 --- a/src/games/shirt/ShirtGame.gd +++ b/src/games/shirt/ShirtGame.gd @@ -9,10 +9,7 @@ class_name ShirtGame @export var player_entity: DinoPlayerEntity func _enter_tree(): - # if Engine.is_editor_hint(): - # return - - Vania.reset_metsys_context(shirt_metsys_settings) + Vania.reset_metsys_context(self, shirt_metsys_settings) func _exit_tree(): for m in modules: