refactor: fix bugs and improve architecture

- Fix double-execution bug in LevelStateHandler (coins/skills were committed twice per level)
- Fix DamageComponent to track multiple targets via HashSet instead of single node
- Fix HealthComponent: update health immediately, decouple from PlayerController via signal wiring in PlayerController
- Remove dead loop in SkillManager.RemoveSkill; simplify O(n²) throw skill loop
- Replace GetNode<T>(path) with .Instance across managers; add Instance to StatisticsManager/SpeedRunManager
- GameManager.GetPlayer() now uses EventBus.PlayerSpawned instead of scanning all scene nodes
- UIManager.UiStack: remove [Export], use private List<Control>
- PlayerState: extract DefaultLives constant, simplify CreateDefault()
This commit is contained in:
2026-03-19 01:41:14 +01:00
parent 427bef6509
commit 321905e68e
11 changed files with 85 additions and 161 deletions

View File

@@ -9,6 +9,8 @@ namespace Mr.BrickAdventures.scripts.State;
/// </summary>
public class PlayerState
{
private const int DefaultLives = 3;
/// <summary>
/// Saved coins (not including current session).
/// </summary>
@@ -17,7 +19,7 @@ public class PlayerState
/// <summary>
/// Remaining lives.
/// </summary>
public int Lives { get; set; } = 3;
public int Lives { get; set; } = DefaultLives;
/// <summary>
/// Indices of completed levels.
@@ -45,17 +47,9 @@ public class PlayerState
public List<string> UnlockedAchievements { get; set; } = new();
/// <summary>
/// Creates a fresh default player state.
/// Creates a fresh default player state (same as <c>new PlayerState()</c>).
/// </summary>
public static PlayerState CreateDefault() => new()
{
Coins = 0,
Lives = 3,
CompletedLevels = new List<int>(),
UnlockedLevels = new List<int> { 0 },
UnlockedSkills = new List<SkillData>(),
Statistics = new Dictionary<string, int>()
};
public static PlayerState CreateDefault() => new();
/// <summary>
/// Resets this state to default values.
@@ -63,7 +57,7 @@ public class PlayerState
public void Reset()
{
Coins = 0;
Lives = 3;
Lives = DefaultLives;
CompletedLevels.Clear();
UnlockedLevels.Clear();
UnlockedLevels.Add(0);