FIX: going to loginScene or customizeScene and then clicking next bring you back directly to the gameScene

This commit is contained in:
kharhamel 2020-12-15 18:00:04 +01:00
parent 5890e72dd5
commit de9d6756b4
5 changed files with 28 additions and 14 deletions

View File

@ -21,7 +21,7 @@ export class GameManager {
private playerName: string|null; private playerName: string|null;
private characterLayers: string[]|null; private characterLayers: string[]|null;
private startRoom!:Room; private startRoom!:Room;
currentSceneName: string|null = null; currentGameSceneName: string|null = null;
constructor() { constructor() {
this.playerName = localUserStore.getName(); this.playerName = localUserStore.getName();
@ -72,8 +72,8 @@ export class GameManager {
} }
public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void { public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void {
console.log('starting '+ (this.currentSceneName || this.startRoom.id)) console.log('starting '+ (this.currentGameSceneName || this.startRoom.id))
scenePlugin.start(this.currentSceneName || 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 //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); 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. * This will close the socket connections and stop the gameScene, but won't remove it.
*/ */
leaveGame(scene: Phaser.Scene, targetSceneName: string): void { leaveGame(scene: Phaser.Scene, targetSceneName: string): void {
if (this.currentSceneName === null) throw 'No current scene id set!'; if (this.currentGameSceneName === null) throw 'No current scene id set!';
const gameScene: GameScene = scene.scene.get(this.currentSceneName) as GameScene; const gameScene: GameScene = scene.scene.get(this.currentGameSceneName) as GameScene;
gameScene.cleanupClosingScene(); gameScene.cleanupClosingScene();
scene.scene.stop(this.currentSceneName); scene.scene.stop(this.currentGameSceneName);
scene.scene.stop(MenuSceneName); scene.scene.stop(MenuSceneName);
scene.scene.run(targetSceneName); 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 { public getCurrentGameScene(scene: Phaser.Scene): GameScene {
if (this.currentSceneName === null) throw 'No current scene id set!'; if (this.currentGameSceneName === null) throw 'No current scene id set!';
return scene.scene.get(this.currentSceneName) as GameScene return scene.scene.get(this.currentGameSceneName) as GameScene
} }
} }

View File

@ -311,7 +311,7 @@ export class GameScene extends ResizableScene implements CenterListener {
//hook create scene //hook create scene
create(): void { create(): void {
gameManager.currentSceneName = this.scene.key; gameManager.currentGameSceneName = this.scene.key;
urlManager.pushRoomIdToUrl(this.room); urlManager.pushRoomIdToUrl(this.room);
this.startLayerName = urlManager.getStartLayerNameFromUrl(); this.startLayerName = urlManager.getStartLayerNameFromUrl();
@ -437,7 +437,7 @@ export class GameScene extends ResizableScene implements CenterListener {
this.presentationModeSprite.on('pointerup', this.switchLayoutMode.bind(this)); this.presentationModeSprite.on('pointerup', this.switchLayoutMode.bind(this));
this.chatModeSprite = new ChatModeIcon(this, 70, this.game.renderer.height - 2); this.chatModeSprite = new ChatModeIcon(this, 70, this.game.renderer.height - 2);
this.chatModeSprite.on('pointerup', this.switchLayoutMode.bind(this)); 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 // FIXME: change this to use the UserInputManager class for input
this.input.keyboard.on('keyup-M', () => { this.input.keyboard.on('keyup-M', () => {

View File

@ -122,8 +122,8 @@ export class CustomizeScene extends ResizableScene {
gameManager.setCharacterLayers(layers); gameManager.setCharacterLayers(layers);
this.scene.sleep(CustomizeSceneName) this.scene.sleep(CustomizeSceneName);
this.scene.run(EnableCameraSceneName); gameManager.tryResumingGame(this, EnableCameraSceneName);
}); });
this.input.keyboard.on('keydown-RIGHT', () => this.moveCursorHorizontally(1)); this.input.keyboard.on('keydown-RIGHT', () => this.moveCursorHorizontally(1));

View File

@ -6,6 +6,7 @@ import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Ch
import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {cypressAsserter} from "../../Cypress/CypressAsserter";
import {SelectCharacterSceneName} from "./SelectCharacterScene"; import {SelectCharacterSceneName} from "./SelectCharacterScene";
import {ResizableScene} from "./ResizableScene"; import {ResizableScene} from "./ResizableScene";
import {EnableCameraSceneName} from "./EnableCameraScene";
//todo: put this constants in a dedicated file //todo: put this constants in a dedicated file
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
@ -84,7 +85,7 @@ export class LoginScene extends ResizableScene {
gameManager.setPlayerName(name); gameManager.setPlayerName(name);
this.scene.sleep(LoginSceneName) this.scene.sleep(LoginSceneName)
this.scene.run(SelectCharacterSceneName); gameManager.tryResumingGame(this, SelectCharacterSceneName);
} }
public onResize(ev: UIEvent): void { public onResize(ev: UIEvent): void {

View File

@ -119,7 +119,7 @@ export class SelectCharacterScene extends ResizableScene {
this.scene.sleep(SelectCharacterSceneName); this.scene.sleep(SelectCharacterSceneName);
if (this.selectedPlayer !== null) { if (this.selectedPlayer !== null) {
gameManager.setCharacterLayers([this.selectedPlayer.texture.key]); gameManager.setCharacterLayers([this.selectedPlayer.texture.key]);
this.scene.run(EnableCameraSceneName); gameManager.tryResumingGame(this, EnableCameraSceneName);
} else { } else {
this.scene.run(CustomizeSceneName); this.scene.run(CustomizeSceneName);
} }