allow start hashes in tiles
# Conflicts: # front/src/Phaser/Game/GameScene.ts
This commit is contained in:
parent
633fa9f870
commit
b20b4abb9e
2 changed files with 21 additions and 7 deletions
|
@ -35,6 +35,13 @@ export class GameMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public getPropertiesForIndex(index: number): Array<ITiledMapLayerProperty> {
|
||||||
|
if (this.tileSetPropertyMap[index]) {
|
||||||
|
return this.tileSetPropertyMap[index]
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the position of the current player (in pixels)
|
* Sets the position of the current player (in pixels)
|
||||||
|
|
|
@ -971,7 +971,7 @@ ${escapedMessage}
|
||||||
this.scene.start(roomId);
|
this.scene.start(roomId);
|
||||||
} 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.initPositionFromLayerName(hash || defaultStartLayerName);
|
this.initPositionFromLayerName(hash || defaultStartLayerName, hash);
|
||||||
this.CurrentPlayer.x = this.startX;
|
this.CurrentPlayer.x = this.startX;
|
||||||
this.CurrentPlayer.y = this.startY;
|
this.CurrentPlayer.y = this.startY;
|
||||||
setTimeout(() => this.mapTransitioning = false, 500);
|
setTimeout(() => this.mapTransitioning = false, 500);
|
||||||
|
@ -1044,11 +1044,11 @@ ${escapedMessage}
|
||||||
} 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.initPositionFromLayerName(this.startLayerName, null);
|
||||||
}
|
}
|
||||||
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.
|
||||||
this.initPositionFromLayerName(defaultStartLayerName);
|
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.
|
||||||
|
@ -1060,10 +1060,10 @@ ${escapedMessage}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private initPositionFromLayerName(layerName: string) {
|
private initPositionFromLayerName(layerName: string, startLayerName: string | null) {
|
||||||
for (const layer of this.gameMap.layersIterator) {
|
for (const layer of this.gameMap.layersIterator) {
|
||||||
if ((layerName === layer.name || layer.name.endsWith('/'+layerName)) && layer.type === 'tilelayer' && (layerName === defaultStartLayerName || this.isStartLayer(layer))) {
|
if ((layerName === layer.name || layer.name.endsWith('/'+layerName)) && layer.type === 'tilelayer' && (layerName === defaultStartLayerName || this.isStartLayer(layer))) {
|
||||||
const startPosition = this.startUser(layer);
|
const startPosition = this.startUser(layer, startLayerName);
|
||||||
this.startX = startPosition.x + this.mapFile.tilewidth/2;
|
this.startX = startPosition.x + this.mapFile.tilewidth/2;
|
||||||
this.startY = startPosition.y + this.mapFile.tileheight/2;
|
this.startY = startPosition.y + this.mapFile.tileheight/2;
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1117,7 @@ ${escapedMessage}
|
||||||
return gameManager.loadMap(room, this.scene).catch(() => {});
|
return gameManager.loadMap(room, this.scene).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private startUser(layer: ITiledMapTileLayer): PositionInterface {
|
private startUser(layer: ITiledMapTileLayer, startName: string | null): PositionInterface {
|
||||||
const tiles = layer.data;
|
const tiles = layer.data;
|
||||||
if (typeof(tiles) === 'string') {
|
if (typeof(tiles) === 'string') {
|
||||||
throw new Error('The content of a JSON map must be filled as a JSON array, not as a string');
|
throw new Error('The content of a JSON map must be filled as a JSON array, not as a string');
|
||||||
|
@ -1130,7 +1130,14 @@ ${escapedMessage}
|
||||||
const y = Math.floor(key / layer.width);
|
const y = Math.floor(key / layer.width);
|
||||||
const x = key % layer.width;
|
const x = key % layer.width;
|
||||||
|
|
||||||
possibleStartPositions.push({x: x * this.mapFile.tilewidth, y: y * this.mapFile.tilewidth});
|
if (startName) {
|
||||||
|
const properties = this.gameMap.getPropertiesForIndex(objectKey);
|
||||||
|
if (!properties.length || !properties.some(property => property.name == "start" && property.value == startName)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
possibleStartPositions.push({ x: x * this.mapFile.tilewidth, y: y * this.mapFile.tilewidth });
|
||||||
});
|
});
|
||||||
// Get a value at random amongst allowed values
|
// Get a value at random amongst allowed values
|
||||||
if (possibleStartPositions.length === 0) {
|
if (possibleStartPositions.length === 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue