From 12108bc52905cccaae7fc07489214527a8ebbade Mon Sep 17 00:00:00 2001 From: GRL Date: Fri, 27 Aug 2021 16:28:59 +0200 Subject: [PATCH] documentation and CHANGELOG --- CHANGELOG.md | 6 ++++++ docs/maps/api-deprecated.md | 1 + docs/maps/api-ui.md | 33 +++++++++++++++------------------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d23f4b9..710b85fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Version develop +### Updates +- New scripting API features : + - Use `WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions): Menu` to add a custom menu or an iframe to the menu. + +## Version 1.4.14 + ### Updates - New scripting API features : - Use `WA.room.loadTileset(url: string) : Promise` to load a tileset from a JSON file. diff --git a/docs/maps/api-deprecated.md b/docs/maps/api-deprecated.md index 930caebe..f2b582a5 100644 --- a/docs/maps/api-deprecated.md +++ b/docs/maps/api-deprecated.md @@ -18,3 +18,4 @@ The list of functions below is **deprecated**. You should not use those but. use - Method `WA.onChatMessage` is deprecated. It has been renamed to `WA.chat.onChatMessage`. - Method `WA.onEnterZone` is deprecated. It has been renamed to `WA.room.onEnterZone`. - Method `WA.onLeaveZone` is deprecated. It has been renamed to `WA.room.onLeaveZone`. +- Method `WA.ui.registerMenuCommand` parameter `callback` is deprecated. Use `WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions)`. \ No newline at end of file diff --git a/docs/maps/api-ui.md b/docs/maps/api-ui.md index 3239890a..dc701500 100644 --- a/docs/maps/api-ui.md +++ b/docs/maps/api-ui.md @@ -69,13 +69,15 @@ WA.room.onLeaveZone('myZone', () => { ### Add custom menu ``` -WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions | ((commandDescriptor: string) => void)): Menu +WA.ui.registerMenuCommand(commandDescriptor: string, options: MenuOptions): Menu ``` Add a custom menu item containing the text `commandDescriptor` in the navbar of the menu. -`options` attributes can have three values : -- `(commandDescriptor: string) => void` : That value is deprecated. But will work like the second value. -- `{callback : (commandDescriptor: string) => void, allowApi?: boolean = true}` : A click on the custom menu will trigger the `callback`. The `allowApi` attribute is not used with the `callback`. -- `{iframe: string, allowApi?: boolean = true}` : A click on the custom menu will open the `iframe` inside the menu. The `allowApi` attribute allow the `iframe` to use the Scripting API. +`options` attribute accepts an object with three properties : +- `callback : (commandDescriptor: string) => void` : A click on the custom menu will trigger the `callback`. +- `iframe: string` : A click on the custom menu will open the `iframe` inside the menu. +- `allowApi?: boolean` : Allow the iframe of the custom menu to use the Scripting API. + +Important : `options` accepts only `callback` or `iframe` not both. Custom menu exist only until the map is unloaded, or you leave the iframe zone of the script. @@ -90,20 +92,15 @@ Custom menu exist only until the map is unloaded, or you leave the iframe zone o Example: ```javascript -//Add a callback menu in a zone -let menu: undefined; -WA.room.onEnterZone('myZone', () => { - menu = WA.ui.registerMenuCommand('menu test', {callback: () => { - WA.chat.sendChatMessage('test'); - }}) -}) -//Remove the callback menu when the player leave the zone -WA.room.onLeaveZone('myZone', () => { - menu.remove(); -}) +const menu = WA.ui.registerMenuCommand('menu test', + { + callback: () => { + WA.chat.sendChatMessage('test'); + } + }) -//Add an iframe in the menu -WA.ui.registerMenuCommand('iframe', {iframe: 'myIframe.html', allowApi: true}); +// Some time later, if you want to remove the menu: +menu.remove(); ``` Please note that `registerMenuCommand` returns an object of the `Menu` class.