Add FSM components for player and enemy state management, including initialization and module resolution

This commit is contained in:
MaddoScientisto 2026-02-26 23:13:57 +01:00
commit b6cc5a00e8
57 changed files with 526 additions and 506 deletions

View file

@ -1,5 +1,3 @@
using System;
using System.Threading.Tasks;
using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
@ -8,16 +6,27 @@ public partial class Init : PlayerStateBase
{
public override PlayerState StateId => PlayerState.Init;
[Export]
private PlayerAnimationProvider _animationProvider;
[Export] private PlayerStorageModule _storageModule;
private PlayerStorageModule _storageModule;
public override void EnterState()
{
_storageModule.FacingDirection = ((PlayerStateMachine)StateMachine).StartingDirection;
_animationProvider.PlayUnteleportAnimation();
_ = AutoSwitchToStart();
// Resolve modules lazily to avoid method/class name conflicts with Init
_animationProvider ??= StateMachine.GetModule<PlayerAnimationProvider>();
_storageModule ??= StateMachine.GetModule<PlayerStorageModule>();
if (_storageModule != null)
_storageModule.FacingDirection = ((PlayerStateMachine)StateMachine).StartingDirection;
if (_animationProvider != null)
{
_animationProvider.PlayUnteleportAnimation();
// If you need to wait for animation end, subscribe here
}
var timer = GetTree().CreateTimer(0.5f);
timer.Timeout += () => StateMachine.SetState(PlayerState.Active);
}
public override void ExitState()
@ -34,10 +43,4 @@ public partial class Init : PlayerStateBase
{
}
private async Task AutoSwitchToStart()
{
await Task.Delay(500);
StateMachine.SetState(PlayerState.Active);
}
}