feat: Implement a comprehensive global event bus with new event handlers and integrate player health and collection events.

This commit is contained in:
2026-01-31 15:15:52 +01:00
parent dde3eaa52e
commit 62bdf1ba39
15 changed files with 322 additions and 54 deletions

View 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}");
}
}