35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
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}");
|
|
}
|
|
}
|