refactor: enhance GameStateStore integration and improve skill management
This commit is contained in:
@@ -15,8 +15,11 @@ public partial class GhostEventHandler : Node
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
EventBus.Instance.LevelStarted -= OnLevelStarted;
|
||||
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||
if (EventBus.Instance != null)
|
||||
{
|
||||
EventBus.Instance.LevelStarted -= OnLevelStarted;
|
||||
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLevelStarted(int levelIndex, Node currentScene)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handles level completion events and updates GameStateStore.
|
||||
/// </summary>
|
||||
public partial class LevelStateHandler : Node
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
EventBus.Instance.LevelCompleted += OnLevelCompleted;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (EventBus.Instance != null)
|
||||
{
|
||||
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||
{
|
||||
// State mutations (commit coins/skills, reset session) are handled by GameManager.OnLevelComplete
|
||||
// before this event fires. This handler is reserved for future level-specific side-effects.
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://gx5vn7viphv
|
||||
@@ -33,7 +33,6 @@ public partial class SkillCollectHandler : Node
|
||||
GameStateStore.Instance?.UnlockSkillInSession(skill);
|
||||
|
||||
// Immediately activate the skill for the player
|
||||
skill.Level = 1;
|
||||
SkillManager?.AddSkill(skill);
|
||||
|
||||
// Emit skill unlocked event for UI/achievements
|
||||
|
||||
@@ -13,7 +13,8 @@ public partial class SpeedRunEventHandler : Node
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||
if (EventBus.Instance != null)
|
||||
EventBus.Instance.LevelCompleted -= OnLevelCompleted;
|
||||
}
|
||||
|
||||
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
using Mr.BrickAdventures.scripts.State;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handles game events and updates statistics accordingly.
|
||||
/// Listens to EventBus signals and increments relevant stats.
|
||||
/// </summary>
|
||||
public partial class StatisticsEventHandler : Node
|
||||
{
|
||||
private StatisticsManager StatisticsManager => StatisticsManager.Instance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Subscribe to events
|
||||
EventBus.Instance.CoinCollected += OnCoinCollected;
|
||||
EventBus.Instance.EnemyDefeated += OnEnemyDefeated;
|
||||
EventBus.Instance.PlayerDied += OnPlayerDied;
|
||||
@@ -33,27 +30,17 @@ public partial class StatisticsEventHandler : Node
|
||||
}
|
||||
|
||||
private void OnCoinCollected(int amount, Vector2 position)
|
||||
{
|
||||
StatisticsManager.IncrementStat("coins_collected", amount);
|
||||
}
|
||||
=> GameStateStore.Instance?.IncrementStat(StatNames.CoinsCollected, amount);
|
||||
|
||||
private void OnEnemyDefeated(Node enemy, Vector2 position)
|
||||
{
|
||||
StatisticsManager.IncrementStat("enemies_defeated");
|
||||
}
|
||||
=> GameStateStore.Instance?.IncrementStat(StatNames.EnemiesDefeated);
|
||||
|
||||
private void OnPlayerDied(Vector2 position)
|
||||
{
|
||||
StatisticsManager.IncrementStat("deaths");
|
||||
}
|
||||
=> GameStateStore.Instance?.IncrementStat(StatNames.Deaths);
|
||||
|
||||
private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
|
||||
{
|
||||
StatisticsManager.IncrementStat("levels_completed");
|
||||
}
|
||||
=> GameStateStore.Instance?.IncrementStat(StatNames.LevelsCompleted);
|
||||
|
||||
private void OnChildRescued(Vector2 position)
|
||||
{
|
||||
StatisticsManager.IncrementStat("children_rescued");
|
||||
}
|
||||
=> GameStateStore.Instance?.IncrementStat(StatNames.ChildrenRescued);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user