Add documentation

No second parameter
This commit is contained in:
GRL 2021-07-07 16:58:54 +02:00
parent 6f6ad949ca
commit e50292a2ba
4 changed files with 17 additions and 18 deletions

View File

@ -54,6 +54,7 @@ WA.room.showLayer(layerName : string): void
WA.room.hideLayer(layerName : string) : void
```
These 2 methods can be used to show and hide a layer.
if `layerName` is the name of a group layer, show/hide all the layer in that group layer.
Example :
```javascript
@ -70,6 +71,9 @@ WA.room.setProperty(layerName : string, propertyName : string, propertyValue : s
Set the value of the `propertyName` property of the layer `layerName` at `propertyValue`. If the property doesn't exist, create the property `propertyName` and set the value of the property at `propertyValue`.
Note :
To unset a property form a layer, use `setProperty` with `propertyValue` set to `undefined`.
Example :
```javascript
WA.room.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');

View File

@ -3,7 +3,6 @@ import * as tg from "generic-type-guard";
export const isLayerEvent = new tg.IsInterface()
.withProperties({
name: tg.isString,
group: tg.isBoolean,
})
.get();
/**

View File

@ -93,11 +93,11 @@ export class WorkadventureRoomCommands extends IframeApiContribution<Workadventu
}
subject.subscribe(callback);
}
showLayer(layerName: string, group: boolean = false): void {
sendToWorkadventure({ type: "showLayer", data: { name: layerName, group: group } });
showLayer(layerName: string): void {
sendToWorkadventure({ type: "showLayer", data: { name: layerName } });
}
hideLayer(layerName: string, group: boolean = false): void {
sendToWorkadventure({ type: "hideLayer", data: { name: layerName, group: group } });
hideLayer(layerName: string): void {
sendToWorkadventure({ type: "hideLayer", data: { name: layerName } });
}
setProperty(layerName: string, propertyName: string, propertyValue: string | number | boolean | undefined): void {
sendToWorkadventure({

View File

@ -1026,13 +1026,13 @@ ${escapedMessage}
this.iframeSubscriptionList.push(
iframeListener.showLayerStream.subscribe((layerEvent) => {
this.setLayerVisibility(layerEvent.name, true, layerEvent.group);
this.setLayerVisibility(layerEvent.name, true);
})
);
this.iframeSubscriptionList.push(
iframeListener.hideLayerStream.subscribe((layerEvent) => {
this.setLayerVisibility(layerEvent.name, false, layerEvent.group);
this.setLayerVisibility(layerEvent.name, false);
})
);
@ -1088,9 +1088,13 @@ ${escapedMessage}
property.value = propertyValue;
}
private setLayerVisibility(layerName: string, visible: boolean, group: boolean): void {
if (group) {
const phaserLayers = this.gameMap.findPhaserLayers(layerName);
private setLayerVisibility(layerName: string, visible: boolean): void {
const phaserLayer = this.gameMap.findPhaserLayer(layerName);
if (phaserLayer != undefined) {
phaserLayer.setVisible(visible);
phaserLayer.setCollisionByProperty({ collides: true }, visible);
} else {
const phaserLayers = this.gameMap.findPhaserLayers(layerName + "/");
if (phaserLayers === []) {
console.warn(
'Could not find layer with name that contains "' +
@ -1103,14 +1107,6 @@ ${escapedMessage}
phaserLayers[i].setVisible(visible);
phaserLayers[i].setCollisionByProperty({ collides: true }, visible);
}
} else {
const phaserLayer = this.gameMap.findPhaserLayer(layerName);
if (phaserLayer === undefined) {
console.warn('Could not find layer "' + layerName + '" when calling WA.hideLayer / WA.showLayer');
return;
}
phaserLayer.setVisible(visible);
phaserLayer.setCollisionByProperty({ collides: true }, visible);
}
this.markDirty();
}