feat: Implement a comprehensive global event bus with new event handlers and integrate player health and collection events.
This commit is contained in:
34
scripts/Events/ScoreEventHandler.cs
Normal file
34
scripts/Events/ScoreEventHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.Autoloads;
|
||||
|
||||
namespace Mr.BrickAdventures.scripts.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handles coin collection events and updates the session state.
|
||||
/// Replaces the manual signal wiring in ScoreComponent.
|
||||
/// </summary>
|
||||
public partial class ScoreEventHandler : Node
|
||||
{
|
||||
private GameManager _gameManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||
|
||||
EventBus.Instance.CoinCollected += OnCoinCollected;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (EventBus.Instance != null)
|
||||
EventBus.Instance.CoinCollected -= OnCoinCollected;
|
||||
}
|
||||
|
||||
private void OnCoinCollected(int amount, Vector2 position)
|
||||
{
|
||||
var currentCoins = (int)_gameManager.CurrentSessionState["coins_collected"];
|
||||
_gameManager.CurrentSessionState["coins_collected"] = currentCoins + amount;
|
||||
GD.Print($"ScoreEventHandler: Collected {amount} coins. Total session coins: {currentCoins + amount}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user