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 1/4] 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 { From 77167c28a6adbcb773a3638a0159663a40088222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 11 Jun 2020 10:00:30 +0200 Subject: [PATCH 2/4] Making sure that even is a user did not move, the reconnection can happen without issues and resume at the old position --- front/src/Connection.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/front/src/Connection.ts b/front/src/Connection.ts index 3c1bc2d4..15e58707 100644 --- a/front/src/Connection.ts +++ b/front/src/Connection.ts @@ -232,6 +232,8 @@ export class Connection implements ConnectionInterface { } joinARoom(roomId: string, startX: number, startY: number, direction: string, moving: boolean): void { + let point = new Point(startX, startY, direction, moving); + this.lastPositionShared = point; this.getSocket().emit(EventMessage.JOIN_ROOM, { roomId, position: {x: startX, y: startY, direction, moving }}, (userPositions: MessageUserPositionInterface[]) => { this.GameManager.initUsersPosition(userPositions); }); From 43c7c9ad079ce70dcf91189c37246206d97fc142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 11 Jun 2020 10:29:11 +0200 Subject: [PATCH 3/4] Fixing null initialization --- front/src/Phaser/Game/GameManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 82c0812b..07bb204b 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -35,7 +35,7 @@ export interface MapObject { export class GameManager { //status: number; private ConnectionInstance: Connection; - private currentGameScene: GameScene|null; + private currentGameScene: GameScene|null = null; private playerName: string; SimplePeer : SimplePeer; private characterUserSelected: string; @@ -168,7 +168,7 @@ export class GameManager { private oldMapUrlFile : string; private oldInstance : string; private scenePlugin: ScenePlugin; - private reconnectScene: Scene|null; + private reconnectScene: Scene|null = null; switchToDisconnectedScene(): void { if (this.currentGameScene === null) { return; From f7265c213eef40b7b6e0bce5394ec0b0986af5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 11 Jun 2020 10:40:43 +0200 Subject: [PATCH 4/4] Patch --- front/src/Phaser/Game/GameManager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 07bb204b..c275da53 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -189,6 +189,9 @@ export class GameManager { 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(); + // Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason. + setTimeout(() => this.reconnectToGameScene(lastPositionShared), 500); + return; } const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance); this.reconnectScene?.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });