From 334972ecca9593e236f61c55cd4ea93c3b753442 Mon Sep 17 00:00:00 2001 From: Russell Matney Date: Fri, 22 Nov 2024 12:31:58 -0500 Subject: [PATCH] feat: pull metsys context reset into Vania static func This helper isn't perfect yet (not yet working when switching games), but it somewhat resets the editor context, so it's a start. --- src/dino/modes/vania/Vania.gd | 14 ++++++++++++++ src/dino/vania/VaniaGame.gd | 13 +++---------- src/games/hatbot/HatBotGame.gd | 10 ++-------- src/games/shirt/ShirtGame.gd | 11 ++--------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/dino/modes/vania/Vania.gd b/src/dino/modes/vania/Vania.gd index 2046eb31c..1655a61a0 100644 --- a/src/dino/modes/vania/Vania.gd +++ b/src/dino/modes/vania/Vania.gd @@ -1,4 +1,18 @@ extends Node2D +class_name Vania + +## static ############################################# + +## NOTE this doesn't completely work yet! +static func reset_metsys_context(metsys_settings): + Log.info("resetting MetSys context") + MetSys.settings = metsys_settings + + # this is typically already connected + U._connect(MetSys.settings.theme_changed, MetSys._update_theme) + MetSys._update_theme() + # MetSys.map_data = MapData.new() + MetSys.map_data.load_data() ## vars ##################################################3 diff --git a/src/dino/vania/VaniaGame.gd b/src/dino/vania/VaniaGame.gd index 573b47861..c79e22549 100644 --- a/src/dino/vania/VaniaGame.gd +++ b/src/dino/vania/VaniaGame.gd @@ -52,7 +52,7 @@ var ready_for_next: bool = false var room_defs: Array[VaniaRoomDef] = [] @export var map_def: MapDef -@export var MetSysSettings = preload("res://src/dino/vania/VaniaMetSysSettings.tres") +@export var vania_metsys_settings = preload("res://src/dino/vania/VaniaMetSysSettings.tres") @onready var hud = $%DinoHUD var time: float = 0 @@ -84,15 +84,8 @@ func all_rooms_visited(): func _enter_tree(): # if Engine.is_editor_hint(): # return - Log.warn("adjusting MetSys settings for Vania Game") - # set expected metsys settings - MetSys.settings = MetSysSettings - - # TODO ignore if already connected - MetSys.settings.theme_changed.connect(MetSys._update_theme) - MetSys._update_theme() - # MetSys.map_data = MapData.new() - MetSys.map_data.load_data() + + Vania.reset_metsys_context(vania_metsys_settings) ## ready ####################################################### diff --git a/src/games/hatbot/HatBotGame.gd b/src/games/hatbot/HatBotGame.gd index ac33daca8..98c3d4fca 100644 --- a/src/games/hatbot/HatBotGame.gd +++ b/src/games/hatbot/HatBotGame.gd @@ -5,20 +5,14 @@ class_name HatBotGame # this script based initially on MetSys/SampleProject/Scripts/Game.gd @export var first_room: String = "RoomZero.tscn" -@export var MetSysSettings = preload("res://src/games/hatbot/HatBotMetSysSettings.tres") +@export var hatbot_metsys_settings = preload("res://src/games/hatbot/HatBotMetSysSettings.tres") @export var player_entity: DinoPlayerEntity func _enter_tree(): # if Engine.is_editor_hint(): # return - Log.warn("adjusting MetSys settings for HatBot Game") - MetSys.settings = MetSysSettings - # TODO ignore if already connected - MetSys.settings.theme_changed.connect(MetSys._update_theme) - MetSys._update_theme() - # MetSys.map_data = MapData.new() - MetSys.map_data.load_data() + Vania.reset_metsys_context(hatbot_metsys_settings) func _ready(): if Engine.is_editor_hint(): diff --git a/src/games/shirt/ShirtGame.gd b/src/games/shirt/ShirtGame.gd index 5df98c765..9682b426b 100644 --- a/src/games/shirt/ShirtGame.gd +++ b/src/games/shirt/ShirtGame.gd @@ -5,21 +5,14 @@ class_name ShirtGame # this script based initially on MetSys/SampleProject/Scripts/Game.gd @export var first_room: String = "RoomZero.tscn" -@export var MetSysSettings = preload("res://src/games/shirt/ShirtMetSysSettings.tres") +@export var shirt_metsys_settings = preload("res://src/games/shirt/ShirtMetSysSettings.tres") @export var player_entity: DinoPlayerEntity func _enter_tree(): # if Engine.is_editor_hint(): # return - Log.warn("adjusting MetSys settings for Shirt Game") - MetSys.settings = MetSysSettings - - # TODO ignore if already connected - MetSys.settings.theme_changed.connect(MetSys._update_theme) - MetSys._update_theme() - # MetSys.map_data = MapData.new() - MetSys.map_data.load_data() + Vania.reset_metsys_context(shirt_metsys_settings) func _ready(): if Engine.is_editor_hint():