You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
951 B
43 lines
951 B
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Util;
|
|
|
|
public partial class Counter : Node2D
|
|
{
|
|
[Export] private int _startFrom = 0;
|
|
[Export] private int _goal = 0;
|
|
|
|
private int _counter;
|
|
|
|
[Signal] public delegate void CounterChangedEventHandler(int amount);
|
|
[Signal] public delegate void GoalReachedEventHandler();
|
|
|
|
public override void _Ready()
|
|
{
|
|
_counter = _startFrom;
|
|
}
|
|
|
|
public void Increment()
|
|
{
|
|
_counter++;
|
|
EmitSignal(SignalName.CounterChanged, _counter);
|
|
|
|
GD.Print(_counter);
|
|
if (_counter == _goal)
|
|
{
|
|
GD.Print("Emitting goal reached signal");
|
|
EmitSignal(SignalName.GoalReached);
|
|
}
|
|
}
|
|
|
|
public void Decrement()
|
|
{
|
|
_counter--;
|
|
EmitSignal(SignalName.CounterChanged, _counter);
|
|
|
|
if (_counter == _goal)
|
|
{
|
|
EmitSignal(SignalName.GoalReached);
|
|
}
|
|
}
|
|
} |