Simplify Energy Stuff
This commit is contained in:
47
src/Gameplay/Components/Energy/EnergyStorage.cs
Normal file
47
src/Gameplay/Components/Energy/EnergyStorage.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
{
|
||||
if (field + value > MaxEnergy)
|
||||
{
|
||||
field = MaxEnergy;
|
||||
}
|
||||
else
|
||||
{
|
||||
field += value;
|
||||
}
|
||||
|
||||
field = value;
|
||||
UpdateLabel();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
UpdateLabel();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
// EnergyManager.Instance.RemoveEnergyStorage(this);
|
||||
}
|
||||
|
||||
private void UpdateLabel()
|
||||
{
|
||||
EnergyLabel.Text = $"{Energy:0}/{MaxEnergy}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user