Merge remote-tracking branch 'origin/metadataScriptingApi' into metadataScriptingApi
This commit is contained in:
commit
b4fa38bf8c
@ -258,7 +258,7 @@ WA.hideLayer('bottom');
|
|||||||
WA.setProperty(layerName : string, propertyName : string, propertyValue : string | number | boolean | undefined) : void;
|
WA.setProperty(layerName : string, propertyName : string, propertyValue : string | number | boolean | undefined) : void;
|
||||||
```
|
```
|
||||||
|
|
||||||
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`.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
|
|
||||||
@ -266,12 +266,12 @@ Example :
|
|||||||
WA.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
WA.setProperty('wikiLayer', 'openWebsite', 'https://www.wikipedia.org/');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Listen player movement
|
### Listen to player movement
|
||||||
|
|
||||||
```
|
```
|
||||||
onPlayerMove(callback: HasPlayerMovedEventCallback): void;
|
onPlayerMove(callback: HasPlayerMovedEventCallback): void;
|
||||||
```
|
```
|
||||||
Listens to the movement of the current user and calls the callback. Send a event when current user stop moving, change direction and every 200ms when moving in the same direction.
|
Listens to the movement of the current user and calls the callback. Sends an event when the user stops moving, changes direction and every 200ms when moving in the same direction.
|
||||||
|
|
||||||
The event has the following attributes :
|
The event has the following attributes :
|
||||||
* **moving (boolean):** **true** when the current player is moving, **false** otherwise.
|
* **moving (boolean):** **true** when the current player is moving, **false** otherwise.
|
||||||
@ -281,7 +281,7 @@ The event has the following attributes :
|
|||||||
|
|
||||||
**callback:** the function that will be called when the current player is moving. It contains the event.
|
**callback:** the function that will be called when the current player is moving. It contains the event.
|
||||||
|
|
||||||
Exemple :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
WA.onPlayerMove(console.log);
|
WA.onPlayerMove(console.log);
|
||||||
```
|
```
|
||||||
@ -292,7 +292,7 @@ WA.onPlayerMove(console.log);
|
|||||||
getMap(): Promise<ITiledMap>
|
getMap(): Promise<ITiledMap>
|
||||||
```
|
```
|
||||||
|
|
||||||
Return a promise of an ITiledMap that contains the JSON file of the map plus the property set by a script.
|
Returns a promise that resolves to the JSON file of the map. Please note that if you modified the map (for instance by calling `WA.setProperty`, the data returned by `getMap` will contain those changes.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
@ -360,23 +360,20 @@ WA.getStartLayerName().then((starLayerName) => {console.log(starLayerName)});
|
|||||||
```
|
```
|
||||||
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void)
|
registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void)
|
||||||
```
|
```
|
||||||
Add a custom menu named "commandDescriptor" in the menu that call the callback when clicked.
|
Add a custom menu item containing the text `commandDescriptor`. A click on the menu will trigger the `callback`.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
let chatbotEnabled = false
|
WA.registerMenuCommand('About', () => {
|
||||||
WA.registerMenuCommand('help', () => {
|
console.log("The About menu was clicked");
|
||||||
chatbotEnabled = true;
|
|
||||||
WA.onChatMessage ...
|
|
||||||
});
|
});
|
||||||
```
|
|
||||||
|
|
||||||
### Getting the list of tags of the current user
|
### Getting the list of tags of the current user
|
||||||
```
|
```
|
||||||
getTagUser(): Promise<string[]>
|
getTagUser(): Promise<string[]>
|
||||||
```
|
```
|
||||||
|
|
||||||
Return the list of all the tags that has the current user. If the current user has no tag, return an empty list. If there is no connection with the room, return nothing.
|
Returns the tags of the current user. If the current user has no tag, returns an empty list.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
```javascript
|
```javascript
|
||||||
@ -384,4 +381,3 @@ WA.getTagUser().then((tagList) => {
|
|||||||
...
|
...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,6 +10,6 @@ export const isGameStateEvent =
|
|||||||
tags : tg.isArray(tg.isString),
|
tags : tg.isArray(tg.isString),
|
||||||
}).get();
|
}).get();
|
||||||
/**
|
/**
|
||||||
* A message sent from the game to the iFrame when the gameState is got by the script
|
* A message sent from the game to the iFrame when the gameState is received by the script
|
||||||
*/
|
*/
|
||||||
export type GameStateEvent = tg.GuardedType<typeof isGameStateEvent>;
|
export type GameStateEvent = tg.GuardedType<typeof isGameStateEvent>;
|
||||||
|
@ -11,7 +11,7 @@ export const isHasPlayerMovedEvent =
|
|||||||
}).get();
|
}).get();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message sent from the game to the iFrame when the player move after the iFrame send a message to the game that it want to listen to the position of the player
|
* A message sent from the game to the iFrame to notify a movement from the current player.
|
||||||
*/
|
*/
|
||||||
export type HasPlayerMovedEvent = tg.GuardedType<typeof isHasPlayerMovedEvent>;
|
export type HasPlayerMovedEvent = tg.GuardedType<typeof isHasPlayerMovedEvent>;
|
||||||
|
|
||||||
|
@ -117,41 +117,14 @@ export class GameMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public findLayer(layerName: string): ITiledMapLayer | undefined {
|
public findLayer(layerName: string): ITiledMapLayer | undefined {
|
||||||
let i = 0;
|
return this.flatLayers.find((layer) => layer.name = layerName);
|
||||||
let found = false;
|
|
||||||
while (!found && i<this.flatLayers.length) {
|
|
||||||
if (this.flatLayers[i].name === layerName) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
return this.flatLayers[i];
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public findPhaserLayer(layerName: string): TilemapLayer | undefined {
|
public findPhaserLayer(layerName: string): TilemapLayer | undefined {
|
||||||
let i = 0;
|
return this.phaserLayers.find((layer) => layer.layer.name = layerName);
|
||||||
let found = false;
|
|
||||||
while (!found && i<this.phaserLayers.length) {
|
|
||||||
if (this.phaserLayers[i].layer.name === layerName) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
return this.phaserLayers[i];
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTerrain(terrain : Phaser.Tilemaps.Tileset): void {
|
public addTerrain(terrain : Phaser.Tilemaps.Tileset): void {
|
||||||
console.log('Add');
|
|
||||||
for (const phaserLayer of this.phaserLayers) {
|
for (const phaserLayer of this.phaserLayers) {
|
||||||
phaserLayer.tileset.push(terrain);
|
phaserLayer.tileset.push(terrain);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user