removed redundancy, fix for startLayer

This commit is contained in:
Lurkars 2021-02-27 15:44:31 +01:00 committed by David Négrier
parent 9b6be3466b
commit 93b7b7bc91

View File

@ -354,22 +354,22 @@ export class GameScene extends ResizableScene implements CenterListener {
}
// helper for recursive group layer support
private createHelper(that: this, layers: ITiledMapLayer[], depth: integer, prefix: string): integer {
private createHelper(layers: ITiledMapLayer[], depth: integer, prefix: string): integer {
for(const layer of layers) {
if(layer.type === 'tilelayer') {
that.addLayer(that.Map.createStaticLayer(prefix + layer.name, that.Terrains, 0, 0).setDepth(depth));
this.addLayer(this.Map.createStaticLayer(prefix + layer.name, this.Terrains, 0, 0).setDepth(depth));
const exitSceneUrl = that.getExitSceneUrl(layer);
const exitSceneUrl = this.getExitSceneUrl(layer);
if(exitSceneUrl !== undefined) {
that.loadNextGame(exitSceneUrl);
this.loadNextGame(exitSceneUrl);
}
const exitUrl = that.getExitUrl(layer);
const exitUrl = this.getExitUrl(layer);
if(exitUrl !== undefined) {
that.loadNextGame(exitUrl);
this.loadNextGame(exitUrl);
}
}
if(layer.type === 'group') {
that.createHelper(that, layer.layers, depth, prefix + layer.name + '/');
this.createHelper(layer.layers, depth, prefix + layer.name + '/');
}
if(layer.type === 'objectgroup' && layer.name === 'floorLayer') {
depth = 10000;
@ -411,7 +411,7 @@ export class GameScene extends ResizableScene implements CenterListener {
//add layer on map
this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>();
let depth = this.createHelper(this, this.mapFile.layers, -2, '');
let depth = this.createHelper(this.mapFile.layers, -2, '');
if (depth === -2) {
throw new Error('Your map MUST contain a layer of type "objectgroup" whose name is "floorLayer" that represents the layer characters are drawn at.');
@ -964,16 +964,22 @@ ${escapedMessage}
}
}
private initPositionFromLayerName(layerName: string) {
for (const layer of this.mapFile.layers) {
private initPositionFromLayerNameHelper(layerName: string, layers : ITiledMapLayer[]) {
for (const layer of layers) {
if (layerName === layer.name && layer.type === 'tilelayer' && (layerName === defaultStartLayerName || this.isStartLayer(layer))) {
const startPosition = this.startUser(layer);
this.startX = startPosition.x + this.mapFile.tilewidth/2;
this.startY = startPosition.y + this.mapFile.tileheight/2;
} else if (layer.type === 'group') {
this.initPositionFromLayerNameHelper(layerName, layer.layers);
}
}
}
private initPositionFromLayerName(layerName: string) {
this.initPositionFromLayerNameHelper(layerName, this.mapFile.layers);
}
private getExitUrl(layer: ITiledMapLayer): string|undefined {
return this.getProperty(layer, "exitUrl") as string|undefined;
}