refactor #6

Merged
GKaszewski merged 9 commits from refactor into master 2026-02-01 11:47:42 +00:00
Showing only changes of commit 2fc988da27 - Show all commits

View File

@@ -2,6 +2,7 @@ using Godot;
using Mr.BrickAdventures; using Mr.BrickAdventures;
using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.Resources; using Mr.BrickAdventures.scripts.Resources;
using Mr.BrickAdventures.scripts.State;
namespace Mr.BrickAdventures.scripts.UI; namespace Mr.BrickAdventures.scripts.UI;
@@ -20,18 +21,35 @@ public partial class DeathScreen : Control
public override void _Ready() public override void _Ready()
{ {
_gameManager = GetNode<GameManager>(Constants.GameManagerPath); _gameManager = GetNode<GameManager>(Constants.GameManagerPath);
SetLabels();
// Subscribe to lives changed event for reactive updates
EventBus.Instance.LivesChanged += OnLivesChanged;
}
public override void _ExitTree()
{
if (EventBus.Instance != null)
{
EventBus.Instance.LivesChanged -= OnLivesChanged;
}
}
private void OnLivesChanged(int lives)
{
// Update the label when lives change
LivesLeftLabel.Text = $" x {lives}";
} }
private void SetLabels() private void SetLabels()
{ {
if (_gameManager == null) return;
if (CurrentLevel != null) if (CurrentLevel != null)
{ {
CurrentLevelLabel.Text = CurrentLevel.LevelName; CurrentLevelLabel.Text = CurrentLevel.LevelName;
} }
LivesLeftLabel.Text = $" x {_gameManager.GetLives()}";
// Read current lives from store
var lives = GameStateStore.Instance?.Player.Lives ?? 0;
LivesLeftLabel.Text = $" x {lives}";
} }
private void SetupTimer() private void SetupTimer()
@@ -66,7 +84,8 @@ public partial class DeathScreen : Control
private void OnTimeout() private void OnTimeout()
{ {
if (_gameManager == null || _gameManager.GetLives() == 0) return; var lives = GameStateStore.Instance?.Player.Lives ?? 0;
if (lives == 0) return;
GetTree().ReloadCurrentScene(); GetTree().ReloadCurrentScene();
} }