refactor to position object
This commit is contained in:
parent
c7fa5cab8b
commit
769e0fcc29
2 changed files with 17 additions and 17 deletions
|
@ -562,8 +562,7 @@ export class GameScene extends DirtyScene implements CenterListener {
|
||||||
this.playerName,
|
this.playerName,
|
||||||
this.characterLayers,
|
this.characterLayers,
|
||||||
{
|
{
|
||||||
x: this.startPositionCalculator.startX,
|
...this.startPositionCalculator.startPosition
|
||||||
y: this.startPositionCalculator.startY
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
left: camera.scrollX,
|
left: camera.scrollX,
|
||||||
|
@ -970,8 +969,8 @@ ${escapedMessage}
|
||||||
} else {
|
} else {
|
||||||
//if the exit points to the current map, we simply teleport the user back to the startLayer
|
//if the exit points to the current map, we simply teleport the user back to the startLayer
|
||||||
this.startPositionCalculator.initPositionFromLayerName(hash, hash);
|
this.startPositionCalculator.initPositionFromLayerName(hash, hash);
|
||||||
this.CurrentPlayer.x = this.startPositionCalculator.startX;
|
this.CurrentPlayer.x = this.startPositionCalculator.startPosition.x;
|
||||||
this.CurrentPlayer.y = this.startPositionCalculator.startY;
|
this.CurrentPlayer.y = this.startPositionCalculator.startPosition.y;
|
||||||
setTimeout(() => this.mapTransitioning = false, 500);
|
setTimeout(() => this.mapTransitioning = false, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1114,8 +1113,8 @@ ${escapedMessage}
|
||||||
try {
|
try {
|
||||||
this.CurrentPlayer = new Player(
|
this.CurrentPlayer = new Player(
|
||||||
this,
|
this,
|
||||||
this.startPositionCalculator.startX,
|
this.startPositionCalculator.startPosition.x,
|
||||||
this.startPositionCalculator.startY,
|
this.startPositionCalculator.startPosition.y,
|
||||||
this.playerName,
|
this.playerName,
|
||||||
texturesPromise,
|
texturesPromise,
|
||||||
PlayerAnimationDirections.Down,
|
PlayerAnimationDirections.Down,
|
||||||
|
|
|
@ -6,10 +6,8 @@ import type { GameMap } from './GameMap';
|
||||||
const defaultStartLayerName = 'start';
|
const defaultStartLayerName = 'start';
|
||||||
|
|
||||||
export class StartPositionCalculator {
|
export class StartPositionCalculator {
|
||||||
public startX!: number;
|
|
||||||
public startY!: number;
|
|
||||||
|
|
||||||
|
|
||||||
|
public startPosition!: PositionInterface
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly gameMap: GameMap,
|
private readonly gameMap: GameMap,
|
||||||
|
@ -21,24 +19,25 @@ export class StartPositionCalculator {
|
||||||
private initStartXAndStartY() {
|
private initStartXAndStartY() {
|
||||||
// If there is an init position passed
|
// If there is an init position passed
|
||||||
if (this.initPosition !== null) {
|
if (this.initPosition !== null) {
|
||||||
this.startX = this.initPosition.x;
|
this.startPosition = this.initPosition;
|
||||||
this.startY = this.initPosition.y;
|
|
||||||
} else {
|
} else {
|
||||||
// Now, let's find the start layer
|
// Now, let's find the start layer
|
||||||
if (this.startLayerName) {
|
if (this.startLayerName) {
|
||||||
this.initPositionFromLayerName(this.startLayerName, 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.
|
// 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);
|
this.initPositionFromLayerName(defaultStartLayerName, this.startLayerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Still no start position? Something is wrong with the map, we need a "start" layer.
|
// 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.');
|
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
|
// Let's start in the middle of the map
|
||||||
this.startX = this.mapFile.width * 16;
|
this.startPosition = {
|
||||||
this.startY = this.mapFile.height * 16;
|
x: this.mapFile.width * 16,
|
||||||
|
y: this.mapFile.height * 16
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +53,10 @@ export class StartPositionCalculator {
|
||||||
for (const layer of this.gameMap.layersIterator) {
|
for (const layer of this.gameMap.layersIterator) {
|
||||||
if ((selectedOrDefaultLayer === layer.name || layer.name.endsWith('/' + selectedOrDefaultLayer)) && layer.type === 'tilelayer' && (selectedOrDefaultLayer === defaultStartLayerName || this.isStartLayer(layer))) {
|
if ((selectedOrDefaultLayer === layer.name || layer.name.endsWith('/' + selectedOrDefaultLayer)) && layer.type === 'tilelayer' && (selectedOrDefaultLayer === defaultStartLayerName || this.isStartLayer(layer))) {
|
||||||
const startPosition = this.startUser(layer, selectedLayer);
|
const startPosition = this.startUser(layer, selectedLayer);
|
||||||
this.startX = startPosition.x + this.mapFile.tilewidth / 2;
|
this.startPosition = {
|
||||||
this.startY = startPosition.y + this.mapFile.tileheight / 2;
|
x: startPosition.x + this.mapFile.tilewidth / 2,
|
||||||
|
y: startPosition.y + this.mapFile.tileheight / 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue