Skip to content

Commit

Permalink
feat: reload metsys editor maps by selecting game scene
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
russmatney committed Nov 22, 2024
1 parent 5d906b0 commit f02b92a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
3 changes: 3 additions & 0 deletions addons/MetroidvaniaSystem/MetSysPlugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions addons/MetroidvaniaSystem/Scripts/MetroidvaniaSystem.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 27 additions & 6 deletions src/dino/modes/vania/Vania.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions src/dino/vania/VaniaGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 #######################################################

Expand Down
5 changes: 1 addition & 4 deletions src/games/hatbot/HatBotGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions src/games/shirt/ShirtGame.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f02b92a

Please sign in to comment.