adding var current- and previousState - set in enterState, adding func changeState
This commit is contained in:
parent
6be5325d86
commit
0296edb080
@ -15,25 +15,41 @@ class StateManager{
|
||||
|
||||
var stateMachine: GKStateMachine?
|
||||
var wantedState: StateTypes?
|
||||
var currentState: GKState?
|
||||
var previousState: GKState?
|
||||
|
||||
var menuSc: MenuScene?
|
||||
var gameVC: GameViewController?
|
||||
|
||||
let LOG = OSLog.init(subsystem: "StateManager", category: "StateManager")
|
||||
|
||||
func enterState(){
|
||||
previousState = stateMachine?.currentState
|
||||
|
||||
switch wantedState {
|
||||
case .menuSt:
|
||||
if stateMachine?.enter(MenuState.self) == false {
|
||||
os_log("Failed entering Menu State", log: LOG, type: .info)
|
||||
}else{
|
||||
currentState = stateMachine?.currentState
|
||||
}
|
||||
case .gameSt:
|
||||
if stateMachine?.enter(GameState.self) == false {
|
||||
os_log("Failed entering Game State", log: LOG, type: .info)
|
||||
}else{
|
||||
currentState = stateMachine?.currentState
|
||||
}
|
||||
case .syncingSt:
|
||||
if stateMachine?.enter(SyncingState.self) == false {
|
||||
os_log("Failed entering Syncing State", log: LOG, type: .info)
|
||||
}else{
|
||||
currentState = stateMachine?.currentState
|
||||
}
|
||||
case .endGameSt:
|
||||
if stateMachine?.enter(EndGameState.self) == false {
|
||||
os_log("Failed entering EndGame State", log: LOG, type: .info)
|
||||
}else{
|
||||
currentState = stateMachine?.currentState
|
||||
}
|
||||
default:
|
||||
os_log("Allowed State was found nil, can't enter any State", log: LOG, type: .info)
|
||||
@ -48,4 +64,11 @@ class StateManager{
|
||||
|
||||
stateMachine = GKStateMachine(states: [menuSt, syncingSt, playingSt, endGameSt])
|
||||
}
|
||||
|
||||
func changeState(wantedState: StateTypes, menuSc: MenuScene?, gameVC: GameViewController?){
|
||||
self.wantedState = wantedState
|
||||
self.menuSc = menuSc
|
||||
self.gameVC = gameVC
|
||||
enterState()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user