refactor: implement singleton pattern for key managers and improve resource access
This commit is contained in:
@@ -4,13 +4,16 @@ namespace Mr.BrickAdventures.Autoloads;
|
||||
|
||||
public partial class ConfigFileHandler : Node
|
||||
{
|
||||
public static ConfigFileHandler Instance { get; private set; }
|
||||
|
||||
private ConfigFile _settingsConfig = new();
|
||||
public const string SettingsPath = "user://settings.ini";
|
||||
|
||||
|
||||
public ConfigFile SettingsConfig => _settingsConfig;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
if (!FileAccess.FileExists(SettingsPath))
|
||||
{
|
||||
var err = _settingsConfig.Save(SettingsPath);
|
||||
@@ -24,4 +27,9 @@ public partial class ConfigFileHandler : Node
|
||||
GD.PushError($"Failed to load settings file at {SettingsPath}: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public partial class SaveSystem : Node
|
||||
var skills = new List<SkillData>();
|
||||
if (skillNames == null) return skills;
|
||||
|
||||
var skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
||||
var skillManager = SkillManager.Instance;
|
||||
if (skillManager == null)
|
||||
{
|
||||
GD.PrintErr("SaveSystem: SkillManager not available to resolve skill names.");
|
||||
|
||||
@@ -4,7 +4,19 @@ namespace Mr.BrickAdventures.Autoloads;
|
||||
|
||||
public partial class UIManager : Node
|
||||
{
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
||||
private readonly System.Collections.Generic.List<Control> UiStack = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
[Signal] public delegate void ScreenPushedEventHandler(Control screen);
|
||||
[Signal] public delegate void ScreenPoppedEventHandler(Control screen);
|
||||
|
||||
Reference in New Issue
Block a user