Files
slimepire/src/Gameplay/Components/Energy/EnergyStorage.cs
2026-06-24 15:49:08 +02:00

50 lines
847 B
C#

using Godot;
namespace Slimepire.Gameplay.Components;
[GlobalClass]
public partial class EnergyStorage : Node
{
[Export]
public Label EnergyLabel = null!;
[Export]
public float MaxEnergy = 100;
public float Energy
{
get;
set
{
field = Mathf.Clamp(field + value, 0, MaxEnergy);
UpdateLabel();
}
}
public bool TryConsume(float amount)
{
if (Energy >= amount)
{
Energy = -amount;
return true;
}
return false;
}
public override void _Ready()
{
UpdateLabel();
}
public override void _ExitTree()
{
// EnergyManager.Instance.RemoveEnergyStorage(this);
}
private void UpdateLabel()
{
EnergyLabel.Text = $"{Energy:0}/{MaxEnergy}";
}
}