coverted property map to object

This commit is contained in:
jonny 2021-06-19 15:41:58 +02:00
parent 27ccdf165c
commit c1d9b2c9ed

View File

@ -12,10 +12,7 @@ export class GameMap {
private lastProperties = new Map<string, string | boolean | number>(); private lastProperties = new Map<string, string | boolean | number>();
private callbacks = new Map<string, Array<PropertyChangeCallback>>(); private callbacks = new Map<string, Array<PropertyChangeCallback>>();
/** private tileSetPropertyMap: { [tilset_firstgid: number]: { [tile_id: number]: Array<ITiledMapLayerProperty> } } = {}
* tileset.firstgid => (Map<tileid,Array<ITiledMapLayerProperty>>)
*/
private tileSetPropertyMap = new Map<number, Map<number, Array<ITiledMapLayerProperty>>>()
public readonly layersIterator: LayersIterator; public readonly layersIterator: LayersIterator;
public exitUrls: Array<string> = [] public exitUrls: Array<string> = []
@ -24,12 +21,12 @@ export class GameMap {
this.layersIterator = new LayersIterator(map); this.layersIterator = new LayersIterator(map);
for (const tileset of map.tilesets) { for (const tileset of map.tilesets) {
if (!this.tileSetPropertyMap.has(tileset.firstgid)) { if (!this.tileSetPropertyMap[tileset.firstgid]) {
this.tileSetPropertyMap.set(tileset.firstgid, new Map()) this.tileSetPropertyMap[tileset.firstgid] = {}
} }
tileset?.tiles?.forEach(tile => { tileset?.tiles?.forEach(tile => {
if (tile.properties) { if (tile.properties) {
this.tileSetPropertyMap.get(tileset.firstgid)?.set(tile.id, tile.properties) this.tileSetPropertyMap[tileset.firstgid][tile.id] = tile.properties
tile.properties.forEach(prop => { tile.properties.forEach(prop => {
if (prop.name == "exitUrl" && typeof prop.value == "string") { if (prop.name == "exitUrl" && typeof prop.value == "string") {
this.exitUrls.push(prop.value); this.exitUrls.push(prop.value);
@ -106,7 +103,7 @@ export class GameMap {
if (tileIndex) { if (tileIndex) {
const tileset = this.map.tilesets.find(tileset => tileset.firstgid + tileset.tilecount > (tileIndex as number)) const tileset = this.map.tilesets.find(tileset => tileset.firstgid + tileset.tilecount > (tileIndex as number))
if (tileset) { if (tileset) {
const tileProperties = this.tileSetPropertyMap.get(tileset?.firstgid)?.get(tileIndex - tileset.firstgid) const tileProperties = this.tileSetPropertyMap[tileset?.firstgid][tileIndex - tileset.firstgid]
if (tileProperties) { if (tileProperties) {
for (const property of tileProperties) { for (const property of tileProperties) {
if (property.value) { if (property.value) {