Add documentation
No second parameter
This commit is contained in:
parent
6f6ad949ca
commit
e50292a2ba
4 changed files with 17 additions and 18 deletions
|
@ -54,6 +54,7 @@ WA.room.showLayer(layerName : string): void
|
||||||
WA.room.hideLayer(layerName : string) : void
|
WA.room.hideLayer(layerName : string) : void
|
||||||
```
|
```
|
||||||
These 2 methods can be used to show and hide a layer.
|
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 :
|
Example :
|
||||||
```javascript
|
```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`.
|
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 :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
WA.room.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
WA.room.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
||||||
|
|
|
@ -3,7 +3,6 @@ import * as tg from "generic-type-guard";
|
||||||
export const isLayerEvent = new tg.IsInterface()
|
export const isLayerEvent = new tg.IsInterface()
|
||||||
.withProperties({
|
.withProperties({
|
||||||
name: tg.isString,
|
name: tg.isString,
|
||||||
group: tg.isBoolean,
|
|
||||||
})
|
})
|
||||||
.get();
|
.get();
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -93,11 +93,11 @@ export class WorkadventureRoomCommands extends IframeApiContribution<Workadventu
|
||||||
}
|
}
|
||||||
subject.subscribe(callback);
|
subject.subscribe(callback);
|
||||||
}
|
}
|
||||||
showLayer(layerName: string, group: boolean = false): void {
|
showLayer(layerName: string): void {
|
||||||
sendToWorkadventure({ type: "showLayer", data: { name: layerName, group: group } });
|
sendToWorkadventure({ type: "showLayer", data: { name: layerName } });
|
||||||
}
|
}
|
||||||
hideLayer(layerName: string, group: boolean = false): void {
|
hideLayer(layerName: string): void {
|
||||||
sendToWorkadventure({ type: "hideLayer", data: { name: layerName, group: group } });
|
sendToWorkadventure({ type: "hideLayer", data: { name: layerName } });
|
||||||
}
|
}
|
||||||
setProperty(layerName: string, propertyName: string, propertyValue: string | number | boolean | undefined): void {
|
setProperty(layerName: string, propertyName: string, propertyValue: string | number | boolean | undefined): void {
|
||||||
sendToWorkadventure({
|
sendToWorkadventure({
|
||||||
|
|
|
@ -1026,13 +1026,13 @@ ${escapedMessage}
|
||||||
|
|
||||||
this.iframeSubscriptionList.push(
|
this.iframeSubscriptionList.push(
|
||||||
iframeListener.showLayerStream.subscribe((layerEvent) => {
|
iframeListener.showLayerStream.subscribe((layerEvent) => {
|
||||||
this.setLayerVisibility(layerEvent.name, true, layerEvent.group);
|
this.setLayerVisibility(layerEvent.name, true);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.iframeSubscriptionList.push(
|
this.iframeSubscriptionList.push(
|
||||||
iframeListener.hideLayerStream.subscribe((layerEvent) => {
|
iframeListener.hideLayerStream.subscribe((layerEvent) => {
|
||||||
this.setLayerVisibility(layerEvent.name, false, layerEvent.group);
|
this.setLayerVisibility(layerEvent.name, false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1088,9 +1088,13 @@ ${escapedMessage}
|
||||||
property.value = propertyValue;
|
property.value = propertyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setLayerVisibility(layerName: string, visible: boolean, group: boolean): void {
|
private setLayerVisibility(layerName: string, visible: boolean): void {
|
||||||
if (group) {
|
const phaserLayer = this.gameMap.findPhaserLayer(layerName);
|
||||||
const phaserLayers = this.gameMap.findPhaserLayers(layerName);
|
if (phaserLayer != undefined) {
|
||||||
|
phaserLayer.setVisible(visible);
|
||||||
|
phaserLayer.setCollisionByProperty({ collides: true }, visible);
|
||||||
|
} else {
|
||||||
|
const phaserLayers = this.gameMap.findPhaserLayers(layerName + "/");
|
||||||
if (phaserLayers === []) {
|
if (phaserLayers === []) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Could not find layer with name that contains "' +
|
'Could not find layer with name that contains "' +
|
||||||
|
@ -1103,14 +1107,6 @@ ${escapedMessage}
|
||||||
phaserLayers[i].setVisible(visible);
|
phaserLayers[i].setVisible(visible);
|
||||||
phaserLayers[i].setCollisionByProperty({ collides: true }, 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();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue