refactor: standardization round 2

- ConsoleManager: lazy GameManager/AchievementManager via Instance (fixes NullRef on console commands)
- AchievementManager, GhostManager: add static Instance property
- GhostEventHandler: use GhostManager.Instance, add _ExitTree unsubscription
- SpeedRunManager: remove unused IsVisible guard; TimeUpdated now emits when running
- SpeedRunHud: use SpeedRunManager.Instance, remove dead IsVisible binding
- SaveDataDto: moved to scripts/State/SaveDataDto.cs
- GameManager.AddCoins: XML doc clarifying permanent vs session coins
This commit is contained in:
2026-03-19 01:50:20 +01:00
parent 321905e68e
commit cfef49fbc7
10 changed files with 67 additions and 51 deletions

View File

@@ -7,25 +7,27 @@ namespace Mr.BrickAdventures.scripts.Events;
[GlobalClass]
public partial class GhostEventHandler : Node
{
private GhostManager _ghostManager;
public override void _Ready()
{
_ghostManager = GetNode<GhostManager>(Constants.GhostManagerPath);
EventBus.Instance.LevelStarted += OnLevelStarted;
EventBus.Instance.LevelCompleted += OnLevelCompleted;
}
public override void _ExitTree()
{
EventBus.Instance.LevelStarted -= OnLevelStarted;
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
}
private void OnLevelStarted(int levelIndex, Node currentScene)
{
GD.Print($"GhostEventHandler: Level {levelIndex} started.");
_ghostManager.StartRecording(levelIndex);
_ghostManager.SpawnGhostPlayer(levelIndex, currentScene);
GhostManager.Instance.StartRecording(levelIndex);
GhostManager.Instance.SpawnGhostPlayer(levelIndex, currentScene);
}
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
{
_ghostManager.StopRecording(true, completionTime);
GhostManager.Instance.StopRecording(true, completionTime);
}
}

View File

@@ -0,0 +1,19 @@
using System.Collections.Generic;
namespace Mr.BrickAdventures.scripts.State;
/// <summary>
/// Serializable DTO for save data - no Godot types.
/// </summary>
public class SaveDataDto
{
public int Version { get; set; }
public int Coins { get; set; }
public int Lives { get; set; }
public int CurrentLevel { get; set; }
public List<int> CompletedLevels { get; set; }
public List<int> UnlockedLevels { get; set; }
public List<string> UnlockedSkillNames { get; set; }
public List<string> UnlockedAchievements { get; set; }
public Dictionary<string, int> Statistics { get; set; }
}

View File

@@ -0,0 +1 @@
uid://lmtb7ckjp5mr

View File

@@ -9,15 +9,9 @@ public partial class SpeedRunHud : Control
{
[Export] private Label _timerLabel;
private SpeedRunManager _speedRunManager;
public override void _Ready()
{
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
_speedRunManager.TimeUpdated += OnTimerUpdated;
Visible = _speedRunManager.IsVisible;
SpeedRunManager.Instance.TimeUpdated += OnTimerUpdated;
}
private void OnTimerUpdated(double totalTime, double levelTime)