-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
PhaserTile.ts
36 lines (32 loc) · 1.13 KB
/
PhaserTile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Tile } from "../Tilemap.js";
import { TiledProject } from "./PhaserTilemap.js";
import { TiledProjectParser } from "tiled-property-flattener";
export class PhaserTile implements Tile {
constructor(
private phaserTile: Phaser.Tilemaps.Tile,
private tiledProject?: TiledProject,
) {}
getProperty(name: string): any {
const inheritedTileProps: Record<string, any> = {};
if (this.tiledProject) {
const parsedProject = TiledProjectParser.parse(this.tiledProject);
const type = this.getType();
if (type) {
const inheritedProps = parsedProject.getCustomTypesMap()?.get(type);
if (inheritedProps) {
for (const [key, val] of Object.entries(inheritedProps)) {
inheritedTileProps[key] = val;
}
}
}
}
const tileProps = this.phaserTile.properties as Record<string, any>;
return tileProps[name] ?? inheritedTileProps[name];
}
hasProperty(name: string): boolean {
return this.getProperty(name) != undefined;
}
private getType(): string | undefined {
return this.phaserTile.tileset?.tileData[this.phaserTile.index - 1]?.type;
}
}