This commit is contained in:
Maddo 2025-02-26 11:04:16 +01:00
commit 054db28c77
5 changed files with 57 additions and 36 deletions

View file

@ -0,0 +1,15 @@
using Godot;
namespace Cirno.Scripts.Components.FSM;
public abstract partial class EnemyFSMState : State
{
[Export]
public EnemyState State { get; private set; }
public override int StateId => (int)State;
protected void ChangeState(EnemyState newState)
{
_stateMachine.SetState((int)newState);
}
}

View file

@ -1,36 +0,0 @@
using Godot;
namespace Cirno.Scripts.Components.FSM;
public partial class EnemyIdle : State
{
//[Export]
//public EnemyState State { get; private set; }
public override int StateId => (int)EnemyState.Idle;
public override void EnterState()
{
}
public override void ExitState()
{
}
public override void ProcessState(double delta)
{
}
public override void PhysicsProcessState(double delta)
{
// Scan for player
// Wait for alarms
}
protected void ChangeState(EnemyState newState)
{
_stateMachine.SetState((int)newState);
}
}

View file

@ -0,0 +1,11 @@
using System;
using Godot;
namespace Cirno.Scripts.Components.FSM;
public abstract partial class FSMStateModule : Node2D
{
public abstract void Init(Actor actor);
public abstract void Update(double delta);
public abstract void PhysicsUpdate(double delta);
}

View file

@ -0,0 +1,22 @@
using Godot;
namespace Cirno.Scripts.Components.FSM;
public abstract partial class PlayerFSMState : State
{
[Export]
public PlayerState State { get; private set; }
public override int StateId => (int)State;
protected void ChangeState(PlayerState newState)
{
_stateMachine.SetState((int)newState);
}
}
public enum PlayerState
{
Idle,
Walking,
Cutscene
}

View file

@ -1,9 +1,13 @@
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Components.FSM;
public abstract partial class State : Node2D
{
[Export]
public Array<FSMStateModule> Modules { get; private set; } = new();
public virtual int StateId { get; }
protected ActorStateMachine _stateMachine;
@ -11,6 +15,11 @@ public abstract partial class State : Node2D
public virtual void Init(ActorStateMachine stateMachine)
{
_stateMachine = stateMachine;
foreach (var module in Modules)
{
//module.Init()
}
}
public abstract void EnterState();