From ce7b4092a608dc5bde2d962680b6f6892a8a7b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 11 Jun 2020 09:37:33 +0200 Subject: [PATCH] Fixing suspend/resume In case we suspend a laptop and resume it, the RECONNECT event is called by socket.io without any error being thrown (so without us being redirected to the Reconnect Scene). This fix makes sure we go to the reconnect scene before going back to the main scene. --- front/src/Phaser/Game/GameManager.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index f9c7c820..82c0812b 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -168,7 +168,7 @@ export class GameManager { private oldMapUrlFile : string; private oldInstance : string; private scenePlugin: ScenePlugin; - private reconnectScene: Scene; + private reconnectScene: Scene|null; switchToDisconnectedScene(): void { if (this.currentGameScene === null) { return; @@ -186,8 +186,12 @@ export class GameManager { } reconnectToGameScene(lastPositionShared: PointInterface) { + if (this.reconnectScene === null && this.currentGameScene) { + // In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep) + this.switchToDisconnectedScene(); + } const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance); - this.reconnectScene.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared }); + this.reconnectScene?.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared }); } private getCurrentGameScene(): GameScene {