diff --git a/addons/MetroidvaniaSystem/MetSysPlugin.gd b/addons/MetroidvaniaSystem/MetSysPlugin.gd index 5c98b559..40925660 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 cf0b103e..93f5acdd 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 f6df7cea..ec242f91 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 36867e5c..ac41f95d 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 fec93840..bc62049b 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 156e3dcf..cc5d2b7a 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: