From 62bdf1ba39bea275832cd1db3bbf0011f65ec280 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 31 Jan 2026 15:15:52 +0100 Subject: [PATCH 1/9] feat: Implement a comprehensive global event bus with new event handlers and integrate player health and collection events. --- Autoloads/EventBus.cs | 121 +++++++++++++++++++ Autoloads/GameManager.cs | 61 +++++----- objects/entities/brick_player.tscn | 6 +- project.godot | 2 + scripts/Constants.cs | 23 ++++ scripts/Constants.cs.uid | 1 + scripts/Events/GhostEventHandler.cs | 12 +- scripts/Events/ScoreEventHandler.cs | 34 ++++++ scripts/Events/ScoreEventHandler.cs.uid | 1 + scripts/Events/SpeedRunEventHandler.cs | 8 +- scripts/Events/StatisticsEventHandler.cs | 62 ++++++++++ scripts/Events/StatisticsEventHandler.cs.uid | 1 + scripts/components/CollectableComponent.cs | 9 +- scripts/components/EnemyDeathComponent.cs | 9 +- scripts/components/HealthComponent.cs | 26 ++-- 15 files changed, 322 insertions(+), 54 deletions(-) create mode 100644 scripts/Constants.cs create mode 100644 scripts/Constants.cs.uid create mode 100644 scripts/Events/ScoreEventHandler.cs create mode 100644 scripts/Events/ScoreEventHandler.cs.uid create mode 100644 scripts/Events/StatisticsEventHandler.cs create mode 100644 scripts/Events/StatisticsEventHandler.cs.uid diff --git a/Autoloads/EventBus.cs b/Autoloads/EventBus.cs index 9b03718..fd881de 100644 --- a/Autoloads/EventBus.cs +++ b/Autoloads/EventBus.cs @@ -1,9 +1,130 @@ using Godot; +using Mr.BrickAdventures.scripts.components; +using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; +/// +/// Global event bus for decoupled communication between game systems. +/// Use the static Instance property for easy access from anywhere. +/// public partial class EventBus : Node { + /// + /// Singleton instance. Available after the autoload is initialized. + /// + public static EventBus Instance { get; private set; } + + public override void _Ready() + { + Instance = this; + } + + public override void _ExitTree() + { + if (Instance == this) + Instance = null; + } + + #region Level Events + [Signal] public delegate void LevelStartedEventHandler(int levelIndex, Node currentScene); [Signal] public delegate void LevelCompletedEventHandler(int levelIndex, Node currentScene, double completionTime); + [Signal] public delegate void LevelRestartedEventHandler(int levelIndex); + + public static void EmitLevelStarted(int levelIndex, Node currentScene) + => Instance?.EmitSignal(SignalName.LevelStarted, levelIndex, currentScene); + + public static void EmitLevelCompleted(int levelIndex, Node currentScene, double completionTime) + => Instance?.EmitSignal(SignalName.LevelCompleted, levelIndex, currentScene, completionTime); + + public static void EmitLevelRestarted(int levelIndex) + => Instance?.EmitSignal(SignalName.LevelRestarted, levelIndex); + + #endregion + + #region Player Events + + [Signal] public delegate void PlayerSpawnedEventHandler(PlayerController player); + [Signal] public delegate void PlayerDiedEventHandler(Vector2 position); + [Signal] public delegate void PlayerDamagedEventHandler(float damage, float remainingHealth, Vector2 position); + [Signal] public delegate void PlayerHealedEventHandler(float amount, float newHealth, Vector2 position); + + public static void EmitPlayerSpawned(PlayerController player) + => Instance?.EmitSignal(SignalName.PlayerSpawned, player); + + public static void EmitPlayerDied(Vector2 position) + => Instance?.EmitSignal(SignalName.PlayerDied, position); + + public static void EmitPlayerDamaged(float damage, float remainingHealth, Vector2 position) + => Instance?.EmitSignal(SignalName.PlayerDamaged, damage, remainingHealth, position); + + public static void EmitPlayerHealed(float amount, float newHealth, Vector2 position) + => Instance?.EmitSignal(SignalName.PlayerHealed, amount, newHealth, position); + + #endregion + + #region Combat Events + + [Signal] public delegate void EnemyDefeatedEventHandler(Node enemy, Vector2 position); + [Signal] public delegate void EnemyDamagedEventHandler(Node enemy, float damage, Vector2 position); + + public static void EmitEnemyDefeated(Node enemy, Vector2 position) + => Instance?.EmitSignal(SignalName.EnemyDefeated, enemy, position); + + public static void EmitEnemyDamaged(Node enemy, float damage, Vector2 position) + => Instance?.EmitSignal(SignalName.EnemyDamaged, enemy, damage, position); + + #endregion + + #region Collection Events + + [Signal] public delegate void CoinCollectedEventHandler(int amount, Vector2 position); + [Signal] public delegate void ItemCollectedEventHandler(CollectableType itemType, float amount, Vector2 position); + [Signal] public delegate void ChildRescuedEventHandler(Vector2 position); + + public static void EmitCoinCollected(int amount, Vector2 position) + => Instance?.EmitSignal(SignalName.CoinCollected, amount, position); + + public static void EmitItemCollected(CollectableType itemType, float amount, Vector2 position) + => Instance?.EmitSignal(SignalName.ItemCollected, (int)itemType, amount, position); + + public static void EmitChildRescued(Vector2 position) + => Instance?.EmitSignal(SignalName.ChildRescued, position); + + #endregion + + #region Skill Events + + [Signal] public delegate void SkillUnlockedEventHandler(string skillName, int level); + [Signal] public delegate void SkillActivatedEventHandler(string skillName); + [Signal] public delegate void SkillDeactivatedEventHandler(string skillName); + + public static void EmitSkillUnlocked(string skillName, int level = 1) + => Instance?.EmitSignal(SignalName.SkillUnlocked, skillName, level); + + public static void EmitSkillActivated(string skillName) + => Instance?.EmitSignal(SignalName.SkillActivated, skillName); + + public static void EmitSkillDeactivated(string skillName) + => Instance?.EmitSignal(SignalName.SkillDeactivated, skillName); + + #endregion + + #region Game State Events + + [Signal] public delegate void GamePausedEventHandler(); + [Signal] public delegate void GameResumedEventHandler(); + [Signal] public delegate void GameSavedEventHandler(); + + public static void EmitGamePaused() + => Instance?.EmitSignal(SignalName.GamePaused); + + public static void EmitGameResumed() + => Instance?.EmitSignal(SignalName.GameResumed); + + public static void EmitGameSaved() + => Instance?.EmitSignal(SignalName.GameSaved); + + #endregion } \ No newline at end of file diff --git a/Autoloads/GameManager.cs b/Autoloads/GameManager.cs index f449190..6997c1a 100644 --- a/Autoloads/GameManager.cs +++ b/Autoloads/GameManager.cs @@ -10,18 +10,19 @@ namespace Mr.BrickAdventures.Autoloads; public partial class GameManager : Node { [Export] public Array LevelScenes { get; set; } = []; - - public PlayerController Player { + + public PlayerController Player + { get => GetPlayer(); private set => _player = value; } - + private List _sceneNodes = []; private PlayerController _player; private SpeedRunManager _speedRunManager; - private EventBus _eventBus; - - [Export] + + + [Export] public Dictionary PlayerState { get; set; } = new() { { "coins", 0 }, @@ -31,7 +32,7 @@ public partial class GameManager : Node { "unlocked_levels", new Array() {0}}, { "unlocked_skills", new Array() } }; - + [Export] public Dictionary CurrentSessionState { get; private set; } = new() { @@ -55,14 +56,14 @@ public partial class GameManager : Node public override void _Ready() { _speedRunManager = GetNode("/root/SpeedRunManager"); - _eventBus = GetNode("/root/EventBus"); + } private void OnNodeAdded(Node node) { _sceneNodes.Add(node); } - + private void OnNodeRemoved(Node node) { _sceneNodes.Remove(node); @@ -76,11 +77,11 @@ public partial class GameManager : Node { PlayerState["coins"] = Mathf.Max(0, (int)PlayerState["coins"] + amount); } - + public void SetCoins(int amount) => PlayerState["coins"] = Mathf.Max(0, amount); - + public int GetCoins() => (int)PlayerState["coins"] + (int)CurrentSessionState["coins_collected"]; - + public void RemoveCoins(int amount) { var sessionCoins = (int)CurrentSessionState["coins_collected"]; @@ -96,12 +97,12 @@ public partial class GameManager : Node } PlayerState["coins"] = Mathf.Max(0, (int)PlayerState["coins"]); } - + public void AddLives(int amount) => PlayerState["lives"] = (int)PlayerState["lives"] + amount; public void RemoveLives(int amount) => PlayerState["lives"] = (int)PlayerState["lives"] - amount; public void SetLives(int amount) => PlayerState["lives"] = amount; public int GetLives() => (int)PlayerState["lives"]; - + public bool IsSkillUnlocked(SkillData skill) { return ((Array)PlayerState["unlocked_skills"]).Contains(skill) @@ -120,7 +121,7 @@ public partial class GameManager : Node foreach (SkillData s in arr) { if (s.Name != skillName) continue; - + arr.Remove(s); break; } @@ -145,7 +146,7 @@ public partial class GameManager : Node { "statistics", new Godot.Collections.Dictionary()} }; } - + public void UnlockLevel(int levelIndex) { var unlocked = (Array)PlayerState["unlocked_levels"]; @@ -160,10 +161,10 @@ public partial class GameManager : Node { PlayerState["current_level"] = next; GetTree().ChangeSceneToPacked(LevelScenes[next]); - _eventBus.EmitSignal(EventBus.SignalName.LevelStarted, next, GetTree().CurrentScene); + EventBus.EmitLevelStarted(next, GetTree().CurrentScene); } } - + public void MarkLevelComplete(int levelIndex) { UnlockLevel(levelIndex + 1); @@ -179,7 +180,7 @@ public partial class GameManager : Node { "skills_unlocked", new Array() } }; } - + public void RestartGame() { ResetPlayerState(); @@ -187,19 +188,19 @@ public partial class GameManager : Node GetTree().ChangeSceneToPacked(LevelScenes[0]); GetNode("/root/SaveSystem").SaveGame(); } - + public void QuitGame() => GetTree().Quit(); public void PauseGame() => Engine.TimeScale = 0; public void ResumeGame() => Engine.TimeScale = 1; - + public void StartNewGame() { ResetPlayerState(); ResetCurrentSessionState(); - + _speedRunManager?.StartTimer(); - + GetTree().ChangeSceneToPacked(LevelScenes[0]); GetNode("/root/SaveSystem").SaveGame(); } @@ -220,19 +221,19 @@ public partial class GameManager : Node else GD.PrintErr("No levels unlocked to continue."); } - + public void OnLevelComplete() { var levelIndex = (int)PlayerState["current_level"]; MarkLevelComplete(levelIndex); - + AddCoins((int)CurrentSessionState["coins_collected"]); foreach (var s in (Array)CurrentSessionState["skills_unlocked"]) UnlockSkill((SkillData)s); var completionTime = _speedRunManager?.GetCurrentLevelTime() ?? 0.0; - _eventBus.EmitSignal(EventBus.SignalName.LevelCompleted, levelIndex, GetTree().CurrentScene, completionTime); - + EventBus.EmitLevelCompleted(levelIndex, GetTree().CurrentScene, completionTime); + ResetCurrentSessionState(); TryToGoToNextLevel(); GetNode("/root/SaveSystem").SaveGame(); @@ -253,17 +254,17 @@ public partial class GameManager : Node public PlayerController GetPlayer() { if (_player != null && IsInstanceValid(_player)) return _player; - + _player = null; foreach (var node in _sceneNodes) { if (node is not PlayerController player) continue; - + _player = player; return _player; } - + GD.PrintErr("PlayerController not found in the scene tree."); return null; } diff --git a/objects/entities/brick_player.tscn b/objects/entities/brick_player.tscn index eceaf7f..0ff0d6c 100644 --- a/objects/entities/brick_player.tscn +++ b/objects/entities/brick_player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=58 format=3 uid="uid://bqi5s710xb1ju"] +[gd_scene load_steps=57 format=3 uid="uid://bqi5s710xb1ju"] [ext_resource type="Script" uid="uid://csel4s0e4g5uf" path="res://scripts/components/PlayerController.cs" id="1_yysbb"] [ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="2_lgb3u"] @@ -19,7 +19,6 @@ [ext_resource type="PackedScene" uid="uid://dre1vit1m4d2n" path="res://objects/movement_abilities/grid_movement_ability.tscn" id="8_xuhvf"] [ext_resource type="Script" uid="uid://dy78ak8eykw6e" path="res://scripts/components/FlipComponent.cs" id="9_yysbb"] [ext_resource type="Script" uid="uid://mnjg3p0aw1ow" path="res://scripts/components/CanPickUpComponent.cs" id="10_yysbb"] -[ext_resource type="Script" uid="uid://ccqb8kd5m0eh7" path="res://scripts/components/ScoreComponent.cs" id="11_o1ihh"] [ext_resource type="Script" uid="uid://dgb8bqcri7nsj" path="res://scripts/components/HealthComponent.cs" id="12_ur2y5"] [ext_resource type="Script" uid="uid://byw1legrv1ep2" path="res://scripts/components/PlayerDeathComponent.cs" id="13_7til7"] [ext_resource type="Script" uid="uid://cecelixl41t3j" path="res://scripts/components/InvulnerabilityComponent.cs" id="15_xuhvf"] @@ -175,9 +174,6 @@ shape = SubResource("RectangleShape2D_vad0t") [node name="CanPickUpComponent" type="Node" parent="."] script = ExtResource("10_yysbb") -[node name="ScoreComponent" type="Node" parent="."] -script = ExtResource("11_o1ihh") - [node name="HealthComponent" type="Node2D" parent="." node_paths=PackedStringArray("HurtSfx", "HealSfx")] script = ExtResource("12_ur2y5") HurtSfx = NodePath("../sfx_hurt") diff --git a/project.godot b/project.godot index d8a3535..69c2537 100644 --- a/project.godot +++ b/project.godot @@ -46,6 +46,8 @@ EventBus="*res://Autoloads/EventBus.cs" StatisticsManager="*res://Autoloads/StatisticsManager.cs" SpeedRunManager="res://Autoloads/SpeedRunManager.cs" GhostManager="res://objects/ghost_manager.tscn" +ScoreEventHandler="*res://scripts/Events/ScoreEventHandler.cs" +StatisticsEventHandler="*res://scripts/Events/StatisticsEventHandler.cs" [debug] diff --git a/scripts/Constants.cs b/scripts/Constants.cs new file mode 100644 index 0000000..6dab51b --- /dev/null +++ b/scripts/Constants.cs @@ -0,0 +1,23 @@ +namespace Mr.BrickAdventures; + +/// +/// Constants for autoload paths and other commonly used values. +/// +public static class Constants +{ + // Autoload paths + public const string EventBusPath = "/root/EventBus"; + public const string GameManagerPath = "/root/GameManager"; + public const string SaveSystemPath = "/root/SaveSystem"; + public const string SpeedRunManagerPath = "/root/SpeedRunManager"; + public const string GhostManagerPath = "/root/GhostManager"; + public const string AchievementManagerPath = "/root/AchievementManager"; + public const string StatisticsManagerPath = "/root/StatisticsManager"; + public const string SkillManagerPath = "/root/SkillManager"; + public const string FloatingTextManagerPath = "/root/FloatingTextManager"; + public const string UIManagerPath = "/root/UIManager"; + public const string ConsoleManagerPath = "/root/ConsoleManager"; + + // Group names + public const string CoinsGroup = "coins"; +} diff --git a/scripts/Constants.cs.uid b/scripts/Constants.cs.uid new file mode 100644 index 0000000..b78e143 --- /dev/null +++ b/scripts/Constants.cs.uid @@ -0,0 +1 @@ +uid://bn7o3n3bomvrd diff --git a/scripts/Events/GhostEventHandler.cs b/scripts/Events/GhostEventHandler.cs index 6a0aab2..3fe6e5e 100644 --- a/scripts/Events/GhostEventHandler.cs +++ b/scripts/Events/GhostEventHandler.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.Events; @@ -10,11 +11,10 @@ public partial class GhostEventHandler : Node public override void _Ready() { - _ghostManager = GetNode("/root/GhostManager"); - var eventBus = GetNode("/root/EventBus"); - - eventBus.LevelStarted += OnLevelStarted; - eventBus.LevelCompleted += OnLevelCompleted; + _ghostManager = GetNode(Constants.GhostManagerPath); + + EventBus.Instance.LevelStarted += OnLevelStarted; + EventBus.Instance.LevelCompleted += OnLevelCompleted; } private void OnLevelStarted(int levelIndex, Node currentScene) @@ -23,7 +23,7 @@ public partial class GhostEventHandler : Node _ghostManager.StartRecording(levelIndex); _ghostManager.SpawnGhostPlayer(levelIndex, currentScene); } - + private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime) { _ghostManager.StopRecording(true, completionTime); diff --git a/scripts/Events/ScoreEventHandler.cs b/scripts/Events/ScoreEventHandler.cs new file mode 100644 index 0000000..0bb7b43 --- /dev/null +++ b/scripts/Events/ScoreEventHandler.cs @@ -0,0 +1,34 @@ +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}"); + } +} diff --git a/scripts/Events/ScoreEventHandler.cs.uid b/scripts/Events/ScoreEventHandler.cs.uid new file mode 100644 index 0000000..c168916 --- /dev/null +++ b/scripts/Events/ScoreEventHandler.cs.uid @@ -0,0 +1 @@ +uid://cs4cfk7g5vh2v diff --git a/scripts/Events/SpeedRunEventHandler.cs b/scripts/Events/SpeedRunEventHandler.cs index 93acbd2..babe841 100644 --- a/scripts/Events/SpeedRunEventHandler.cs +++ b/scripts/Events/SpeedRunEventHandler.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.Events; @@ -10,10 +11,9 @@ public partial class SpeedRunEventHandler : Node public override void _Ready() { - _speedRunManager = GetNode("/root/SpeedRunManager"); - var eventBus = GetNode("/root/EventBus"); - - eventBus.LevelCompleted += OnLevelCompleted; + _speedRunManager = GetNode(Constants.SpeedRunManagerPath); + + EventBus.Instance.LevelCompleted += OnLevelCompleted; } private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime) diff --git a/scripts/Events/StatisticsEventHandler.cs b/scripts/Events/StatisticsEventHandler.cs new file mode 100644 index 0000000..420d6b9 --- /dev/null +++ b/scripts/Events/StatisticsEventHandler.cs @@ -0,0 +1,62 @@ +using Godot; +using Mr.BrickAdventures; +using Mr.BrickAdventures.Autoloads; + +namespace Mr.BrickAdventures.scripts.Events; + +/// +/// Handles game events and updates statistics accordingly. +/// Listens to EventBus signals and increments relevant stats. +/// +public partial class StatisticsEventHandler : Node +{ + private StatisticsManager _statisticsManager; + + public override void _Ready() + { + _statisticsManager = GetNode(Constants.StatisticsManagerPath); + + // Subscribe to events + EventBus.Instance.CoinCollected += OnCoinCollected; + EventBus.Instance.EnemyDefeated += OnEnemyDefeated; + EventBus.Instance.PlayerDied += OnPlayerDied; + EventBus.Instance.LevelCompleted += OnLevelCompleted; + EventBus.Instance.ChildRescued += OnChildRescued; + } + + public override void _ExitTree() + { + if (EventBus.Instance == null) return; + + EventBus.Instance.CoinCollected -= OnCoinCollected; + EventBus.Instance.EnemyDefeated -= OnEnemyDefeated; + EventBus.Instance.PlayerDied -= OnPlayerDied; + EventBus.Instance.LevelCompleted -= OnLevelCompleted; + EventBus.Instance.ChildRescued -= OnChildRescued; + } + + private void OnCoinCollected(int amount, Vector2 position) + { + _statisticsManager.IncrementStat("coins_collected", amount); + } + + private void OnEnemyDefeated(Node enemy, Vector2 position) + { + _statisticsManager.IncrementStat("enemies_defeated"); + } + + private void OnPlayerDied(Vector2 position) + { + _statisticsManager.IncrementStat("deaths"); + } + + private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime) + { + _statisticsManager.IncrementStat("levels_completed"); + } + + private void OnChildRescued(Vector2 position) + { + _statisticsManager.IncrementStat("children_rescued"); + } +} diff --git a/scripts/Events/StatisticsEventHandler.cs.uid b/scripts/Events/StatisticsEventHandler.cs.uid new file mode 100644 index 0000000..11d654b --- /dev/null +++ b/scripts/Events/StatisticsEventHandler.cs.uid @@ -0,0 +1 @@ +uid://l68tjau3k6bw diff --git a/scripts/components/CollectableComponent.cs b/scripts/components/CollectableComponent.cs index 2a925af..418b33d 100644 --- a/scripts/components/CollectableComponent.cs +++ b/scripts/components/CollectableComponent.cs @@ -1,5 +1,6 @@ using System; using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.Resources; @@ -35,7 +36,7 @@ public partial class CollectableComponent : Node if (Owner.HasNode("FadeAwayComponent")) _hasFadeAway = true; - _floatingTextManager = GetNode("/root/FloatingTextManager"); + _floatingTextManager = GetNode(Constants.FloatingTextManagerPath); } private async void OnArea2DBodyEntered(Node2D body) @@ -53,12 +54,18 @@ public partial class CollectableComponent : Node { case CollectableType.Coin: _floatingTextManager?.ShowCoin((int)Data.Amount, ownerNode.GlobalPosition); + EventBus.EmitCoinCollected((int)Data.Amount, ownerNode.GlobalPosition); break; case CollectableType.Health: _floatingTextManager?.ShowMessage("Healed!", ownerNode.GlobalPosition); + EventBus.EmitItemCollected(Data.Type, Data.Amount, ownerNode.GlobalPosition); break; case CollectableType.Kid: _floatingTextManager?.ShowMessage("Rescued!", ownerNode.GlobalPosition); + EventBus.EmitChildRescued(ownerNode.GlobalPosition); + break; + default: + EventBus.EmitItemCollected(Data.Type, Data.Amount, ownerNode.GlobalPosition); break; } } diff --git a/scripts/components/EnemyDeathComponent.cs b/scripts/components/EnemyDeathComponent.cs index 330e66f..2e9722a 100644 --- a/scripts/components/EnemyDeathComponent.cs +++ b/scripts/components/EnemyDeathComponent.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Godot; +using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.components; @@ -23,7 +24,7 @@ public partial class EnemyDeathComponent : Node GD.PushError("EnemyDeathComponent: Health is not set."); return; } - + Health.Death += OnDeath; } @@ -34,6 +35,12 @@ public partial class EnemyDeathComponent : Node private async Task Die() { + // Emit enemy defeated event for statistics and other systems + if (Owner is Node2D ownerNode) + { + EventBus.EmitEnemyDefeated(Owner, ownerNode.GlobalPosition); + } + CollisionShape.SetDisabled(true); var tween = CreateTween(); tween.TweenProperty(Owner, "scale", Vector2.Zero, TweenDuration); diff --git a/scripts/components/HealthComponent.cs b/scripts/components/HealthComponent.cs index 49484b0..685dd2a 100644 --- a/scripts/components/HealthComponent.cs +++ b/scripts/components/HealthComponent.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.components; @@ -11,22 +12,22 @@ public partial class HealthComponent : Node2D [Export] public float MaxHealth { get; set; } = 1.0f; [Export] public AudioStreamPlayer2D HurtSfx { get; set; } [Export] public AudioStreamPlayer2D HealSfx { get; set; } - + [Signal] public delegate void HealthChangedEventHandler(float delta, float totalHealth); [Signal] public delegate void DeathEventHandler(); - + private FloatingTextManager _floatingTextManager; public override void _Ready() { - _floatingTextManager = GetNode("/root/FloatingTextManager"); + _floatingTextManager = GetNode(Constants.FloatingTextManagerPath); } - + public void SetHealth(float newValue) { _ = ApplyHealthChange(newValue); } - + public void IncreaseHealth(float delta) { _ = ApplyHealthChange(Health + delta); @@ -46,7 +47,7 @@ public partial class HealthComponent : Node2D if (delta == 0.0f) return; - + if (delta < 0.0f) _floatingTextManager?.ShowDamage(Mathf.Abs(delta), GlobalPosition); else @@ -64,16 +65,27 @@ public partial class HealthComponent : Node2D await HurtSfx.ToSignal(HurtSfx, AudioStreamPlayer2D.SignalName.Finished); } } - + Health = newHealth; if (Health <= 0f) { EmitSignalDeath(); + // Emit global event if this is the player + if (Owner is PlayerController) + EventBus.EmitPlayerDied(GlobalPosition); } else { EmitSignalHealthChanged(delta, Health); + // Emit global events if this is the player + if (Owner is PlayerController) + { + if (delta < 0f) + EventBus.EmitPlayerDamaged(Mathf.Abs(delta), Health, GlobalPosition); + else + EventBus.EmitPlayerHealed(delta, Health, GlobalPosition); + } } } } \ No newline at end of file -- 2.49.1 From b62478bbeab0db99c2092eba0f3dc029328a03e3 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 31 Jan 2026 15:35:04 +0100 Subject: [PATCH 2/9] refactor: Replace hardcoded node paths with constants and remove ScoreComponent. --- Autoloads/AchievementManager.cs | 15 ++++--- Autoloads/ConsoleManager.cs | 19 ++++---- Autoloads/GameManager.cs | 11 ++--- Autoloads/SaveSystem.cs | 9 ++-- Autoloads/SkillManager.cs | 31 ++++++------- Autoloads/StatisticsManager.cs | 7 +-- scripts/Constants.cs | 1 + scripts/UI/AudioSettings.cs | 19 ++++---- scripts/UI/ChargeProgressBar.cs | 19 ++++---- scripts/UI/Credits.cs | 3 +- scripts/UI/DeathScreen.cs | 25 +++++------ scripts/UI/GameOverScreen.cs | 9 ++-- scripts/UI/Hud.cs | 3 +- scripts/UI/MainMenu.cs | 9 ++-- scripts/UI/Marketplace.cs | 27 ++++++------ scripts/UI/MarketplaceButton.cs | 17 ++++---- scripts/UI/PauseMenu.cs | 5 ++- scripts/UI/SettingsMenu.cs | 11 ++--- scripts/UI/SpeedRunHud.cs | 9 ++-- .../components/BrickShieldSkillComponent.cs | 9 ++-- scripts/components/ExitDoorComponent.cs | 15 ++++--- scripts/components/LeverComponent.cs | 13 +++--- scripts/components/PlayerController.cs | 43 ++++++++++--------- scripts/components/PlayerDeathComponent.cs | 7 +-- scripts/components/ScoreComponent.cs | 43 ------------------- scripts/components/ScoreComponent.cs.uid | 1 - scripts/components/SkillUnlockerComponent.cs | 5 ++- 27 files changed, 183 insertions(+), 202 deletions(-) delete mode 100644 scripts/components/ScoreComponent.cs delete mode 100644 scripts/components/ScoreComponent.cs.uid diff --git a/Autoloads/AchievementManager.cs b/Autoloads/AchievementManager.cs index 5b275e9..38105e8 100644 --- a/Autoloads/AchievementManager.cs +++ b/Autoloads/AchievementManager.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; @@ -8,14 +9,14 @@ public partial class AchievementManager : Node { [Export] private string AchievementsFolderPath = "res://achievements/"; [Export] private PackedScene AchievementPopupScene { get; set; } - + private System.Collections.Generic.Dictionary _achievements = new(); private Array _unlockedAchievementIds = []; private GameManager _gameManager; - + public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); LoadAchievementsFromFolder(); LoadUnlockedAchievements(); } @@ -44,7 +45,7 @@ public partial class AchievementManager : Node fileName = dir.GetNext(); } } - + public void UnlockAchievement(string achievementId) { if (!_achievements.TryGetValue(achievementId, out var achievement)) @@ -75,11 +76,11 @@ public partial class AchievementManager : Node { SteamManager.UnlockAchievement(achievement.Id); } - + // 4. Save progress SaveUnlockedAchievements(); } - + public void LockAchievement(string achievementId) { if (_unlockedAchievementIds.Contains(achievementId)) @@ -88,7 +89,7 @@ public partial class AchievementManager : Node SaveUnlockedAchievements(); } } - + private void SaveUnlockedAchievements() { _gameManager.PlayerState["unlocked_achievements"] = _unlockedAchievementIds; diff --git a/Autoloads/ConsoleManager.cs b/Autoloads/ConsoleManager.cs index bd7ef9c..a55b84e 100644 --- a/Autoloads/ConsoleManager.cs +++ b/Autoloads/ConsoleManager.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; namespace Mr.BrickAdventures.Autoloads; @@ -12,9 +13,9 @@ public partial class ConsoleManager : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); - _achievementManager = GetNode("/root/AchievementManager"); - _skillManager = GetNode("/root/SkillManager"); + _gameManager = GetNode(Constants.GameManagerPath); + _achievementManager = GetNode(Constants.AchievementManagerPath); + _skillManager = GetNode(Constants.SkillManagerPath); } private void AddCoinsCommand(int amount) @@ -88,7 +89,7 @@ public partial class ConsoleManager : Node _skillUnlockerComponent.UnlockAllSkills(); } - + private void RemoveSkillCommand(string skillName) { if (!GetSkillManagement()) return; @@ -102,28 +103,28 @@ public partial class ConsoleManager : Node _gameManager.RemoveSkill(skill.Name); _skillManager.DeactivateSkill(skill); } - + private void RemoveAllSkillsCommand() { if (!GetSkillManagement()) return; - + foreach (var skill in _skillManager.AvailableSkills) { _gameManager.RemoveSkill(skill.Name); _skillManager.DeactivateSkill(skill); } } - + private void GoToNextLevelCommand() { _gameManager.OnLevelComplete(); } - + private void UnlockAchievementCommand(string achievementId) { _achievementManager.UnlockAchievement(achievementId); } - + private void ResetAchievementCommand(string achievementId) { _achievementManager.LockAchievement(achievementId); diff --git a/Autoloads/GameManager.cs b/Autoloads/GameManager.cs index 6997c1a..b7bfc9f 100644 --- a/Autoloads/GameManager.cs +++ b/Autoloads/GameManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; using Double = System.Double; @@ -55,7 +56,7 @@ public partial class GameManager : Node public override void _Ready() { - _speedRunManager = GetNode("/root/SpeedRunManager"); + _speedRunManager = GetNode(Constants.SpeedRunManagerPath); } @@ -186,7 +187,7 @@ public partial class GameManager : Node ResetPlayerState(); ResetCurrentSessionState(); GetTree().ChangeSceneToPacked(LevelScenes[0]); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public void QuitGame() => GetTree().Quit(); @@ -202,12 +203,12 @@ public partial class GameManager : Node _speedRunManager?.StartTimer(); GetTree().ChangeSceneToPacked(LevelScenes[0]); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public void ContinueGame() { - var save = GetNode("/root/SaveSystem"); + var save = GetNode(Constants.SaveSystemPath); if (!save.LoadGame()) { GD.PrintErr("Failed to load game. Starting a new game instead."); @@ -236,7 +237,7 @@ public partial class GameManager : Node ResetCurrentSessionState(); TryToGoToNextLevel(); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public Array GetUnlockedSkills() diff --git a/Autoloads/SaveSystem.cs b/Autoloads/SaveSystem.cs index d5ce18a..0eeda5f 100644 --- a/Autoloads/SaveSystem.cs +++ b/Autoloads/SaveSystem.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; @@ -13,7 +14,7 @@ public partial class SaveSystem : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } public void SaveGame() @@ -46,16 +47,16 @@ public partial class SaveSystem : Node GD.Print("Game state loaded from: ", SavePath); GD.Print("Player state: ", saveDataObj["player_state"]); _gameManager.PlayerState = (Dictionary)saveDataObj["player_state"]; - + var skills = new Array(); foreach (var skill in (Array)_gameManager.PlayerState["unlocked_skills"]) { skills.Add(skill); } - + _gameManager.UnlockSkills(skills); return true; } - + public bool CheckSaveExists() => FileAccess.FileExists(SavePath); } \ No newline at end of file diff --git a/Autoloads/SkillManager.cs b/Autoloads/SkillManager.cs index d499789..ae525f4 100644 --- a/Autoloads/SkillManager.cs +++ b/Autoloads/SkillManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.interfaces; using Mr.BrickAdventures.scripts.Resources; @@ -14,19 +15,19 @@ public partial class SkillManager : Node private PlayerController _player; [Export] public Array AvailableSkills { get; set; } = []; - + public Dictionary ActiveComponents { get; private set; } = new(); [Signal] public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent); [Signal] public delegate void SkillRemovedEventHandler(SkillData skillData); - + public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } - + /// /// Called by the PlayerController from its _Ready method to register itself with the manager. /// @@ -39,7 +40,7 @@ public partial class SkillManager : Node { UnregisterPlayer(); } - + _player = player; if (_player != null) { @@ -61,7 +62,7 @@ public partial class SkillManager : Node } _player = null; } - + public void AddSkill(SkillData skillData) { // Ensure a valid player is registered before adding a skill. @@ -70,7 +71,7 @@ public partial class SkillManager : Node GD.Print("SkillManager: Player not available to add skill."); return; } - + if (ActiveComponents.ContainsKey(skillData.Name)) return; @@ -98,9 +99,9 @@ public partial class SkillManager : Node if (instance is ISkill skill) { // Initialize the skill with the registered player instance. - skill.Initialize(_player, skillData); + skill.Initialize(_player, skillData); skill.Activate(); - } + } else { GD.PrintErr($"Skill scene for '{skillData.Name}' does not implement ISkill!"); @@ -111,18 +112,18 @@ public partial class SkillManager : Node // Add the skill node as a child of the player. _player.AddChild(instance); ActiveComponents[skillData.Name] = instance; - + if (instance is BrickThrowComponent btc) { - EmitSignalActiveThrowSkillChanged(btc); + EmitSignalActiveThrowSkillChanged(btc); } } - + public void RemoveSkill(string skillName) { if (!ActiveComponents.TryGetValue(skillName, out var component)) return; - + if (component.AsGodotObject() is BrickThrowComponent) { EmitSignalActiveThrowSkillChanged(null); @@ -133,7 +134,7 @@ public partial class SkillManager : Node { skill.Deactivate(); } - + if (IsInstanceValid(inst)) inst.QueueFree(); @@ -150,7 +151,7 @@ public partial class SkillManager : Node var sd = GetSkillByName(skillName); if (sd != null) EmitSignalSkillRemoved(sd); } - + private void RemoveAllActiveSkills() { // Create a copy of keys to avoid modification during iteration diff --git a/Autoloads/StatisticsManager.cs b/Autoloads/StatisticsManager.cs index a9c9ccf..f8406bd 100644 --- a/Autoloads/StatisticsManager.cs +++ b/Autoloads/StatisticsManager.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; namespace Mr.BrickAdventures.Autoloads; @@ -11,8 +12,8 @@ public partial class StatisticsManager : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); - _achievementManager = GetNode("/root/AchievementManager"); + _gameManager = GetNode(Constants.GameManagerPath); + _achievementManager = GetNode(Constants.AchievementManagerPath); LoadStatistics(); } @@ -28,7 +29,7 @@ public partial class StatisticsManager : Node _gameManager.PlayerState["statistics"] = _stats; } } - + /// /// Increases a numerical statistic by a given amount. /// diff --git a/scripts/Constants.cs b/scripts/Constants.cs index 6dab51b..a5b064b 100644 --- a/scripts/Constants.cs +++ b/scripts/Constants.cs @@ -17,6 +17,7 @@ public static class Constants public const string FloatingTextManagerPath = "/root/FloatingTextManager"; public const string UIManagerPath = "/root/UIManager"; public const string ConsoleManagerPath = "/root/ConsoleManager"; + public const string ConfigFileHandlerPath = "/root/ConfigFileHandler"; // Group names public const string CoinsGroup = "coins"; diff --git a/scripts/UI/AudioSettings.cs b/scripts/UI/AudioSettings.cs index b9acc6f..96eeebb 100644 --- a/scripts/UI/AudioSettings.cs +++ b/scripts/UI/AudioSettings.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -10,19 +11,19 @@ public partial class AudioSettings : Control [Export] public Slider SfxVolumeSlider { get; set; } [Export] public Control AudioSettingsControl { get; set; } [Export] public float MuteThreshold { get; set; } = -20f; - + private UIManager _uiManager; private ConfigFileHandler _configFileHandler; public override void _Ready() { - _uiManager = GetNode("/root/UIManager"); - _configFileHandler = GetNode("/root/ConfigFileHandler"); + _uiManager = GetNode(Constants.UIManagerPath); + _configFileHandler = GetNode(Constants.ConfigFileHandlerPath); Initialize(); MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged; MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged; SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged; - + LoadSettings(); } @@ -35,7 +36,7 @@ public partial class AudioSettings : Control { if (!@event.IsActionReleased("ui_cancel")) return; if (!_uiManager.IsScreenOnTop(AudioSettingsControl)) return; - + SaveSettings(); _uiManager.PopScreen(); } @@ -64,12 +65,12 @@ public partial class AudioSettings : Control MasterVolumeSlider.Value = volumeDb; MasterVolumeSlider.MinValue = MuteThreshold; MasterVolumeSlider.MaxValue = 0f; - + var musicVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("music")); MusicVolumeSlider.Value = musicVolumeDb; MusicVolumeSlider.MinValue = MuteThreshold; MusicVolumeSlider.MaxValue = 0f; - + var sfxVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("sfx")); SfxVolumeSlider.Value = sfxVolumeDb; SfxVolumeSlider.MinValue = MuteThreshold; @@ -95,12 +96,12 @@ public partial class AudioSettings : Control { var settingsConfig = _configFileHandler.SettingsConfig; if (!settingsConfig.HasSection("audio_settings")) return; - + var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value); var musicVolume = (float)settingsConfig.GetValue("audio_settings", "music_volume", MusicVolumeSlider.Value); var sfxVolume = (float)settingsConfig.GetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value); var muteThreshold = (float)settingsConfig.GetValue("audio_settings", "mute_threshold", MuteThreshold); - + MasterVolumeSlider.Value = masterVolume; MusicVolumeSlider.Value = musicVolume; SfxVolumeSlider.Value = sfxVolume; diff --git a/scripts/UI/ChargeProgressBar.cs b/scripts/UI/ChargeProgressBar.cs index 91654ef..286295f 100644 --- a/scripts/UI/ChargeProgressBar.cs +++ b/scripts/UI/ChargeProgressBar.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -17,15 +18,15 @@ public partial class ChargeProgressBar : ProgressBar { ProgressBar.Hide(); - _skillManager = GetNodeOrNull("/root/SkillManager"); + _skillManager = GetNodeOrNull(Constants.SkillManagerPath); if (_skillManager == null) { GD.PrintErr("ChargeProgressBar: SkillManager autoload not found."); return; } - + _skillManager.ActiveThrowSkillChanged += OnActiveThrowSkillChanged; - + SetupDependencies(); } @@ -43,7 +44,7 @@ public partial class ChargeProgressBar : ProgressBar OnOwnerExiting(); if (throwComponent == null || !IsInstanceValid(throwComponent)) return; - + _throwComponent = throwComponent; _throwComponent.TreeExiting += OnOwnerExiting; SetupDependencies(); @@ -60,7 +61,7 @@ public partial class ChargeProgressBar : ProgressBar } _throwComponent = null; } - + private void SetupDependencies() { @@ -68,7 +69,7 @@ public partial class ChargeProgressBar : ProgressBar { return; } - + if (_throwComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput) { _throwInput = throwInput; @@ -77,7 +78,7 @@ public partial class ChargeProgressBar : ProgressBar { _throwInput = null; } - + if (_throwInput == null) { return; @@ -88,9 +89,9 @@ public partial class ChargeProgressBar : ProgressBar ProgressBar.Hide(); return; } - + SetupProgressBar(); - + _throwInput.ChargeStarted += OnChargeStarted; _throwInput.ChargeStopped += OnChargeStopped; _throwInput.ChargeUpdated += OnChargeUpdated; diff --git a/scripts/UI/Credits.cs b/scripts/UI/Credits.cs index b0d2d0f..d26b114 100644 --- a/scripts/UI/Credits.cs +++ b/scripts/UI/Credits.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -9,7 +10,7 @@ public partial class Credits : Control public override void _Ready() { - _uiManager = GetNode("/root/UIManager"); + _uiManager = GetNode(Constants.UIManagerPath); } public override void _UnhandledInput(InputEvent @event) diff --git a/scripts/UI/DeathScreen.cs b/scripts/UI/DeathScreen.cs index ce03d99..31f0d2a 100644 --- a/scripts/UI/DeathScreen.cs +++ b/scripts/UI/DeathScreen.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.Resources; @@ -12,27 +13,27 @@ public partial class DeathScreen : Control [Export] public Label LivesLeftLabel { get; set; } [Export] public float TimeoutTime { get; set; } = 2.0f; [Export] public Godot.Collections.Array NodesToDisable { get; set; } = new(); - + private GameManager _gameManager; private Timer _timer; public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); SetLabels(); } - + private void SetLabels() { if (_gameManager == null) return; - + if (CurrentLevel != null) { CurrentLevelLabel.Text = CurrentLevel.LevelName; } LivesLeftLabel.Text = $" x {_gameManager.GetLives()}"; } - + private void SetupTimer() { _timer = new Timer(); @@ -42,31 +43,31 @@ public partial class DeathScreen : Control AddChild(_timer); _timer.Start(); } - + private void ToggleNodes() { foreach (var node in NodesToDisable) { - node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled - ? ProcessModeEnum.Inherit + node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled + ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled; } } - + public void OnPlayerDeath() { if (_gameManager == null) return; - + ToggleNodes(); SetLabels(); Show(); SetupTimer(); } - + private void OnTimeout() { if (_gameManager == null || _gameManager.GetLives() == 0) return; - + GetTree().ReloadCurrentScene(); } } \ No newline at end of file diff --git a/scripts/UI/GameOverScreen.cs b/scripts/UI/GameOverScreen.cs index 6cb17a1..514c728 100644 --- a/scripts/UI/GameOverScreen.cs +++ b/scripts/UI/GameOverScreen.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -9,14 +10,14 @@ public partial class GameOverScreen : Control [Export] public Button RestartButton { get; set; } [Export] public Button MainMenuButton { get; set; } [Export] public PackedScene MainMenuScene { get; set; } - + private GameManager _gameManager; public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); RestartButton.Pressed += OnRestartClicked; - MainMenuButton.Pressed += OnMainMenuClicked; + MainMenuButton.Pressed += OnMainMenuClicked; } private void OnMainMenuClicked() @@ -33,7 +34,7 @@ public partial class GameOverScreen : Control public void OnPlayerDeath() { if (_gameManager == null || _gameManager.GetLives() != 0) return; - + GameOverPanel.Show(); } } \ No newline at end of file diff --git a/scripts/UI/Hud.cs b/scripts/UI/Hud.cs index 9f584ce..cc021a5 100644 --- a/scripts/UI/Hud.cs +++ b/scripts/UI/Hud.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; @@ -15,7 +16,7 @@ public partial class Hud : Control public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } public override void _Process(double delta) diff --git a/scripts/UI/MainMenu.cs b/scripts/UI/MainMenu.cs index b3aa727..bf6810f 100644 --- a/scripts/UI/MainMenu.cs +++ b/scripts/UI/MainMenu.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -14,16 +15,16 @@ public partial class MainMenu : Control [Export] public Label VersionLabel { get; set; } [Export] public Control SettingsControl { get; set; } [Export] public Control CreditsControl { get; set; } - + private SaveSystem _saveSystem; private GameManager _gameManager; private UIManager _uiManager; public override void _Ready() { - _saveSystem = GetNode("/root/SaveSystem"); - _gameManager = GetNode("/root/GameManager"); - _uiManager = GetNode("/root/UIManager"); + _saveSystem = GetNode(Constants.SaveSystemPath); + _gameManager = GetNode(Constants.GameManagerPath); + _uiManager = GetNode(Constants.UIManagerPath); NewGameButton.Pressed += OnNewGamePressed; ContinueButton.Pressed += OnContinuePressed; diff --git a/scripts/UI/Marketplace.cs b/scripts/UI/Marketplace.cs index 4b801c7..7cefe6f 100644 --- a/scripts/UI/Marketplace.cs +++ b/scripts/UI/Marketplace.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -17,7 +18,7 @@ public partial class Marketplace : Control [Export] public Array ComponentsToDisable { get; set; } = []; [Export] public PackedScene MarketplaceButtonScene { get; set; } [Export] public PackedScene SkillButtonScene { get; set; } - + private GameManager _gameManager; private SkillManager _skillManager; private readonly List