using Godot; using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.Events; /// /// Handles coin collection events and updates the session state. /// Replaces the manual signal wiring in ScoreComponent. /// public partial class ScoreEventHandler : Node { private GameManager _gameManager; public override void _Ready() { _gameManager = GetNode(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}"); } }