Properties changed via the Iframe API now trigger changes directly
Changes performed in WA.room.setPropertyLayer now have a real-time impact. If the property is changed on a layer the current player is on, the changes will be triggered.
This commit is contained in:
parent
a0d3685227
commit
4536a63e69
@ -80,8 +80,11 @@ export class GameMap {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
this.triggerAll();
|
||||||
|
}
|
||||||
|
|
||||||
const newProps = this.getProperties(key);
|
private triggerAll(): void {
|
||||||
|
const newProps = this.getProperties(this.key ?? 0);
|
||||||
const oldProps = this.lastProperties;
|
const oldProps = this.lastProperties;
|
||||||
this.lastProperties = newProps;
|
this.lastProperties = newProps;
|
||||||
|
|
||||||
@ -253,4 +256,34 @@ export class GameMap {
|
|||||||
}
|
}
|
||||||
return this.tileNameMap.get(tile);
|
return this.tileNameMap.get(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setLayerProperty(
|
||||||
|
layerName: string,
|
||||||
|
propertyName: string,
|
||||||
|
propertyValue: string | number | undefined | boolean
|
||||||
|
) {
|
||||||
|
const layer = this.findLayer(layerName);
|
||||||
|
if (layer === undefined) {
|
||||||
|
console.warn('Could not find layer "' + layerName + '" when calling setProperty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (layer.properties === undefined) {
|
||||||
|
layer.properties = [];
|
||||||
|
}
|
||||||
|
const property = layer.properties.find((property) => property.name === propertyName);
|
||||||
|
if (property === undefined) {
|
||||||
|
if (propertyValue === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
layer.properties.push({ name: propertyName, type: typeof propertyValue, value: propertyValue });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (propertyValue === undefined) {
|
||||||
|
const index = layer.properties.indexOf(property);
|
||||||
|
layer.properties.splice(index, 1);
|
||||||
|
}
|
||||||
|
property.value = propertyValue;
|
||||||
|
|
||||||
|
this.triggerAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1241,30 +1241,10 @@ ${escapedMessage}
|
|||||||
propertyName: string,
|
propertyName: string,
|
||||||
propertyValue: string | number | boolean | undefined
|
propertyValue: string | number | boolean | undefined
|
||||||
): void {
|
): void {
|
||||||
const layer = this.gameMap.findLayer(layerName);
|
|
||||||
if (layer === undefined) {
|
|
||||||
console.warn('Could not find layer "' + layerName + '" when calling setProperty');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (propertyName === "exitUrl" && typeof propertyValue === "string") {
|
if (propertyName === "exitUrl" && typeof propertyValue === "string") {
|
||||||
this.loadNextGameFromExitUrl(propertyValue);
|
this.loadNextGameFromExitUrl(propertyValue);
|
||||||
}
|
}
|
||||||
if (layer.properties === undefined) {
|
this.gameMap.setLayerProperty(layerName, propertyName, propertyValue);
|
||||||
layer.properties = [];
|
|
||||||
}
|
|
||||||
const property = layer.properties.find((property) => property.name === propertyName);
|
|
||||||
if (property === undefined) {
|
|
||||||
if (propertyValue === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
layer.properties.push({ name: propertyName, type: typeof propertyValue, value: propertyValue });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (propertyValue === undefined) {
|
|
||||||
const index = layer.properties.indexOf(property);
|
|
||||||
layer.properties.splice(index, 1);
|
|
||||||
}
|
|
||||||
property.value = propertyValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private setLayerVisibility(layerName: string, visible: boolean): void {
|
private setLayerVisibility(layerName: string, visible: boolean): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user