From 0296edb0809c58eb50f257fe79ce9098d8d3700a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Fri, 29 May 2020 12:42:21 +0200 Subject: [PATCH] adding var current- and previousState - set in enterState, adding func changeState --- GoldWars/GoldWars/StateManager.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/GoldWars/GoldWars/StateManager.swift b/GoldWars/GoldWars/StateManager.swift index 67d201a..eb4c66c 100644 --- a/GoldWars/GoldWars/StateManager.swift +++ b/GoldWars/GoldWars/StateManager.swift @@ -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() + } }