This commit is contained in:
Hanusiak Piotr 2021-12-14 10:28:41 +01:00
parent b12fb228af
commit 0f1378c069

View File

@ -63,6 +63,7 @@ export class GameMap {
public readonly flatLayers: ITiledMapLayer[]; public readonly flatLayers: ITiledMapLayer[];
public readonly tiledObjects: ITiledMapObject[]; public readonly tiledObjects: ITiledMapObject[];
public readonly phaserLayers: TilemapLayer[] = []; public readonly phaserLayers: TilemapLayer[] = [];
public readonly zones: ITiledMapObject[] = [];
public exitUrls: Array<string> = []; public exitUrls: Array<string> = [];
@ -75,6 +76,7 @@ export class GameMap {
) { ) {
this.flatLayers = flattenGroupLayersMap(map); this.flatLayers = flattenGroupLayersMap(map);
this.tiledObjects = this.getObjectsFromLayers(this.flatLayers); this.tiledObjects = this.getObjectsFromLayers(this.flatLayers);
this.zones = this.tiledObjects.filter((object) => object.type === "zone");
let depth = -2; let depth = -2;
for (const layer of this.flatLayers) { for (const layer of this.flatLayers) {
@ -192,12 +194,11 @@ export class GameMap {
} }
/** /**
* We user Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering. * We use Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering.
*/ */
private triggerZonesChange(): void { private triggerZonesChange(): void {
const zones = this.tiledObjects.filter((object) => object.type === "zone");
const zonesByOldPosition = this.oldPosition const zonesByOldPosition = this.oldPosition
? zones.filter((zone) => { ? this.zones.filter((zone) => {
if (!this.oldPosition) { if (!this.oldPosition) {
return false; return false;
} }
@ -206,7 +207,7 @@ export class GameMap {
: []; : [];
const zonesByNewPosition = this.position const zonesByNewPosition = this.position
? zones.filter((zone) => { ? this.zones.filter((zone) => {
if (!this.position) { if (!this.position) {
return false; return false;
} }
@ -466,16 +467,11 @@ export class GameMap {
const objectLayers = layers.filter((layer) => layer.type === "objectgroup"); const objectLayers = layers.filter((layer) => layer.type === "objectgroup");
for (const objectLayer of objectLayers) { for (const objectLayer of objectLayers) {
if (this.isOfTypeITiledMapObjectLayer(objectLayer)) { if (objectLayer.type === "objectgroup") {
objects.push(...objectLayer.objects); objects.push(...objectLayer.objects);
} }
} }
return objects; return objects;
} }
// NOTE: Simple typeguard for Objects Layer.
private isOfTypeITiledMapObjectLayer(obj: ITiledMapLayer): obj is ITiledMapObjectLayer {
return (obj as ITiledMapObjectLayer).objects !== undefined;
}
} }