Files
przygody-pana-cegly/scripts/UI/Hud.cs
Gabriel Kaszewski 360f73ba24 feat: coins and skills move to the new domain (commit B of the swap)
atomic pair - purchasing couples them, so neither moves alone.

SkillData.Level is gone. It was an [Export] on a cached Resource: one
instance per process, so the level never persisted, leaked between save
slots, and made "unowned" indistinguishable from "level 1". Level now
comes from the Playthrough and is passed to ISkill.Initialize.

SkillManager reconciles from SkillSetChanged instead of being told by
each caller. The old shape was "record it, then tell SkillManager" as two
calls at four sites; AddSkill's early return when no player is registered
left the skill owned but inert. Reconciliation also tracks the level each
component was built at, so an upgrade rebuilds it rather than being
patched in from outside.

SkillUnlockerComponent collapses to one TryBuy - unlock and upgrade were
two methods each doing affordability, debit, level mutation and manager
notification in order.

The guard three components copy-pasted around Upgrades[Level - 1] - and
which BrickArmor omitted - now lives once in SkillComponentBase.

Hud reads coins from CoinsChanged instead of rebuilding translated
strings every frame. Lives still polls; it moves with the death path.
2026-07-28 20:13:24 +02:00

55 lines
1.5 KiB
C#

using Godot;
using Mr.BrickAdventures;
using Mr.BrickAdventures.Autoloads;
using Mr.BrickAdventures.scripts.components;
namespace Mr.BrickAdventures.scripts.UI;
public partial class Hud : Control
{
[Export] public HealthComponent Health { get; set; }
[Export] public Label CoinsLabel { get; set; }
[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;
SetCoinsLabel(ProgressionRoot.Instance?.TotalCoins.Value ?? 0);
}
public override void _ExitTree()
{
if (EventBus.Instance != null)
EventBus.Instance.CoinsChanged -= OnCoinsChanged;
}
// Lives still polls the old store; it moves with the death path in the next commit.
public override void _Process(double delta)
{
SetHealthBar();
SetLivesLabel();
}
private void OnCoinsChanged(int totalCoins) => SetCoinsLabel(totalCoins);
private void SetCoinsLabel(int totalCoins)
{
CoinsLabel.Text = Tr("COINS_LABEL") + ": " + totalCoins;
}
private void SetLivesLabel()
{
LivesLabel.Text = Tr("LIVES_LABEL") + ": " + (Store?.Player.Lives ?? 0);
}
private void SetHealthBar()
{
HealthBar.Value = Health.Health;
HealthBar.MaxValue = Health.MaxHealth;
}
}