50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
|
|
// <auto-generated/>
|
|
#pragma warning disable CS0105
|
|
using Code.Infrastructure.StateMachine;
|
|
|
|
using Code.Infrastructure.App.States;
|
|
|
|
using Code.Example.Platformer;
|
|
|
|
using Code.Infrastructure.App.States;
|
|
|
|
#pragma warning restore CS0105
|
|
namespace Code.Infrastructure.App
|
|
{
|
|
|
|
public partial class AppStateMachine : AbstractStateMachine<Code.Infrastructure.App.AppStates,Code.Infrastructure.App.AppStateMachineContext>
|
|
{
|
|
|
|
public AppStateMachine(Code.Infrastructure.App.AppStateMachineContext context, EventBus.EventBus eventBus) : base(context)
|
|
{
|
|
|
|
var stateBootstrapState = new BootstrapState(StateMachineContext,eventBus);
|
|
States.Add(stateBootstrapState.myState, stateBootstrapState);
|
|
|
|
var statePlatformerState = new PlatformerState(StateMachineContext,eventBus);
|
|
States.Add(statePlatformerState.myState, statePlatformerState);
|
|
|
|
var stateMainMenuState = new MainMenuState(StateMachineContext,eventBus);
|
|
States.Add(stateMainMenuState.myState, stateMainMenuState);
|
|
|
|
}
|
|
|
|
protected override bool CheckTransitionAllowed(Code.Infrastructure.App.AppStates nextState) => AllowedStates.HasFlag(nextState);
|
|
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
|
}
|
|
|
|
public static class AppStateMachineExtensions
|
|
{
|
|
public static AbstractStateMachine<Code.Infrastructure.App.AppStates, Code.Infrastructure.App.AppStateMachineContext> AllowStateTransition(
|
|
this AbstractStateMachine<Code.Infrastructure.App.AppStates, Code.Infrastructure.App.AppStateMachineContext> stateMachine, Code.Infrastructure.App.AppStates state)
|
|
{
|
|
if (stateMachine == null) return null;
|
|
|
|
stateMachine.AllowedStates |= state;
|
|
return stateMachine;
|
|
}
|
|
}
|
|
}
|
|
|