From ea30a02762f57e2b82f9f024009651a3b78f5e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 11 Jun 2020 14:12:03 +0200 Subject: [PATCH] Fixing reconnect issues --- front/src/Phaser/Game/GameManager.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index c19858fa..ae31ed3c 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -186,9 +186,18 @@ export class GameManager { } private timeoutCallback: NodeJS.Timeout|null = null; - reconnectToGameScene(lastPositionShared: PointInterface) { - if (this.reconnectScene === null && this.currentGameScene && this.timeoutCallback === null) { + reconnectToGameScene(lastPositionShared: PointInterface): void { + if (this.timeoutCallback !== null) { + return; + } + if (this.reconnectScene === null) { console.log('Reconnect called without switchToDisconnectedScene called first'); + + if (!this.currentGameScene) { + console.error('Reconnect called but we are not on a GameScene'); + return; + } + // In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep) this.switchToDisconnectedScene(); // Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason. @@ -201,7 +210,8 @@ export class GameManager { } console.log('Reconnecting to game scene'); 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 }); + this.reconnectScene = null; } private getCurrentGameScene(): GameScene {