Fixing start position on disconnect

This commit is contained in:
David Négrier 2020-06-10 14:57:32 +02:00
parent 928e486de5
commit 43e4489d4d

View file

@ -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.'); 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 there is an init position passed
if (this.startLayerName) { if (this.initPosition !== null) {
for (let layer of this.mapFile.layers) { this.startX = this.initPosition.x;
if (this.startLayerName === layer.name && layer.type === 'tilelayer' && this.isStartLayer(layer)) { this.startY = this.initPosition.y;
let startPosition = this.startUser(layer); } else {
this.startX = startPosition.x; // Now, let's find the start layer
this.startY = startPosition.y; 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 (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.
// 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) {
for (let layer of this.mapFile.layers) { if (layer.type === 'tilelayer' && layer.name === "start") {
if (layer.type === 'tilelayer' && layer.name === "start") { let startPosition = this.startUser(layer);
let startPosition = this.startUser(layer); this.startX = startPosition.x;
this.startX = startPosition.x; this.startY = startPosition.y;
this.startY = startPosition.y; }
} }
} }
} }