diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 458e5f96..3b1d0b44 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -562,8 +562,7 @@ export class GameScene extends DirtyScene implements CenterListener { this.playerName, this.characterLayers, { - x: this.startPositionCalculator.startX, - y: this.startPositionCalculator.startY + ...this.startPositionCalculator.startPosition }, { left: camera.scrollX, @@ -970,8 +969,8 @@ ${escapedMessage} } else { //if the exit points to the current map, we simply teleport the user back to the startLayer this.startPositionCalculator.initPositionFromLayerName(hash, hash); - this.CurrentPlayer.x = this.startPositionCalculator.startX; - this.CurrentPlayer.y = this.startPositionCalculator.startY; + this.CurrentPlayer.x = this.startPositionCalculator.startPosition.x; + this.CurrentPlayer.y = this.startPositionCalculator.startPosition.y; setTimeout(() => this.mapTransitioning = false, 500); } } @@ -1114,8 +1113,8 @@ ${escapedMessage} try { this.CurrentPlayer = new Player( this, - this.startPositionCalculator.startX, - this.startPositionCalculator.startY, + this.startPositionCalculator.startPosition.x, + this.startPositionCalculator.startPosition.y, this.playerName, texturesPromise, PlayerAnimationDirections.Down, diff --git a/front/src/Phaser/Game/StartPositionCalculator.ts b/front/src/Phaser/Game/StartPositionCalculator.ts index 5dc454aa..aaad5415 100644 --- a/front/src/Phaser/Game/StartPositionCalculator.ts +++ b/front/src/Phaser/Game/StartPositionCalculator.ts @@ -6,10 +6,8 @@ import type { GameMap } from './GameMap'; const defaultStartLayerName = 'start'; export class StartPositionCalculator { - public startX!: number; - public startY!: number; - + public startPosition!: PositionInterface constructor( private readonly gameMap: GameMap, @@ -21,24 +19,25 @@ export class StartPositionCalculator { private initStartXAndStartY() { // If there is an init position passed if (this.initPosition !== null) { - this.startX = this.initPosition.x; - this.startY = this.initPosition.y; + this.startPosition = this.initPosition; } else { // Now, let's find the start layer if (this.startLayerName) { this.initPositionFromLayerName(this.startLayerName, this.startLayerName); } - if (this.startX === undefined) { + if (this.startPosition === undefined) { // If we have no start layer specified or if the hash passed does not exist, let's go with the default start position. this.initPositionFromLayerName(defaultStartLayerName, this.startLayerName); } } // Still no start position? Something is wrong with the map, we need a "start" layer. - if (this.startX === undefined) { + if (this.startPosition === undefined) { console.warn('This map is missing a layer named "start" that contains the available default start positions.'); // Let's start in the middle of the map - this.startX = this.mapFile.width * 16; - this.startY = this.mapFile.height * 16; + this.startPosition = { + x: this.mapFile.width * 16, + y: this.mapFile.height * 16 + }; } } @@ -54,8 +53,10 @@ export class StartPositionCalculator { for (const layer of this.gameMap.layersIterator) { if ((selectedOrDefaultLayer === layer.name || layer.name.endsWith('/' + selectedOrDefaultLayer)) && layer.type === 'tilelayer' && (selectedOrDefaultLayer === defaultStartLayerName || this.isStartLayer(layer))) { const startPosition = this.startUser(layer, selectedLayer); - this.startX = startPosition.x + this.mapFile.tilewidth / 2; - this.startY = startPosition.y + this.mapFile.tileheight / 2; + this.startPosition = { + x: startPosition.x + this.mapFile.tilewidth / 2, + y: startPosition.y + this.mapFile.tileheight / 2 + } } }