From 0c796dff90bc08ceabdce5611d58a4a4b6e4473d Mon Sep 17 00:00:00 2001 From: GRL Date: Thu, 19 Aug 2021 17:22:16 +0200 Subject: [PATCH] Player return a the same position when after editing his profile --- front/src/Phaser/Game/GameManager.ts | 10 ++++++++++ front/src/Phaser/Game/GameScene.ts | 24 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 12558d5d..265f4bd9 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -17,6 +17,7 @@ export class GameManager { private playerName: string | null; private characterLayers: string[] | null; private companion: string | null; + private positionBeforeSleep: { scene: string; x: number; y: number } | undefined; private startRoom!: Room; private scenePlugin!: Phaser.Scenes.ScenePlugin; currentGameSceneName: string | null = null; @@ -70,6 +71,10 @@ export class GameManager { return this.companion; } + getPositionBeforeSleep(): { scene: string; x: number; y: number } | undefined { + return this.positionBeforeSleep; + } + public loadMap(room: Room) { const roomID = room.key; @@ -108,6 +113,11 @@ export class GameManager { if (this.currentGameSceneName === null) throw "No current scene id set!"; const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene; gameScene.cleanupClosingScene(); + this.positionBeforeSleep = { + scene: gameScene.roomUrl, + x: gameScene.CurrentPlayer.x, + y: gameScene.CurrentPlayer.y, + }; this.scenePlugin.stop(this.currentGameSceneName); this.scenePlugin.sleep(MenuSceneName); if (!this.scenePlugin.get(targetSceneName)) { diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 9a5d8f27..863fc4cd 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -92,9 +92,7 @@ import { PropertyUtils } from "../Map/PropertyUtils"; import Tileset = Phaser.Tilemaps.Tileset; import { userIsAdminStore } from "../../Stores/GameStore"; import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore"; -import { get } from "svelte/store"; import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager"; -import { helpCameraSettingsVisibleStore } from "../../Stores/HelpCameraSettingsStore"; export interface GameSceneInitInterface { initPosition: PointInterface | null; @@ -540,7 +538,15 @@ export class GameScene extends DirtyScene { } //notify game manager can to create currentUser in map - this.createCurrentPlayer(); + const positionBeforeSleep = gameManager.getPositionBeforeSleep(); + if (positionBeforeSleep && positionBeforeSleep.scene === this.room.key) { + this.createCurrentPlayer(positionBeforeSleep.x, positionBeforeSleep.y); + } else { + this.createCurrentPlayer( + this.startPositionCalculator.startPosition.x, + this.startPositionCalculator.startPosition.y + ); + } this.removeAllRemotePlayers(); //cleanup the list of remote players in case the scene was rebooted this.initCamera(); @@ -760,8 +766,10 @@ export class GameScene extends DirtyScene { this.connectionAnswerPromiseResolve(onConnect.room); // Analyze tags to find if we are admin. If yes, show console. - this.scene.wake(); - this.scene.stop(ReconnectingSceneName); + if (this.scene.isSleeping()) { + this.scene.wake(); + this.scene.stop(ReconnectingSceneName); + } //init user position and play trigger to check layers properties this.gameMap.setPosition(this.CurrentPlayer.x, this.CurrentPlayer.y); @@ -1483,14 +1491,14 @@ ${escapedMessage} } } - createCurrentPlayer() { + createCurrentPlayer(x: number, y: number) { //TODO create animation moving between exit and start const texturesPromise = lazyLoadPlayerCharacterTextures(this.load, this.characterLayers); try { this.CurrentPlayer = new Player( this, - this.startPositionCalculator.startPosition.x, - this.startPositionCalculator.startPosition.y, + x, + y, this.playerName, texturesPromise, PlayerAnimationDirections.Down,