39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using Code.App.AppStates;
|
|
using Code.StateMachine;
|
|
|
|
namespace Code.App.StateMachine
|
|
{
|
|
public class AppStateMachine : AbstractStateMachine<AppState, AppStateMachineContext>
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
States.Add(AppState.Bootstrap, new BootstrapState(StateMachineContext));
|
|
States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext));
|
|
States.Add(AppState.Gameplay, new GameplayState(StateMachineContext));
|
|
States.Add(AppState.GameOver, new GameOverState(StateMachineContext));
|
|
//TODO: Для теста
|
|
States.Add(AppState.MovementDev, new MovementDevState(StateMachineContext));
|
|
|
|
AllowedStates |= AppState.MainMenu;
|
|
AllowedStates |= AppState.Gameplay;
|
|
AllowedStates |= AppState.MovementDev;
|
|
|
|
CurrentBaseState = States[AppState.Bootstrap];
|
|
}
|
|
|
|
protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState);
|
|
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
|
}
|
|
|
|
public static class AppStateMachineExtensions
|
|
{
|
|
public static AbstractStateMachine<AppState, AppStateMachineContext> AllowStateTransition(
|
|
this AbstractStateMachine<AppState, AppStateMachineContext> appStateMachine, AppState state)
|
|
{
|
|
if (appStateMachine == null) return null;
|
|
|
|
appStateMachine.AllowedStates |= state;
|
|
return appStateMachine;
|
|
}
|
|
}
|
|
} |