Merge pull request #492 from thecodingmachine/fixSceneNavigation

FIX: fix scene navigation
This commit is contained in:
Kharhamel 2020-12-15 18:14:03 +01:00 committed by GitHub
commit 16f7c3d204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 14 deletions

View File

@ -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
}
}

View File

@ -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', () => {

View File

@ -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));

View File

@ -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 {

View File

@ -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);
}