You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
absg/Source/SpaceBattler/Private/StateMachineSubsystem.cpp

90 lines
2.4 KiB

// Fill out your copyright notice in the Description page of Project Settings.
#include "StateMachineSubsystem.h"
void UStateMachineSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
CurrentState = EGameState::MainMenu;
UE_LOG(LogTemp, Display, TEXT("Starting game state machine in MAINMENU state"))
}
bool UStateMachineSubsystem::ChangeState(const EGameState NewState)
{
// Exit from old state
switch (CurrentState)
{
case EGameState::MainMenu:
switch(NewState)
{
case EGameState::Battle:
UE_LOG(LogTemp, Display, TEXT("Entering BATTLE state from MAINMENU"))
break;
default:
UE_LOG(LogTemp, Error, TEXT("NewState is invalid from MAINMENU state: %hhd"), NewState)
return false;
}
break;
case EGameState::Battle:
switch(NewState)
{
case EGameState::Battle:
UE_LOG(LogTemp, Warning, TEXT("Entering BATTLE state from BATTLE. Should only be possible when debugging"))
break;
case EGameState::BattleMenu:
UE_LOG(LogTemp, Display, TEXT("Entering BATTLEMENU state from BATTLE"))
break;
case EGameState::GameOver:
UE_LOG(LogTemp, Display, TEXT("Entering GAMEOVER state from BATTLE"))
break;
case EGameState::Victory:
UE_LOG(LogTemp, Display, TEXT("Entering VICTORY state from BATTLE"))
break;
default:
UE_LOG(LogTemp, Error, TEXT("NewState is invalid from BATTLE state: %hhd"), NewState)
return false;
}
break;
case EGameState::BattleMenu:
switch(NewState)
{
case EGameState::Battle:
UE_LOG(LogTemp, Display, TEXT("Entering BATTLE state from BATTLEMENU"))
break;
default:
UE_LOG(LogTemp, Error, TEXT("NewState is invalid from BATTLEMENU state: %hhd"), NewState)
return false;
}
break;
case EGameState::GameOver:
switch(NewState)
{
case EGameState::MainMenu:
UE_LOG(LogTemp, Display, TEXT("Entering MAINMENU state from GAMEOVER"))
break;
default:
UE_LOG(LogTemp, Error, TEXT("NewState is invalid from GAMEOVER: %hhd"), NewState)
return false;
}
break;
case EGameState::Victory:
switch(NewState)
{
case EGameState::MainMenu:
UE_LOG(LogTemp, Display, TEXT("Entering MAINMENU state from VICTORY"))
break;
default:
UE_LOG(LogTemp, Error, TEXT("NewState is invalid from VICTORY: %hhd"), NewState)
return false;
}
default:
UE_LOG(LogTemp, Error, TEXT("Leaving unknown state, this is a problem"))
return false;
}
CurrentState = NewState;
StateChangedDelegate.Broadcast(NewState);
return true;
}