diff --git a/Autoloads/GameManager.cs b/Autoloads/GameManager.cs index 80583c8..51e40a7 100644 --- a/Autoloads/GameManager.cs +++ b/Autoloads/GameManager.cs @@ -21,11 +21,7 @@ public partial class GameManager : Node } private PlayerController _player; - private SpeedRunManager _speedRunManager; - - /// - /// Lazy accessor for GameStateStore - avoids initialization order issues. - /// + private SpeedRunManager SpeedRunManager => SpeedRunManager.Instance; private GameStateStore Store => GameStateStore.Instance; public static GameManager Instance { get; private set; } @@ -33,7 +29,6 @@ public partial class GameManager : Node public override void _Ready() { Instance = this; - _speedRunManager = SpeedRunManager.Instance; EventBus.Instance.PlayerSpawned += OnPlayerSpawned; } @@ -197,7 +192,7 @@ public partial class GameManager : Node public void StartNewGame() { Store?.ResetAll(); - _speedRunManager?.StartTimer(); + SpeedRunManager?.StartTimer(); GetTree().ChangeSceneToPacked(LevelScenes[0]); SaveSystem.Instance.SaveGame(); EventBus.EmitGameStarted(); @@ -234,7 +229,7 @@ public partial class GameManager : Node Store.CommitSessionCoins(); Store.CommitSessionSkills(); - var completionTime = _speedRunManager?.GetCurrentLevelTime() ?? 0.0; + var completionTime = SpeedRunManager?.GetCurrentLevelTime() ?? 0.0; EventBus.EmitLevelCompleted(levelIndex, GetTree().CurrentScene, completionTime); Store.ResetSession(); diff --git a/scripts/Events/SkillCollectHandler.cs b/scripts/Events/SkillCollectHandler.cs index 3c60911..9e2c6a2 100644 --- a/scripts/Events/SkillCollectHandler.cs +++ b/scripts/Events/SkillCollectHandler.cs @@ -10,11 +10,10 @@ namespace Mr.BrickAdventures.scripts.Events; /// public partial class SkillCollectHandler : Node { - private SkillManager _skillManager; + private SkillManager SkillManager => SkillManager.Instance; public override void _Ready() { - _skillManager = SkillManager.Instance; EventBus.Instance.SkillCollected += OnSkillCollected; } @@ -35,7 +34,7 @@ public partial class SkillCollectHandler : Node // Immediately activate the skill for the player skill.Level = 1; - _skillManager?.AddSkill(skill); + SkillManager?.AddSkill(skill); // Emit skill unlocked event for UI/achievements EventBus.EmitSkillUnlocked(skill.Name, skill.Level); diff --git a/scripts/Events/StatisticsEventHandler.cs b/scripts/Events/StatisticsEventHandler.cs index 9a41c3a..66b311f 100644 --- a/scripts/Events/StatisticsEventHandler.cs +++ b/scripts/Events/StatisticsEventHandler.cs @@ -9,12 +9,10 @@ namespace Mr.BrickAdventures.scripts.Events; /// public partial class StatisticsEventHandler : Node { - private StatisticsManager _statisticsManager; + private StatisticsManager StatisticsManager => StatisticsManager.Instance; public override void _Ready() { - _statisticsManager = StatisticsManager.Instance; - // Subscribe to events EventBus.Instance.CoinCollected += OnCoinCollected; EventBus.Instance.EnemyDefeated += OnEnemyDefeated; @@ -36,26 +34,26 @@ public partial class StatisticsEventHandler : Node private void OnCoinCollected(int amount, Vector2 position) { - _statisticsManager.IncrementStat("coins_collected", amount); + StatisticsManager.IncrementStat("coins_collected", amount); } private void OnEnemyDefeated(Node enemy, Vector2 position) { - _statisticsManager.IncrementStat("enemies_defeated"); + StatisticsManager.IncrementStat("enemies_defeated"); } private void OnPlayerDied(Vector2 position) { - _statisticsManager.IncrementStat("deaths"); + StatisticsManager.IncrementStat("deaths"); } private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime) { - _statisticsManager.IncrementStat("levels_completed"); + StatisticsManager.IncrementStat("levels_completed"); } private void OnChildRescued(Vector2 position) { - _statisticsManager.IncrementStat("children_rescued"); + StatisticsManager.IncrementStat("children_rescued"); } } diff --git a/scripts/UI/ChargeProgressBar.cs b/scripts/UI/ChargeProgressBar.cs index 286295f..21b4568 100644 --- a/scripts/UI/ChargeProgressBar.cs +++ b/scripts/UI/ChargeProgressBar.cs @@ -1,5 +1,4 @@ using Godot; -using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -18,7 +17,7 @@ public partial class ChargeProgressBar : ProgressBar { ProgressBar.Hide(); - _skillManager = GetNodeOrNull(Constants.SkillManagerPath); + _skillManager = SkillManager.Instance; if (_skillManager == null) { GD.PrintErr("ChargeProgressBar: SkillManager autoload not found."); diff --git a/scripts/UI/DeathScreen.cs b/scripts/UI/DeathScreen.cs index 80b56ca..ecf1d0e 100644 --- a/scripts/UI/DeathScreen.cs +++ b/scripts/UI/DeathScreen.cs @@ -1,5 +1,4 @@ using Godot; -using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.Resources; using Mr.BrickAdventures.scripts.State; @@ -15,13 +14,11 @@ public partial class DeathScreen : Control [Export] public float TimeoutTime { get; set; } = 2.0f; [Export] public Godot.Collections.Array NodesToDisable { get; set; } = new(); - private GameManager _gameManager; + private GameManager GameManager => GameManager.Instance; private Timer _timer; public override void _Ready() { - _gameManager = GameManager.Instance; - // Subscribe to lives changed event for reactive updates EventBus.Instance.LivesChanged += OnLivesChanged; } @@ -74,7 +71,7 @@ public partial class DeathScreen : Control public void OnPlayerDeath() { - if (_gameManager == null) return; + if (GameManager == null) return; ToggleNodes(); SetLabels(); diff --git a/scripts/UI/Marketplace.cs b/scripts/UI/Marketplace.cs index 1e91681..7e8bcae 100644 --- a/scripts/UI/Marketplace.cs +++ b/scripts/UI/Marketplace.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Godot; using Godot.Collections; -using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -19,17 +18,14 @@ public partial class Marketplace : Control [Export] public PackedScene MarketplaceButtonScene { get; set; } [Export] public PackedScene SkillButtonScene { get; set; } - private GameManager _gameManager; - private SkillManager _skillManager; + private GameManager GameManager => GameManager.Instance; + private SkillManager SkillManager => SkillManager.Instance; private readonly List