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.
77 lines
1.7 KiB
77 lines
1.7 KiB
using Godot;
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
public partial class FightStateManager : Node
|
|
{
|
|
[Signal]
|
|
public delegate void ExitingTransitionEventHandler(FightState exitingState);
|
|
|
|
[Signal]
|
|
public delegate void EnteringTransitionEventHandler(FightState enteringState);
|
|
|
|
public enum FightState
|
|
{
|
|
None,
|
|
FightStartAnim,
|
|
Input,
|
|
InputTargetSelect,
|
|
FriendAttackAnim,
|
|
Enemy,
|
|
EnemyAttackAnim,
|
|
PlayerWinAnim,
|
|
EnemyWinAnim,
|
|
ChangeSideToEnemy,
|
|
ChangeSideToFriendly,
|
|
Heal,
|
|
}
|
|
|
|
private FightState _fightStateBacking = FightState.None;
|
|
|
|
public FightState CurrentFightState
|
|
{
|
|
set => Transition(_fightStateBacking, value);
|
|
get => _fightStateBacking;
|
|
}
|
|
|
|
private void Transition(FightState from, FightState to)
|
|
{
|
|
if(from == to)
|
|
return;
|
|
|
|
GD.Print($"Transitioning from {from} to {to}");
|
|
ExitTransition(from);
|
|
_fightStateBacking = to;
|
|
EnterTransition(to);
|
|
}
|
|
|
|
private void ExitTransition(FightState from)
|
|
{
|
|
EmitSignalExitingTransition(from);
|
|
}
|
|
|
|
private void EnterTransition(FightState to)
|
|
{
|
|
EmitSignalEnteringTransition(to);
|
|
switch (to)
|
|
{
|
|
case FightState.FightStartAnim:
|
|
EnterFightStartAnim();
|
|
break;
|
|
}
|
|
}
|
|
private void EnterFightStartAnim()
|
|
{
|
|
GetTree().CreateTimer(1).Timeout += () => CurrentFightState = FightState.Input;
|
|
}
|
|
|
|
public void ToStartAnim()
|
|
{
|
|
CurrentFightState = FightState.FightStartAnim;
|
|
}
|
|
|
|
public bool IsRunning()
|
|
{
|
|
return CurrentFightState != FightState.None;
|
|
}
|
|
}
|