feat: lives and death move to the new domain (commit C of the swap)
fixes the regression commit B introduced: coins and skills lived in the Attempt ledger, but nothing discarded it, because LivesStateHandler still called the old store and HandlePlayerDeath was never invoked. Dying kept everything earned that level. Discard-on-death is the ledger's purpose, so it could not be separated from it. new AttemptFailed(remaining, runOver) event, raised after the life is spent and the ledger discarded. DeathScreen and GameOverScreen react to that instead of being wired to HealthComponent.Death by scene connections which fired *before* the life was charged - on the last life game-over saw one life left and showed nothing, then the death screen saw zero and refused to reload. 18 scene connections deleted; the race is now unrepresentable rather than fixed. DeathScreen also had two read paths for lives - a signal and a direct store read - because neither was reliable alone. Now one. Hud reads both facts from signals; only health still polls, and that belongs to the component rather than to progression. GameManager no longer touches GameStateStore or SaveSystem at all.
This commit is contained in:
@@ -12,29 +12,36 @@ public partial class Hud : Control
|
||||
[Export] public ProgressBar HealthBar { get; set; }
|
||||
[Export] public Label LivesLabel { get; set; }
|
||||
|
||||
private GameStateStore Store => GameStateStore.Instance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (EventBus.Instance != null)
|
||||
{
|
||||
EventBus.Instance.CoinsChanged += OnCoinsChanged;
|
||||
EventBus.Instance.LivesChanged += OnLivesChanged;
|
||||
}
|
||||
|
||||
SetCoinsLabel(ProgressionRoot.Instance?.TotalCoins.Value ?? 0);
|
||||
var progression = ProgressionRoot.Instance;
|
||||
SetCoinsLabel(progression?.TotalCoins.Value ?? 0);
|
||||
SetLivesLabel(progression?.Lives.Value ?? 0);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (EventBus.Instance != null)
|
||||
{
|
||||
EventBus.Instance.CoinsChanged -= OnCoinsChanged;
|
||||
EventBus.Instance.LivesChanged -= OnLivesChanged;
|
||||
}
|
||||
}
|
||||
|
||||
// Lives still polls the old store; it moves with the death path in the next commit.
|
||||
// Health belongs to the component on the player, not to progression, so it stays a direct read.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
SetHealthBar();
|
||||
SetLivesLabel();
|
||||
}
|
||||
|
||||
private void OnLivesChanged(int lives) => SetLivesLabel(lives);
|
||||
|
||||
private void OnCoinsChanged(int totalCoins) => SetCoinsLabel(totalCoins);
|
||||
|
||||
private void SetCoinsLabel(int totalCoins)
|
||||
@@ -42,9 +49,9 @@ public partial class Hud : Control
|
||||
CoinsLabel.Text = Tr("COINS_LABEL") + ": " + totalCoins;
|
||||
}
|
||||
|
||||
private void SetLivesLabel()
|
||||
private void SetLivesLabel(int lives)
|
||||
{
|
||||
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + (Store?.Player.Lives ?? 0);
|
||||
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + lives;
|
||||
}
|
||||
|
||||
private void SetHealthBar()
|
||||
|
||||
Reference in New Issue
Block a user