refactor: Consolidate skill component logic into SkillComponentBase and update manager access to singletons.
This commit is contained in:
@@ -13,9 +13,9 @@ public partial class ConsoleManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||
_gameManager = GameManager.Instance;
|
||||
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||
_skillManager = SkillManager.Instance;
|
||||
}
|
||||
|
||||
private void AddCoinsCommand(int amount)
|
||||
|
||||
@@ -14,6 +14,18 @@ public partial class FloatingTextManager : Node
|
||||
[Export] public Color CoinColor { get; set; } = new Color("#ebd320"); // Gold
|
||||
[Export] public Color MessageColor { get; set; } = new Color("#ffffff"); // White
|
||||
|
||||
public static FloatingTextManager Instance { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
public void ShowDamage(float amount, Vector2 position)
|
||||
{
|
||||
var text = Mathf.Round(amount * 100f).ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
@@ -30,6 +30,8 @@ public partial class GameManager : Node
|
||||
/// </summary>
|
||||
private GameStateStore Store => GameStateStore.Instance;
|
||||
|
||||
public static GameManager Instance { get; private set; }
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
GetTree().NodeAdded += OnNodeAdded;
|
||||
@@ -38,6 +40,7 @@ public partial class GameManager : Node
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
GetTree().NodeAdded -= OnNodeAdded;
|
||||
GetTree().NodeRemoved -= OnNodeRemoved;
|
||||
_sceneNodes.Clear();
|
||||
@@ -45,6 +48,7 @@ public partial class GameManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||
}
|
||||
|
||||
@@ -140,11 +144,9 @@ public partial class GameManager : Node
|
||||
{
|
||||
if (Store == null) return new Array<SkillData>();
|
||||
|
||||
var skills = Store.GetAllUnlockedSkills();
|
||||
var result = new Array<SkillData>();
|
||||
foreach (var s in Store.Player.UnlockedSkills)
|
||||
result.Add(s);
|
||||
foreach (var s in Store.Session.SkillsUnlocked)
|
||||
if (!result.Contains(s)) result.Add(s);
|
||||
foreach (var s in skills) result.Add(s);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using Mr.BrickAdventures.scripts.Resources;
|
||||
using Mr.BrickAdventures.scripts.State;
|
||||
|
||||
@@ -163,6 +164,19 @@ public partial class GameStateStore : Node
|
||||
Session.SkillsUnlocked.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all unlocked skills from player persistence and current session.
|
||||
/// </summary>
|
||||
public List<SkillData> GetAllUnlockedSkills()
|
||||
{
|
||||
var result = new List<SkillData>(Player.UnlockedSkills);
|
||||
foreach (var skill in Session.SkillsUnlocked)
|
||||
{
|
||||
if (!result.Contains(skill)) result.Add(skill);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Reset Operations
|
||||
|
||||
@@ -14,12 +14,24 @@ public partial class SaveSystem : Node
|
||||
[Export] public string SavePath { get; set; } = "user://savegame.json";
|
||||
[Export] public int Version { get; set; } = 2;
|
||||
|
||||
public static SaveSystem Instance { get; private set; }
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
};
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
public void SaveGame()
|
||||
{
|
||||
var store = GameStateStore.Instance;
|
||||
|
||||
@@ -18,6 +18,8 @@ public partial class SkillManager : Node
|
||||
|
||||
public Dictionary ActiveComponents { get; private set; } = new();
|
||||
|
||||
public static SkillManager Instance { get; private set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent);
|
||||
[Signal]
|
||||
@@ -25,9 +27,15 @@ public partial class SkillManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the PlayerController from its _Ready method to register itself with the manager.
|
||||
/// </summary>
|
||||
@@ -143,7 +151,6 @@ public partial class SkillManager : Node
|
||||
{
|
||||
if (s.Name == skillName)
|
||||
{
|
||||
s.IsActive = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -188,12 +195,16 @@ public partial class SkillManager : Node
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsSkillActive(SkillData skill)
|
||||
{
|
||||
return skill != null && ActiveComponents.ContainsKey(skill.Name);
|
||||
}
|
||||
|
||||
public void ActivateSkill(SkillData skill)
|
||||
{
|
||||
if (!ActiveComponents.ContainsKey(skill.Name))
|
||||
{
|
||||
AddSkill(skill);
|
||||
skill.IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +213,6 @@ public partial class SkillManager : Node
|
||||
if (ActiveComponents.ContainsKey(skill.Name))
|
||||
{
|
||||
RemoveSkill(skill.Name);
|
||||
skill.IsActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user