initial add

This commit is contained in:
2026-04-10 17:53:31 -05:00
commit ebd36e4ef3
196 changed files with 51603 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
using Godot;
using System.Collections.Generic;
public partial class StateMachine : State {
[Export]
public State InitialState { get; set; }
private State currentState;
private readonly Dictionary<string, State> stateList = [];
public override void _Ready() {
foreach (var child in GetChildren()) {
if (child is State state)
{
stateList.Add(child.Name.ToString().ToLower(), state);
state.Transitioned += OnChildTransition;
}
}
if (InitialState != null)
{
InitialState.Enter();
currentState = InitialState;
}
}
public void Process(float delta)
{
currentState?.Update(delta);
}
public override void PhysicsUpdate(double delta)
{
currentState?.PhysicsUpdate(delta);
}
public void OnChildTransition(Node sender, string newStateName)
{
if (sender != currentState)
{
return;
}
var newState = stateList[newStateName.ToLower()];
if (newState == null)
{
return;
}
currentState?.Exit();
newState.Enter();
currentState = newState;
}
}