From 43e4489d4d4a09748f36f5cf196084205cb6e71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 10 Jun 2020 14:57:32 +0200 Subject: [PATCH] Fixing start position on disconnect --- front/src/Phaser/Game/GameScene.ts | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 245b2f32..387b7ad3 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -160,23 +160,29 @@ export class GameScene extends Phaser.Scene { throw new Error('Your map MUST contain a layer of type "objectgroup" whose name is "floorLayer" that represents the layer characters are drawn at.'); } - // Now, let's find the start layer - if (this.startLayerName) { - for (let layer of this.mapFile.layers) { - if (this.startLayerName === layer.name && layer.type === 'tilelayer' && this.isStartLayer(layer)) { - let startPosition = this.startUser(layer); - this.startX = startPosition.x; - this.startY = startPosition.y; + // If there is an init position passed + if (this.initPosition !== null) { + this.startX = this.initPosition.x; + this.startY = this.initPosition.y; + } else { + // Now, let's find the start layer + if (this.startLayerName) { + for (let layer of this.mapFile.layers) { + if (this.startLayerName === layer.name && layer.type === 'tilelayer' && this.isStartLayer(layer)) { + let startPosition = this.startUser(layer); + this.startX = startPosition.x; + this.startY = startPosition.y; + } } } - } - if (this.startX === undefined) { - // If we have no start layer specified or if the hash passed does not exist, let's go with the default start position. - for (let layer of this.mapFile.layers) { - if (layer.type === 'tilelayer' && layer.name === "start") { - let startPosition = this.startUser(layer); - this.startX = startPosition.x; - this.startY = startPosition.y; + if (this.startX === undefined) { + // If we have no start layer specified or if the hash passed does not exist, let's go with the default start position. + for (let layer of this.mapFile.layers) { + if (layer.type === 'tilelayer' && layer.name === "start") { + let startPosition = this.startUser(layer); + this.startX = startPosition.x; + this.startY = startPosition.y; + } } } }