From 8537dee23174ac58a6a4a4e612f4aebd9b6ca609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Fri, 29 May 2020 13:04:40 +0200 Subject: [PATCH] game scene and menu scene are now initialized in states, still need to test for 2 player --- GoldWars/GoldWars/GameState.swift | 3 ++- GoldWars/GoldWars/GameViewController.swift | 13 +--------- GoldWars/GoldWars/MenuState.swift | 28 ++++++++++++++++++++++ GoldWars/GoldWars/Scenes/MenuScene.swift | 9 ++++--- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/GoldWars/GoldWars/GameState.swift b/GoldWars/GoldWars/GameState.swift index d4bc4a8..7c79be8 100644 --- a/GoldWars/GoldWars/GameState.swift +++ b/GoldWars/GoldWars/GameState.swift @@ -19,8 +19,9 @@ class GameState: GKState { override func didEnter(from previousState: GKState?) { os_log("Entered Game State", log: LOG, type: .info) + StateManager.stateManager.menuSc!.loadScene(scene: GameScene(size: StateManager.stateManager.menuSc!.size)) } - + override func update(deltaTime seconds: TimeInterval) { } diff --git a/GoldWars/GoldWars/GameViewController.swift b/GoldWars/GoldWars/GameViewController.swift index 0c249a9..c36c21f 100644 --- a/GoldWars/GoldWars/GameViewController.swift +++ b/GoldWars/GoldWars/GameViewController.swift @@ -15,19 +15,8 @@ class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - StateManager.stateManager.wantedState = StateTypes.menuSt StateManager.stateManager.createStates() - StateManager.stateManager.enterState() - - if let view = self.view as! SKView? { - let scene = MenuScene(size: self.view.bounds.size) - EntityManager.menuEMInstance.setScene(scene: scene) - scene.scaleMode = .aspectFill - view.presentScene(scene) - //TODO: create dev profile or remove on delivery - view.showsFPS = true - view.showsNodeCount = true - } + StateManager.stateManager.changeState(wantedState: .menuSt, menuSc: nil, gameVC: self) GameCenterManager.sharedInstance.viewController = self } diff --git a/GoldWars/GoldWars/MenuState.swift b/GoldWars/GoldWars/MenuState.swift index e8e1879..7dba33b 100644 --- a/GoldWars/GoldWars/MenuState.swift +++ b/GoldWars/GoldWars/MenuState.swift @@ -12,18 +12,46 @@ import os class MenuState: GKState { let LOG = OSLog.init(subsystem: "MenuState", category: "MenuState") + var menuEM = EntityManager.menuEMInstance override func isValidNextState(_ stateClass: AnyClass) -> Bool { + if CommandLine.arguments.contains("--no-matchmaking") { + return stateClass is GameState.Type + } return stateClass is SyncingState.Type } override func update(deltaTime seconds: TimeInterval) { + /* if menuEM.entities.count != 0 { + menuEM.getBackground()!.update(deltaTime: seconds) + menuEM.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated + } + + if GameCenterManager.sharedInstance.initIsFinish { + StateManager.stateManager.menuSc!.loadScene(scene: GameCenterManager.sharedInstance.gameScene!) + }*/ } override func didEnter(from previousState: GKState?) { os_log("Entered Menu State", log: LOG, type: .info) + + if (previousState == nil){ + presentFirstViewMenu() + } } override func willExit(to nextState: GKState) { } + + func presentFirstViewMenu(){ + if let view = StateManager.stateManager.gameVC!.view as! SKView? { + let scene = MenuScene(size: StateManager.stateManager.gameVC!.view.bounds.size) + EntityManager.menuEMInstance.setScene(scene: scene) + scene.scaleMode = .aspectFill + view.presentScene(scene) + //TODO: create dev profile or remove on delivery + view.showsFPS = true + view.showsNodeCount = true + } + } } diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index 82469a3..6818207 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -8,6 +8,7 @@ import SpriteKit import SceneKit + class MenuScene: SKScene { var entityManager = EntityManager.menuEMInstance @@ -23,12 +24,13 @@ class MenuScene: SKScene { position: CGPoint(x: midX, y: midY), onButtonPress: { if CommandLine.arguments.contains("--no-matchmaking") { - self.loadScene(scene: GameScene(size: self.size)) + StateManager.stateManager.changeState(wantedState: .gameSt, menuSc: self, gameVC: nil) + //self.loadScene(scene: GameScene(size: self.size)) SoundManager.sharedInstance.stopMenuMusic() } else { - if GameCenterManager.isAuthenticated { - GameCenterManager.sharedInstance.presentMatchmaker() + StateManager.stateManager.changeState(wantedState: .syncingSt, menuSc: self, gameVC: nil) + GameCenterManager.sharedInstance.presentMatchmaker() }else { GameCenterManager.sharedInstance.authUser() } @@ -78,4 +80,5 @@ class MenuScene: SKScene { } } + }