2025-02-20 14:09:42 +01:00
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.Components.Actors;
|
|
|
|
|
|
|
2025-06-21 18:54:14 +02:00
|
|
|
|
public partial class ActorResourceProvider : Node
|
2025-02-20 14:09:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
[Export]
|
|
|
|
|
|
public string ResourceName { get; private set; }
|
|
|
|
|
|
|
2025-03-18 11:57:15 +01:00
|
|
|
|
public float MaxResource
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _maxResource;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_maxResource == value) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (value > _currentResource)
|
|
|
|
|
|
{
|
|
|
|
|
|
EmitSignal(SignalName.ResourceIncreased, _currentResource, _currentResource, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (value < _currentResource)
|
|
|
|
|
|
{
|
|
|
|
|
|
EmitSignal(SignalName.ResourceDecreased, _currentResource, _currentResource, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_maxResource = value;
|
|
|
|
|
|
|
|
|
|
|
|
EmitSignal(SignalName.ResourceChanged, _currentResource, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-20 14:09:42 +01:00
|
|
|
|
|
|
|
|
|
|
private float _currentResource = 0f;
|
|
|
|
|
|
|
2025-03-18 11:57:15 +01:00
|
|
|
|
[Export]
|
|
|
|
|
|
private float _maxResource = 10f;
|
|
|
|
|
|
|
2025-02-20 14:09:42 +01:00
|
|
|
|
[Signal]
|
|
|
|
|
|
public delegate void ResourceChangedEventHandler(float newValue, float maxValue);
|
|
|
|
|
|
|
2025-03-03 10:58:20 +01:00
|
|
|
|
[Signal]
|
|
|
|
|
|
public delegate void ResourceIncreasedEventHandler(float oldValue, float newValue, float maxValue);
|
|
|
|
|
|
|
|
|
|
|
|
[Signal]
|
|
|
|
|
|
public delegate void ResourceDecreasedEventHandler(float oldValue, float newValue, float maxValue);
|
|
|
|
|
|
|
2025-02-20 14:09:42 +01:00
|
|
|
|
[Signal]
|
|
|
|
|
|
public delegate void ResourceMaxedEventHandler(float maxValue);
|
|
|
|
|
|
|
|
|
|
|
|
[Signal]
|
|
|
|
|
|
public delegate void ResourceDepletedEventHandler();
|
|
|
|
|
|
|
|
|
|
|
|
public float CurrentResource
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _currentResource;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2025-03-03 10:58:20 +01:00
|
|
|
|
if (_currentResource == value) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (value > _currentResource)
|
|
|
|
|
|
{
|
|
|
|
|
|
EmitSignal(SignalName.ResourceIncreased, _currentResource, value, MaxResource);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (value < _currentResource)
|
2025-02-20 14:09:42 +01:00
|
|
|
|
{
|
2025-03-03 10:58:20 +01:00
|
|
|
|
EmitSignal(SignalName.ResourceDecreased, _currentResource, value, MaxResource);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_currentResource = value;
|
2025-02-20 14:09:42 +01:00
|
|
|
|
|
2025-03-03 10:58:20 +01:00
|
|
|
|
if (_currentResource >= MaxResource) {
|
|
|
|
|
|
_currentResource = MaxResource;
|
|
|
|
|
|
EmitSignal(SignalName.ResourceMaxed, MaxResource);
|
2025-02-20 14:09:42 +01:00
|
|
|
|
}
|
2025-03-03 10:58:20 +01:00
|
|
|
|
else if (_currentResource <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
EmitSignal(SignalName.ResourceDepleted);
|
2025-03-22 18:15:27 +01:00
|
|
|
|
_currentResource = 0;
|
2025-03-03 10:58:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EmitSignal(SignalName.ResourceChanged, _currentResource, MaxResource);
|
2025-02-20 14:09:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void FillResource()
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentResource = MaxResource;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|