From de9d6756b4d325cef6e59d9d1eae5c6d94f1bdf4 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Tue, 15 Dec 2020 18:00:04 +0100 Subject: [PATCH] FIX: going to loginScene or customizeScene and then clicking next bring you back directly to the gameScene --- front/src/Phaser/Game/GameManager.ts | 29 ++++++++++++++----- front/src/Phaser/Game/GameScene.ts | 4 +-- front/src/Phaser/Login/CustomizeScene.ts | 4 +-- front/src/Phaser/Login/LoginScene.ts | 3 +- .../src/Phaser/Login/SelectCharacterScene.ts | 2 +- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 88ed1c52..dc0218c4 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -21,7 +21,7 @@ export class GameManager { private playerName: string|null; private characterLayers: string[]|null; private startRoom!:Room; - currentSceneName: string|null = null; + currentGameSceneName: string|null = null; constructor() { this.playerName = localUserStore.getName(); @@ -72,8 +72,8 @@ export class GameManager { } public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void { - console.log('starting '+ (this.currentSceneName || this.startRoom.id)) - scenePlugin.start(this.currentSceneName || this.startRoom.id); + console.log('starting '+ (this.currentGameSceneName || this.startRoom.id)) + scenePlugin.start(this.currentGameSceneName || this.startRoom.id); //the menu scene launches faster than the gameScene, so we delay it to not have menu buttons on a black screen setTimeout(() => scenePlugin.launch(MenuSceneName), 1000); } @@ -83,17 +83,30 @@ export class GameManager { * This will close the socket connections and stop the gameScene, but won't remove it. */ leaveGame(scene: Phaser.Scene, targetSceneName: string): void { - if (this.currentSceneName === null) throw 'No current scene id set!'; - const gameScene: GameScene = scene.scene.get(this.currentSceneName) as GameScene; + if (this.currentGameSceneName === null) throw 'No current scene id set!'; + const gameScene: GameScene = scene.scene.get(this.currentGameSceneName) as GameScene; gameScene.cleanupClosingScene(); - scene.scene.stop(this.currentSceneName); + scene.scene.stop(this.currentGameSceneName); scene.scene.stop(MenuSceneName); scene.scene.run(targetSceneName); } + + /** + * follow up to leaveGame() + */ + tryResumingGame(scene: Phaser.Scene, fallbackSceneName: string) { + if (this.currentGameSceneName) { + scene.scene.start(this.currentGameSceneName); + //the menu scene launches faster than the gameScene, so we delay it to not have menu buttons on a black screen + setTimeout(() => scene.scene.launch(MenuSceneName), 1000); + } else { + scene.scene.run(fallbackSceneName) + } + } public getCurrentGameScene(scene: Phaser.Scene): GameScene { - if (this.currentSceneName === null) throw 'No current scene id set!'; - return scene.scene.get(this.currentSceneName) as GameScene + if (this.currentGameSceneName === null) throw 'No current scene id set!'; + return scene.scene.get(this.currentGameSceneName) as GameScene } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index cbfa64d9..9f707da7 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -311,7 +311,7 @@ export class GameScene extends ResizableScene implements CenterListener { //hook create scene create(): void { - gameManager.currentSceneName = this.scene.key; + gameManager.currentGameSceneName = this.scene.key; urlManager.pushRoomIdToUrl(this.room); this.startLayerName = urlManager.getStartLayerNameFromUrl(); @@ -437,7 +437,7 @@ export class GameScene extends ResizableScene implements CenterListener { this.presentationModeSprite.on('pointerup', this.switchLayoutMode.bind(this)); this.chatModeSprite = new ChatModeIcon(this, 70, this.game.renderer.height - 2); this.chatModeSprite.on('pointerup', this.switchLayoutMode.bind(this)); - this.openChatIcon = new OpenChatIcon(this, 2, this.game.renderer.height - 36) + this.openChatIcon = new OpenChatIcon(this, 2, this.game.renderer.height - 2) // FIXME: change this to use the UserInputManager class for input this.input.keyboard.on('keyup-M', () => { diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index d9236c06..9a8776a2 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -122,8 +122,8 @@ export class CustomizeScene extends ResizableScene { gameManager.setCharacterLayers(layers); - this.scene.sleep(CustomizeSceneName) - this.scene.run(EnableCameraSceneName); + this.scene.sleep(CustomizeSceneName); + gameManager.tryResumingGame(this, EnableCameraSceneName); }); this.input.keyboard.on('keydown-RIGHT', () => this.moveCursorHorizontally(1)); diff --git a/front/src/Phaser/Login/LoginScene.ts b/front/src/Phaser/Login/LoginScene.ts index e828f8cb..64baac81 100644 --- a/front/src/Phaser/Login/LoginScene.ts +++ b/front/src/Phaser/Login/LoginScene.ts @@ -6,6 +6,7 @@ import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Ch import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {SelectCharacterSceneName} from "./SelectCharacterScene"; import {ResizableScene} from "./ResizableScene"; +import {EnableCameraSceneName} from "./EnableCameraScene"; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; @@ -84,7 +85,7 @@ export class LoginScene extends ResizableScene { gameManager.setPlayerName(name); this.scene.sleep(LoginSceneName) - this.scene.run(SelectCharacterSceneName); + gameManager.tryResumingGame(this, SelectCharacterSceneName); } public onResize(ev: UIEvent): void { diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index 5b4dc6cf..0c0a3536 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -119,7 +119,7 @@ export class SelectCharacterScene extends ResizableScene { this.scene.sleep(SelectCharacterSceneName); if (this.selectedPlayer !== null) { gameManager.setCharacterLayers([this.selectedPlayer.texture.key]); - this.scene.run(EnableCameraSceneName); + gameManager.tryResumingGame(this, EnableCameraSceneName); } else { this.scene.run(CustomizeSceneName); }