Room - WorkAdventure Documentation
Room - WorkAdventure Documentation
Using Typescript
WA.room.onEnterLayer(name: string): Subscription
Map Storage API WA.room.onLeaveLayer(name: string): Subscription
Room API
Listens to the position of the current user. The event is triggered when the user enters or leaves a given layer.
Example:
WA.room.onLeaveLayer("myLayer").subscribe(() => {
WA.chat.sendChatMessage("Goodbye!", "Mr Robot");
myLayerSubscriber.unsubscribe();
});
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 :
WA.room.showLayer("bottom");
//...
WA.room.hideLayer("bottom");
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 from a layer, use setProperty with propertyValue set to undefined .
Example :
Create Area
WA.room.area.create(area: {
name: string, // Name of the area (must be unique)
x: number, // X position
y: number, // Y position
width: number, // Width size
height: number, // Height size
}): Area;
You can create new Area object (currently limited to rectangular shapes).
Example:
Get an Area
Modify Area
It is possible to modify already existing Area object (currently limited to x, y, width, height).
Delete Area
You can delete Area if it has a name.
WA.room.area.delete('MyNewArea');
Listens to the position of the current user. The event is triggered when the user enters or leaves a given area.
Example:
WA.room.area.onLeave("myArea").subscribe(() => {
WA.chat.sendChatMessage("Goodbye!", "Mr Robot");
myAreaSubscriber.unsubscribe();
});
Set the value of the propertyName property of the area 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 from an area, use setProperty with propertyValue set to undefined .
Example :
WA.room.id: string;
INFO
You need to wait for the end of the initialization before accessing WA.room.id
WA.onInit().then(() => {
console.log("Room id: ", WA.room.id);
// Will output something like: 'https://play.workadventu.re/@/myorg/myworld/myroom', or 'https://play.worka
});
WA.room.mapURL: string;
INFO
You need to wait for the end of the initialization before accessing WA.room.mapURL
WA.onInit().then(() => {
console.log("Map URL: ", WA.room.mapURL);
// Will output something like: 'https://mymap.org/map.json"
});
WA.room.getTiledMap(): Promise<ITiledMap>
Check the Tiled documentation to learn more about the format of the JSON map .
The parameters passed in the hash (#) are available in WA.room.hashParameters property. Use this to pass parameters from the URL
to your script.
INFO
You need to wait for the end of the initialization before accessing WA.room.hashParameters
WA.onInit().then(() => {
console.log("Map URL: ", WA.room.hashParameters.myparam);
// Will output something like: 'hello"
});
Changing tiles
Replace the tile at the x and y coordinates in the layer named layer by the tile with the id tile .
If tile is a string, it's not the id of the tile but the value of the property name .
Important ! : If you use tile as a number, be sure to add the firstgid of the tileset of the tile that you want to the id of the tile in
Tiled Editor.
Note: If you want to unset a tile, use setTiles with tile set to null .
Example :
WA.room.setTiles([
{ x: 6, y: 4, tile: "blue", layer: "setTiles" },
{ x: 7, y: 4, tile: 109, layer: "setTiles" },
{ x: 8, y: 4, tile: 109, layer: "setTiles" },
{ x: 9, y: 4, tile: "blue", layer: "setTiles" },
]);
Loading a tileset
Load a tileset in JSON format from an url and return the id of the first tile of the loaded tileset.
WA.room.loadTileset("Assets/Tileset.json").then((firstId) => {
WA.room.setTiles([{ x: 4, y: 4, tile: firstId, layer: "bottom" }]);
});
You can get an instance of an embedded website by using the WA.room.website.get() method. It returns a promise of an
EmbeddedWebsite instance.
// Get an existing website object where 'my_website' is the name of the object (on any layer object of the ma
const website = await WA.room.website.get("my_website");
website.url = "https://example.com";
website.visible = true;
interface CreateEmbeddedWebsiteEvent {
name: string; // A unique name for this iframe
url: string; // The URL the iframe points to.
position: {
x: number, // In "game" pixels, relative to the map or player coordinates, depending on origin
y: number, // In "game" pixels, relative to the map or player coordinates, depending on origin
width: number, // In "game" pixels
height: number, // In "game" pixels
},
visible?: boolean, // Whether to display the iframe or not
allowApi?: boolean, // Whether the scripting API should be available to the iframe
allow?: string, // The list of feature policies allowed
origin: "player" | "map" // The origin used to place the x and y coordinates of the iframe's top-left cor
scale: number, // A ratio used to resize the iframe
}
You can create an instance of an embedded website by using the WA.room.website.create() method. It returns an
EmbeddedWebsite instance.
class EmbeddedWebsite {
readonly name: string;
url: string;
visible: boolean;
allow: string;
allowApi: boolean;
x: number; // In "game" pixels, relative to the map or player coordinates, depending on origin
y: number; // In "game" pixels, relative to the map or player coordinates, depending on origin
width: number; // In "game" pixels
height: number; // In "game" pixels
origin: "player" | "map";
scale: number;
}
When you modify a property of an EmbeddedWebsite instance, the iframe is automatically modified in the map.
CAUTION
The websites you add/edit/delete via the scripting API are only shown locally. If you want them to be displayed for every player,
you can use variables to share a common state between all users.
Previous Next
« Players Sound »