refactored to Array of tile

This commit is contained in:
jonny 2021-05-10 01:21:37 +02:00
parent bed45a8310
commit 8db72d2dfd
2 changed files with 17 additions and 14 deletions

View File

@ -3,13 +3,14 @@ import * as tg from "generic-type-guard";
export const updateTile = "updateTile" export const updateTile = "updateTile"
export const isUpdateTileEvent = export const isUpdateTileEvent = tg.isArray(
new tg.IsInterface().withProperties({ new tg.IsInterface().withProperties({
x: tg.isNumber, x: tg.isNumber,
y: tg.isNumber, y: tg.isNumber,
tile: tg.isUnion(tg.isNumber, tg.isString), tile: tg.isUnion(tg.isNumber, tg.isString),
layer: tg.isUnion(tg.isNumber, tg.isString) layer: tg.isUnion(tg.isNumber, tg.isString)
}).get(); }).get()
);
/** /**
* A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property.
*/ */

View File

@ -868,18 +868,20 @@ ${escapedMessage}
})); }));
this.iframeSubscriptionList.push(iframeListener.updateTileEvent.subscribe(event => { this.iframeSubscriptionList.push(iframeListener.updateTileEvent.subscribe(event => {
const layer = this.Layers.find(layer => layer.layer.name == event.layer) for (const eventTile of event) {
if (layer) { const layer = this.Layers.find(layer => layer.layer.name == eventTile.layer)
const tile = layer.getTileAt(event.x, event.y) if (layer) {
if (typeof event.tile == "string") { const tile = layer.getTileAt(eventTile.x, eventTile.y)
const tileIndex = this.getIndexForTileType(event.tile); if (typeof eventTile.tile == "string") {
if (tileIndex) { const tileIndex = this.getIndexForTileType(eventTile.tile);
tile.index = tileIndex if (tileIndex) {
tile.index = tileIndex
} else {
return
}
} else { } else {
return tile.index = eventTile.tile
} }
} else {
tile.index = event.tile
} }
this.scene.scene.sys.game.events.emit("contextrestored") this.scene.scene.sys.game.events.emit("contextrestored")
} }
@ -898,7 +900,7 @@ ${escapedMessage}
} }
private getIndexForTileType(tileType: string): number | undefined { private getIndexForTileType(tileType: string): number | null {
for (const tileset of this.mapFile.tilesets) { for (const tileset of this.mapFile.tilesets) {
if (tileset.tiles) { if (tileset.tiles) {
for (const tilesetTile of tileset.tiles) { for (const tilesetTile of tileset.tiles) {
@ -908,7 +910,7 @@ ${escapedMessage}
} }
} }
} }
return undefined return null
} }
private getMapDirUrl(): string { private getMapDirUrl(): string {