From 6dcb0d3750f78838ac03f89131bce9132489869c Mon Sep 17 00:00:00 2001 From: GRL Date: Thu, 27 May 2021 17:06:39 +0200 Subject: [PATCH 01/19] first step to change tile --- front/src/Api/Events/ChangeTileEvent.ts | 14 +- front/src/Phaser/Game/GameScene.ts | 17 +- front/src/iframe_api.ts | 21 +- maps/tests/Metadata/changeTile.html | 28 +++ maps/tests/Metadata/changeTile.json | 275 ++++++++++++++++++++++++ 5 files changed, 334 insertions(+), 21 deletions(-) create mode 100644 maps/tests/Metadata/changeTile.html create mode 100644 maps/tests/Metadata/changeTile.json diff --git a/front/src/Api/Events/ChangeTileEvent.ts b/front/src/Api/Events/ChangeTileEvent.ts index 23599881..4a071403 100644 --- a/front/src/Api/Events/ChangeTileEvent.ts +++ b/front/src/Api/Events/ChangeTileEvent.ts @@ -1,12 +1,14 @@ import * as tg from "generic-type-guard"; export const isChangeTileEvent = - new tg.IsInterface().withProperties({ - x: tg.isNumber, - y: tg.isNumber, - tile: tg.isUnion(tg.isNumber, tg.isString), - layer: tg.isUnion(tg.isNumber, tg.isString) - }).get(); + tg.isArray( + new tg.IsInterface().withProperties({ + x: tg.isNumber, + y: tg.isNumber, + tile: tg.isUnion(tg.isNumber, tg.isString), + layer: tg.isString + }).get() + ); /** * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. */ diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index b314fe3b..cb820ba4 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -890,19 +890,12 @@ ${escapedMessage} this.userInputManager.restoreControls(); })) -/* this.iframeSubscriptionList.push(iframeListener.loadPageStream.subscribe((url: string) => { - this.loadNextGame(url).then(() => { - this.events.once(EVENT_TYPE.POST_UPDATE, () => { - this.onMapExit(url); - }) - }) - }))*/ - - this.iframeSubscriptionList.push(iframeListener.updateTileEvent.subscribe(event => { + this.iframeSubscriptionList.push(iframeListener.changeTileStream.subscribe(event => { for (const eventTile of event) { const layer = this.gameMap.findPhaserLayer(eventTile.layer); if (layer) { - const tile = layer.getTileAt(eventTile.x, eventTile.y) + console.log('layer : ', layer); + const tile = layer.getTileAt(eventTile.x, eventTile.y, true) if (typeof eventTile.tile == "string") { const tileIndex = this.getIndexForTileType(eventTile.tile); if (tileIndex) { @@ -911,11 +904,11 @@ ${escapedMessage} return } } else { - tile.index = eventTile.tile + tile.index = eventTile.tile //+ firsrtgid du layer } } } - this.scene.scene.sys.game.events.emit("contextrestored") + //this.dirty = true; })) let scriptedBubbleSprite: Sprite; diff --git a/front/src/iframe_api.ts b/front/src/iframe_api.ts index a390e616..b8b5ccdf 100644 --- a/front/src/iframe_api.ts +++ b/front/src/iframe_api.ts @@ -44,9 +44,10 @@ interface WorkAdventureApi { displayBubble(): void; removeBubble(): void; loadSound(url : string): Sound; - registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void): void - getCurrentUser(): Promise - getCurrentRoom(): Promise + registerMenuCommand(commandDescriptor: string, callback: (commandDescriptor: string) => void): void; + getCurrentUser(): Promise; + getCurrentRoom(): Promise; + changeTile(tiles: TileDescriptor[]): void; //loadTileset(name: string, imgUrl : string, tilewidth : number, tileheight : number, margin : number, spacing : number): void; onPlayerMove(callback: (playerMovedEvent: HasPlayerMovedEvent) => void): void @@ -65,6 +66,13 @@ interface Room { startLayer: string | null } +interface TileDescriptor { + x: number + y: number + tile: number | string + layer: string +} + declare global { // eslint-disable-next-line no-var var WA: WorkAdventureApi @@ -221,6 +229,13 @@ window.WA = { }) }, + changeTile(tiles: TileDescriptor[]) { + postToParent({ + type: 'changeTile', + data: tiles + }) + }, + /** * Send a message in the chat. * Only the local user will receive this message. diff --git a/maps/tests/Metadata/changeTile.html b/maps/tests/Metadata/changeTile.html new file mode 100644 index 00000000..214908a9 --- /dev/null +++ b/maps/tests/Metadata/changeTile.html @@ -0,0 +1,28 @@ + + + + + + + + + \ No newline at end of file diff --git a/maps/tests/Metadata/changeTile.json b/maps/tests/Metadata/changeTile.json new file mode 100644 index 00000000..48f57e0f --- /dev/null +++ b/maps/tests/Metadata/changeTile.json @@ -0,0 +1,275 @@ +{ "compressionlevel":-1, + "height":10, + "infinite":false, + "layers":[ + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":10, + "id":1, + "name":"start", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "data":[33, 34, 34, 34, 34, 34, 34, 34, 34, 35, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 49, 50, 50, 50, 50, 50, 50, 50, 50, 51], + "height":10, + "id":2, + "name":"bottom", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":10, + "id":4, + "name":"metadata", + "opacity":1, + "properties":[ + { + "name":"openWebsite", + "type":"string", + "value":"changeTile.html" + }, + { + "name":"openWebsiteAllowApi", + "type":"bool", + "value":true + }], + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "data":[65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":10, + "id":8, + "name":"changeTile", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "draworder":"topdown", + "id":5, + "name":"floorLayer", + "objects":[ + { + "height":159.866671635267, + "id":1, + "name":"", + "rotation":0, + "text": + { + "fontfamily":"Sans Serif", + "pixelsize":9, + "text":"Test : \nWalk on the grass\n\nResult : \nTiles of the first left colum become red tile (tile find by Number)\nTiles of the below the grass become blue (tile find by String)\n", + "wrap":true + }, + "type":"", + "visible":true, + "width":287.674838251912, + "x":32.5473600365393, + "y":160.305680721763 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + }], + "nextlayerid":9, + "nextobjectid":2, + "orientation":"orthogonal", + "renderorder":"right-down", + "tiledversion":"1.4.3", + "tileheight":32, + "tilesets":[ + { + "columns":8, + "firstgid":1, + "image":"tileset_dungeon.png", + "imageheight":256, + "imagewidth":256, + "margin":0, + "name":"TDungeon", + "spacing":0, + "tilecount":64, + "tileheight":32, + "tiles":[ + { + "id":0, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":1, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":2, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":3, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":4, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":8, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":9, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":10, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":11, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":12, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":16, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":17, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":18, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":19, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }, + { + "id":20, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }] + }], + "tilewidth":32 + }, + { + "columns":8, + "firstgid":65, + "image":"floortileset.png", + "imageheight":288, + "imagewidth":256, + "margin":0, + "name":"Floor", + "spacing":0, + "tilecount":72, + "tileheight":32, + "tiles":[ + { + "id":34, + "type":"Red" + }, + { + "id":44, + "type":"blue" + }], + "tilewidth":32 + }], + "tilewidth":32, + "type":"map", + "version":1.4, + "width":10 +} \ No newline at end of file From 0623ee0bf2ebb8cb1f4b4277aad3d1373d2050f9 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Mon, 21 Jun 2021 11:44:18 +0200 Subject: [PATCH 02/19] HOTFIX: loading errors after the preload stage should not crash the game anymore --- .../Entity/PlayerTexturesLoadingManager.ts | 22 ++++++++++++++++--- front/src/Phaser/Game/GameScene.ts | 16 +++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts b/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts index 95f00a9e..eaba79aa 100644 --- a/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts +++ b/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts @@ -59,9 +59,11 @@ export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, textur } else { returnPromise = Promise.resolve(texturekeys); } + + //If the loading fail, we render the default model instead. return returnPromise.then((keys) => keys.map((key) => { return typeof key !== 'string' ? key.name : key; - })) + })).catch(() => lazyLoadPlayerCharacterTextures(loadPlugin, ["color_22", "eyes_23"])); } export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptionInterface): BodyResourceDescriptionInterface => { @@ -80,11 +82,25 @@ export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptio } export const createLoadingPromise = (loadPlugin: LoaderPlugin, playerResourceDescriptor: BodyResourceDescriptionInterface, frameConfig: FrameConfig) => { - return new Promise((res) => { + return new Promise((res, rej) => { + console.log('count', loadPlugin.listenerCount('loaderror')); if (loadPlugin.textureManager.exists(playerResourceDescriptor.name)) { return res(playerResourceDescriptor); } loadPlugin.spritesheet(playerResourceDescriptor.name, playerResourceDescriptor.img, frameConfig); - loadPlugin.once('filecomplete-spritesheet-' + playerResourceDescriptor.name, () => res(playerResourceDescriptor)); + const errorCallback = (file: {src: string}) => { + if (file.src !== playerResourceDescriptor.img) return; + console.error('failed loading player ressource: ', playerResourceDescriptor) + rej(playerResourceDescriptor); + loadPlugin.off('filecomplete-spritesheet-' + playerResourceDescriptor.name, successCallback); + loadPlugin.off('loaderror', errorCallback); + } + const successCallback = () => { + loadPlugin.off('loaderror', errorCallback); + res(playerResourceDescriptor); + } + + loadPlugin.once('filecomplete-spritesheet-' + playerResourceDescriptor.name, successCallback); + loadPlugin.on('loaderror', errorCallback); }); } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 72279c61..62d66c30 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -192,6 +192,7 @@ export class GameScene extends DirtyScene implements CenterListener { private pinchManager: PinchManager|undefined; private mapTransitioning: boolean = false; //used to prevent transitions happenning at the same time. private emoteManager!: EmoteManager; + private preloading: boolean = true; constructor(private room: Room, MapUrlFile: string, customKey?: string|undefined) { super({ @@ -259,11 +260,15 @@ export class GameScene extends DirtyScene implements CenterListener { return; } - this.scene.start(ErrorSceneName, { - title: 'Network error', - subTitle: 'An error occurred while loading resource:', - message: this.originalMapUrl ?? file.src - }); + //once preloading is over, we don't want loading errors to crash the game, so we need to disable this behavior after preloading. + console.error('Error when loading: ', file); + if (this.preloading) { + this.scene.start(ErrorSceneName, { + title: 'Network error', + subTitle: 'An error occurred while loading resource:', + message: this.originalMapUrl ?? file.src + }); + } }); this.load.on('filecomplete-tilemapJSON-'+this.MapUrlFile, (key: string, type: string, data: unknown) => { this.onMapLoad(data); @@ -388,6 +393,7 @@ export class GameScene extends DirtyScene implements CenterListener { //hook create scene create(): void { + this.preloading = false; this.trackDirtyAnims(); gameManager.gameSceneIsCreated(this); From 3e29ed4376a9e469c51291a93f8d0c1599e03b84 Mon Sep 17 00:00:00 2001 From: GRL Date: Tue, 22 Jun 2021 11:48:08 +0200 Subject: [PATCH 03/19] Correction of button customize WOKA scene issue --- .../CustomCharacterScene.svelte | 12 +++---- front/src/Phaser/Login/CustomizeScene.ts | 32 +++++++++---------- front/src/Stores/CustomCharacterStore.ts | 4 ++- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/front/src/Components/CustomCharacterScene/CustomCharacterScene.svelte b/front/src/Components/CustomCharacterScene/CustomCharacterScene.svelte index f9e3a66b..3fff6bc0 100644 --- a/front/src/Components/CustomCharacterScene/CustomCharacterScene.svelte +++ b/front/src/Components/CustomCharacterScene/CustomCharacterScene.svelte @@ -1,11 +1,11 @@ diff --git a/maps/tests/Metadata/changeTile.json b/maps/tests/Metadata/changeTile.json index 48f57e0f..834ea9a1 100644 --- a/maps/tests/Metadata/changeTile.json +++ b/maps/tests/Metadata/changeTile.json @@ -1,4 +1,11 @@ { "compressionlevel":-1, + "editorsettings": + { + "export": + { + "target":"." + } + }, "height":10, "infinite":false, "layers":[ @@ -50,7 +57,7 @@ "y":0 }, { - "data":[65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "data":[65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0], "height":10, "id":8, "name":"changeTile", @@ -67,7 +74,7 @@ "name":"floorLayer", "objects":[ { - "height":159.866671635267, + "height":191.866671635267, "id":1, "name":"", "rotation":0, @@ -75,14 +82,14 @@ { "fontfamily":"Sans Serif", "pixelsize":9, - "text":"Test : \nWalk on the grass\n\nResult : \nTiles of the first left colum become red tile (tile find by Number)\nTiles of the below the grass become blue (tile find by String)\n", + "text":"Test : \nWalk on the grass\n\nResult : \nThe Yellow Tile open a jitsi with Trigger.\n\nThe Red Tile open cowebsite Wikip\u00e9dia. The highest Red Tile is find by 'string' index, the lowest by 'number' index.\n\nThe White Tile are silent tile. You can not open a bubble in it. (Even if the other player didn't activate the script.)\n\nThe Pale Tile (Lowest) is an exitUrl tile to customMenu.json.\n\nThe Blue Tile are 'collides' tile. The two tile in the center are 'number' index. The others are 'string' index.\n", "wrap":true }, "type":"", "visible":true, "width":287.674838251912, "x":32.5473600365393, - "y":160.305680721763 + "y":128.305680721763 }], "opacity":1, "type":"objectgroup", @@ -258,13 +265,62 @@ "tilecount":72, "tileheight":32, "tiles":[ + { + "id":9, + "properties":[ + { + "name":"exitUrl", + "type":"string", + "value":"customMenu.json" + }] + }, + { + "id":27, + "properties":[ + { + "name":"jitsiRoom", + "type":"string", + "value":"TEST" + }, + { + "name":"jitsiTrigger", + "type":"string", + "value":"onaction" + }, + { + "name":"jitsiUrl", + "type":"string", + "value":"meet.jit.si" + }] + }, { "id":34, + "properties":[ + { + "name":"openWebsite", + "type":"string", + "value":"https:\/\/fr.wikipedia.org\/wiki\/Wikip%C3%A9dia:Accueil_principal" + }], "type":"Red" }, { "id":44, + "properties":[ + { + "name":"collides", + "type":"bool", + "value":true + }], "type":"blue" + }, + { + "id":52, + "properties":[ + { + "name":"silent", + "type":"bool", + "value":true + }] }], "tilewidth":32 }], From b182a08ca2c6290e37570522ec49037fec45beb7 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 28 Jun 2021 09:33:13 +0200 Subject: [PATCH 05/19] correction from review --- docs/maps/api-room.md | 9 ++++++ front/src/Api/IframeListener.ts | 2 -- front/src/Phaser/Game/GameMap.ts | 48 ++++++++++++++++++++++++++--- front/src/Phaser/Game/GameScene.ts | 30 +----------------- maps/tests/Metadata/changeTile.json | 29 +++++++++++++---- 5 files changed, 76 insertions(+), 42 deletions(-) diff --git a/docs/maps/api-room.md b/docs/maps/api-room.md index 3bb01cc0..74eafee7 100644 --- a/docs/maps/api-room.md +++ b/docs/maps/api-room.md @@ -118,6 +118,14 @@ WA.room.getCurrentUser().then((user) => { WA.room.changeTile(tiles: TileDescriptor[]): void ``` 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`. +
+
+ +
+
+ `TileDescriptor` has the following attributes : * **x (number) :** The coordinate x of the tile that you want to replace. * **y (number) :** The coordinate y of the tile that you want to replace. @@ -126,6 +134,7 @@ Replace the tile at the `x` and `y` coordinates in the layer named `layer` by th **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. + Example : ```javascript WA.room.changeTile([ diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index ac3723b7..cbe4dcf3 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -193,8 +193,6 @@ class IframeListener { this._unregisterMenuCommandStream.next(data); }) handleMenuItemRegistrationEvent(payload.data) - } else if (payload.type == "registerMenuCommand" && isMenuItemRegisterEvent(payload.data)) { - this._registerMenuCommandStream.next(payload.data.menutItem) } else if (payload.type == "changeTile" && isChangeTileEvent(payload.data)) { this._changeTileStream.next(payload.data); } diff --git a/front/src/Phaser/Game/GameMap.ts b/front/src/Phaser/Game/GameMap.ts index ab3e6010..aeb4cb62 100644 --- a/front/src/Phaser/Game/GameMap.ts +++ b/front/src/Phaser/Game/GameMap.ts @@ -13,8 +13,9 @@ export class GameMap { private key: number | undefined; private lastProperties = new Map(); private callbacks = new Map>(); + private tileNameMap = new Map(); - private tileSetPropertyMap: { [tile_index: number]: Array } = {} + private tileSetPropertyMap: { [tile_index: number]: Array } = {}; public readonly flatLayers: ITiledMapLayer[]; public readonly phaserLayers: TilemapLayer[] = []; @@ -36,6 +37,9 @@ export class GameMap { if (tile.properties) { this.tileSetPropertyMap[tileset.firstgid + tile.id] = tile.properties tile.properties.forEach(prop => { + if (prop.name == 'name' && typeof prop.value == "string") { + this.tileNameMap.set(prop.value, tileset.firstgid + tile.id); + } if (prop.name == "exitUrl" && typeof prop.value == "string") { this.exitUrls.push(prop.value); } @@ -130,8 +134,8 @@ export class GameMap { return this.map; } - public getTilesetProperties(): { [tile_index: number]: Array } { - return this.tileSetPropertyMap; + private getTileProperty(index: number): Array { + return this.tileSetPropertyMap[index]; } private trigger(propName: string, oldValue: string | number | boolean | undefined, newValue: string | number | boolean | undefined, allProps: Map) { @@ -169,13 +173,47 @@ export class GameMap { } } - public putTileInFlatLayer(index: number, x: number, y: number, layer: string): void { + private putTileInFlatLayer(index: number, x: number, y: number, layer: string): void { const fLayer = this.findLayer(layer); - if (fLayer?.type !== 'tilelayer') { + if ( fLayer == undefined ) { + console.error("The layer that you want to change doesn't exist."); + return; + } + if (fLayer.type !== 'tilelayer') { + console.error("The layer that you want to change is not a tilelayer. Tile can only be put in tilelayer."); return; } // @ts-ignore fLayer.data[x+y*fLayer.height] = index; } + public putTile(tile: string | number, x: number, y: number, layer: string): void { + const phaserLayer = this.findPhaserLayer(layer); + if ( phaserLayer ) { + const tileIndex = this.getIndexForTileType(tile); + if ( tileIndex !== undefined ) { + this.putTileInFlatLayer(tileIndex, x, y, layer); + const phaserTile = phaserLayer.putTileAt(tileIndex, x, y); + for (const property of this.getTileProperty(tileIndex)) { + if ( property.name === "collides" ) { + phaserTile.setCollision(true); + } + } + } + else { + console.error("The tile that you want to place doesn't exist."); + } + } + else { + console.error("The layer that you want to change is not a tilelayer. Tile can only be put in tilelayer."); + } + } + + private getIndexForTileType(tile: string | number): number | undefined { + if (typeof tile == "number") { + return tile; + } + return this.tileNameMap.get(tile); + } + } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 9a46991a..a3a890e6 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -954,19 +954,7 @@ ${escapedMessage} })); this.iframeSubscriptionList.push(iframeListener.changeTileStream.subscribe((eventTiles) => { for (const eventTile of eventTiles) { - const layer = this.gameMap.findPhaserLayer(eventTile.layer); - if ( layer ) { - const tileIndex = this.getIndexForTileType(eventTile.tile); - if ( tileIndex ) { - this.gameMap.putTileInFlatLayer(tileIndex, eventTile.x, eventTile.y, eventTile.layer); - const tile = layer.putTileAt(tileIndex, eventTile.x, eventTile.y); - for (const property of this.gameMap.getTilesetProperties()[tileIndex]) { - if ( property.name === "collides" ) { - tile.setCollision(true); - } - } - } - } + this.gameMap.putTile(eventTile.tile, eventTile.x, eventTile.y, eventTile.layer); } })) @@ -997,22 +985,6 @@ ${escapedMessage} this.dirty = true; } - private getIndexForTileType(tileType: string | number): number | null { - if (typeof tileType == "number") { - return tileType; - } - for (const tileset of this.mapFile.tilesets) { - if (tileset.tiles) { - for (const tilesetTile of tileset.tiles) { - if (tilesetTile.type == tileType) { - return tileset.firstgid + tilesetTile.id - } - } - } - } - return null - } - private getMapDirUrl(): string { return this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/')); } diff --git a/maps/tests/Metadata/changeTile.json b/maps/tests/Metadata/changeTile.json index 834ea9a1..bdf34704 100644 --- a/maps/tests/Metadata/changeTile.json +++ b/maps/tests/Metadata/changeTile.json @@ -82,12 +82,12 @@ { "fontfamily":"Sans Serif", "pixelsize":9, - "text":"Test : \nWalk on the grass\n\nResult : \nThe Yellow Tile open a jitsi with Trigger.\n\nThe Red Tile open cowebsite Wikip\u00e9dia. The highest Red Tile is find by 'string' index, the lowest by 'number' index.\n\nThe White Tile are silent tile. You can not open a bubble in it. (Even if the other player didn't activate the script.)\n\nThe Pale Tile (Lowest) is an exitUrl tile to customMenu.json.\n\nThe Blue Tile are 'collides' tile. The two tile in the center are 'number' index. The others are 'string' index.\n", + "text":"Test : \nWalk on the grass\n\nResult : \nThe Yellow Tile open a jitsi with Trigger.\n\nThe Red Tile open cowebsite Wikip\u00e9dia. The highest Red Tile is find by 'name' property index, the lowest by 'number' index.\n\nThe White Tile are silent tile. You can not open a bubble in it. (Even if the other player didn't activate the script.)\n\nThe Pale Tile (Lowest) is an exitUrl tile to customMenu.json.\n\nThe Blue Tile are 'collides' tile. The two tile in the center are 'number' index. The others are 'name' property index.\n", "wrap":true }, "type":"", "visible":true, - "width":287.674838251912, + "width":274.674838251912, "x":32.5473600365393, "y":128.305680721763 }], @@ -296,12 +296,25 @@ { "id":34, "properties":[ + { + "name":"name", + "type":"string", + "value":"Red" + }, { "name":"openWebsite", "type":"string", "value":"https:\/\/fr.wikipedia.org\/wiki\/Wikip%C3%A9dia:Accueil_principal" - }], - "type":"Red" + }] + }, + { + "id":40, + "properties":[ + { + "name":"name", + "type":"string", + "value":"" + }] }, { "id":44, @@ -310,8 +323,12 @@ "name":"collides", "type":"bool", "value":true - }], - "type":"blue" + }, + { + "name":"name", + "type":"string", + "value":"blue" + }] }, { "id":52, From 0b161a2368ce52161b64def7c155961201394d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 28 Jun 2021 09:56:18 +0200 Subject: [PATCH 06/19] Fixing typos --- maps/tests/Metadata/changeTile.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maps/tests/Metadata/changeTile.json b/maps/tests/Metadata/changeTile.json index bdf34704..71e4c45b 100644 --- a/maps/tests/Metadata/changeTile.json +++ b/maps/tests/Metadata/changeTile.json @@ -82,7 +82,7 @@ { "fontfamily":"Sans Serif", "pixelsize":9, - "text":"Test : \nWalk on the grass\n\nResult : \nThe Yellow Tile open a jitsi with Trigger.\n\nThe Red Tile open cowebsite Wikip\u00e9dia. The highest Red Tile is find by 'name' property index, the lowest by 'number' index.\n\nThe White Tile are silent tile. You can not open a bubble in it. (Even if the other player didn't activate the script.)\n\nThe Pale Tile (Lowest) is an exitUrl tile to customMenu.json.\n\nThe Blue Tile are 'collides' tile. The two tile in the center are 'number' index. The others are 'name' property index.\n", + "text":"Test : \nWalk on the grass\n\nResult : \nThe Yellow Tile opens a Jitsi with Trigger.\n\nThe Red Tile opens cowebsite Wikipedia. The highest Red Tile is found by 'name' property index, the lowest by 'number' index.\n\nThe White Tiles are silent tiles. You cannot open a bubble in it. (Even if the other player didn't activate the script.)\n\nThe Pale Tile (Lowest) is an exitUrl tile to customMenu.json.\n\nThe Blue Tile are 'collides' tile. The two tiles in the center are 'number' index. The others are 'name' property index.\n", "wrap":true }, "type":"", @@ -345,4 +345,4 @@ "type":"map", "version":1.4, "width":10 -} \ No newline at end of file +} From 651b0a45184934bf119681427518ac11bbfc8bf1 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 28 Jun 2021 12:03:06 +0200 Subject: [PATCH 07/19] Add test map for changing tiles by script in index --- maps/tests/index.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/maps/tests/index.html b/maps/tests/index.html index 0929ab83..d1c887ae 100644 --- a/maps/tests/index.html +++ b/maps/tests/index.html @@ -162,6 +162,14 @@ Test animated tiles + + + Success Failure Pending + + + Test change tiles + + + - - \ No newline at end of file + From 1e57028e6ea507a6da75da8a9c98a3f614150393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 28 Jun 2021 14:58:49 +0200 Subject: [PATCH 09/19] Renaming `changeTile` to `setTiles` --- CHANGELOG.md | 2 +- docs/maps/api-room.md | 14 ++--- front/src/Api/Events/IframeEvent.ts | 4 +- .../{ChangeTileEvent.ts => SetTilesEvent.ts} | 6 +- front/src/Api/IframeListener.ts | 10 +-- front/src/Api/iframe/room.ts | 4 +- front/src/Phaser/Game/GameScene.ts | 2 +- maps/tests/Metadata/changeTile.html | 31 ---------- maps/tests/Metadata/setTiles.html | 31 ++++++++++ .../{changeTile.json => setTiles.json} | 62 +++++++++---------- maps/tests/index.html | 4 +- 11 files changed, 85 insertions(+), 85 deletions(-) rename front/src/Api/Events/{ChangeTileEvent.ts => SetTilesEvent.ts} (56%) delete mode 100644 maps/tests/Metadata/changeTile.html create mode 100644 maps/tests/Metadata/setTiles.html rename maps/tests/Metadata/{changeTile.json => setTiles.json} (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4bc7ba3..c8992891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - Use `WA.room.getCurrentUser(): Promise` to get the ID, name and tags of the current player - Use `WA.room.getCurrentRoom(): Promise` to get the ID, JSON map file, url of the map of the current room and the layer where the current player started - Use `WA.ui.registerMenuCommand(): void` to add a custom menu - - Use `WA.room.changeTile(): void` to change an array of tiles + - Use `WA.room.setTiles(): void` to change an array of tiles ## Version 1.4.1 diff --git a/docs/maps/api-room.md b/docs/maps/api-room.md index 74eafee7..17e3d48e 100644 --- a/docs/maps/api-room.md +++ b/docs/maps/api-room.md @@ -115,7 +115,7 @@ WA.room.getCurrentUser().then((user) => { ### Changing tiles ``` -WA.room.changeTile(tiles: TileDescriptor[]): void +WA.room.setTiles(tiles: TileDescriptor[]): void ``` Replace the tile at the `x` and `y` coordinates in the layer named `layer` by the tile with the id `tile`. @@ -137,10 +137,10 @@ If `tile` is a string, it's not the id of the tile but the value of the property Example : ```javascript -WA.room.changeTile([ - {x: 6, y: 4, tile: 'blue', layer: 'changeTile'}, - {x: 7, y: 4, tile: 109, layer: 'changeTile'}, - {x: 8, y: 4, tile: 109, layer: 'changeTile'}, - {x: 9, y: 4, tile: 'blue', layer: 'changeTile'} +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'} ]); -``` \ No newline at end of file +``` diff --git a/front/src/Api/Events/IframeEvent.ts b/front/src/Api/Events/IframeEvent.ts index ac6ee1cd..137eccad 100644 --- a/front/src/Api/Events/IframeEvent.ts +++ b/front/src/Api/Events/IframeEvent.ts @@ -18,7 +18,7 @@ import type { PlaySoundEvent } from "./PlaySoundEvent"; import type { MenuItemClickedEvent } from "./ui/MenuItemClickedEvent"; import type { MenuItemRegisterEvent } from './ui/MenuItemRegisterEvent'; import type { HasPlayerMovedEvent } from "./HasPlayerMovedEvent"; -import type { ChangeTileEvent } from "./ChangeTileEvent"; +import type { SetTilesEvent } from "./SetTilesEvent"; export interface TypedMessageEvent extends MessageEvent { data: T @@ -46,7 +46,7 @@ export type IframeEventMap = { loadSound: LoadSoundEvent playSound: PlaySoundEvent stopSound: null - changeTile: ChangeTileEvent + setTiles: SetTilesEvent getState: undefined, registerMenuCommand: MenuItemRegisterEvent } diff --git a/front/src/Api/Events/ChangeTileEvent.ts b/front/src/Api/Events/SetTilesEvent.ts similarity index 56% rename from front/src/Api/Events/ChangeTileEvent.ts rename to front/src/Api/Events/SetTilesEvent.ts index 4a071403..24dd2e35 100644 --- a/front/src/Api/Events/ChangeTileEvent.ts +++ b/front/src/Api/Events/SetTilesEvent.ts @@ -1,6 +1,6 @@ import * as tg from "generic-type-guard"; -export const isChangeTileEvent = +export const isSetTilesEvent = tg.isArray( new tg.IsInterface().withProperties({ x: tg.isNumber, @@ -10,6 +10,6 @@ export const isChangeTileEvent = }).get() ); /** - * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. + * A message sent from the iFrame to the game to set one or many tiles. */ -export type ChangeTileEvent = tg.GuardedType; \ No newline at end of file +export type SetTilesEvent = tg.GuardedType; diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index cbe4dcf3..e8b0fc0b 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -29,7 +29,7 @@ import type {GameStateEvent} from "./Events/GameStateEvent"; import type {HasPlayerMovedEvent} from "./Events/HasPlayerMovedEvent"; import {isLoadPageEvent} from "./Events/LoadPageEvent"; import {handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent} from "./Events/ui/MenuItemRegisterEvent"; -import {ChangeTileEvent, isChangeTileEvent} from "./Events/ChangeTileEvent"; +import {SetTilesEvent, isSetTilesEvent} from "./Events/SetTilesEvent"; /** * Listens to messages from iframes and turn those messages into easy to use observables. @@ -103,8 +103,8 @@ class IframeListener { private readonly _loadSoundStream: Subject = new Subject(); public readonly loadSoundStream = this._loadSoundStream.asObservable(); - private readonly _changeTileStream: Subject = new Subject(); - public readonly changeTileStream = this._changeTileStream.asObservable(); + private readonly _setTilesStream: Subject = new Subject(); + public readonly setTilesStream = this._setTilesStream.asObservable(); private readonly iframes = new Set(); private readonly iframeCloseCallbacks = new Map void)[]>(); @@ -193,8 +193,8 @@ class IframeListener { this._unregisterMenuCommandStream.next(data); }) handleMenuItemRegistrationEvent(payload.data) - } else if (payload.type == "changeTile" && isChangeTileEvent(payload.data)) { - this._changeTileStream.next(payload.data); + } else if (payload.type == "setTiles" && isSetTilesEvent(payload.data)) { + this._setTilesStream.next(payload.data); } } }, false); diff --git a/front/src/Api/iframe/room.ts b/front/src/Api/iframe/room.ts index a16a8918..f3d2f360 100644 --- a/front/src/Api/iframe/room.ts +++ b/front/src/Api/iframe/room.ts @@ -137,9 +137,9 @@ class WorkadventureRoomCommands extends IframeApiContribution { + this.iframeSubscriptionList.push(iframeListener.setTilesStream.subscribe((eventTiles) => { for (const eventTile of eventTiles) { this.gameMap.putTile(eventTile.tile, eventTile.x, eventTile.y, eventTile.layer); } diff --git a/maps/tests/Metadata/changeTile.html b/maps/tests/Metadata/changeTile.html deleted file mode 100644 index eddf3323..00000000 --- a/maps/tests/Metadata/changeTile.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - diff --git a/maps/tests/Metadata/setTiles.html b/maps/tests/Metadata/setTiles.html new file mode 100644 index 00000000..90b5a84d --- /dev/null +++ b/maps/tests/Metadata/setTiles.html @@ -0,0 +1,31 @@ + + + + + + + + diff --git a/maps/tests/Metadata/changeTile.json b/maps/tests/Metadata/setTiles.json similarity index 94% rename from maps/tests/Metadata/changeTile.json rename to maps/tests/Metadata/setTiles.json index 71e4c45b..5b281a15 100644 --- a/maps/tests/Metadata/changeTile.json +++ b/maps/tests/Metadata/setTiles.json @@ -20,7 +20,7 @@ "width":10, "x":0, "y":0 - }, + }, { "data":[33, 34, 34, 34, 34, 34, 34, 34, 34, 35, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 49, 50, 50, 50, 50, 50, 50, 50, 50, 51], "height":10, @@ -32,7 +32,7 @@ "width":10, "x":0, "y":0 - }, + }, { "data":[0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 128, 128, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "height":10, @@ -43,8 +43,8 @@ { "name":"openWebsite", "type":"string", - "value":"changeTile.html" - }, + "value":"setTiles.html" + }, { "name":"openWebsiteAllowApi", "type":"bool", @@ -55,19 +55,19 @@ "width":10, "x":0, "y":0 - }, + }, { "data":[65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 65, 65, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0], "height":10, "id":8, - "name":"changeTile", + "name":"setTiles", "opacity":1, "type":"tilelayer", "visible":true, "width":10, "x":0, "y":0 - }, + }, { "draworder":"topdown", "id":5, @@ -124,7 +124,7 @@ "type":"bool", "value":true }] - }, + }, { "id":1, "properties":[ @@ -133,7 +133,7 @@ "type":"bool", "value":true }] - }, + }, { "id":2, "properties":[ @@ -142,7 +142,7 @@ "type":"bool", "value":true }] - }, + }, { "id":3, "properties":[ @@ -151,7 +151,7 @@ "type":"bool", "value":true }] - }, + }, { "id":4, "properties":[ @@ -160,7 +160,7 @@ "type":"bool", "value":true }] - }, + }, { "id":8, "properties":[ @@ -169,7 +169,7 @@ "type":"bool", "value":true }] - }, + }, { "id":9, "properties":[ @@ -178,7 +178,7 @@ "type":"bool", "value":true }] - }, + }, { "id":10, "properties":[ @@ -187,7 +187,7 @@ "type":"bool", "value":true }] - }, + }, { "id":11, "properties":[ @@ -196,7 +196,7 @@ "type":"bool", "value":true }] - }, + }, { "id":12, "properties":[ @@ -205,7 +205,7 @@ "type":"bool", "value":true }] - }, + }, { "id":16, "properties":[ @@ -214,7 +214,7 @@ "type":"bool", "value":true }] - }, + }, { "id":17, "properties":[ @@ -223,7 +223,7 @@ "type":"bool", "value":true }] - }, + }, { "id":18, "properties":[ @@ -232,7 +232,7 @@ "type":"bool", "value":true }] - }, + }, { "id":19, "properties":[ @@ -241,7 +241,7 @@ "type":"bool", "value":true }] - }, + }, { "id":20, "properties":[ @@ -252,7 +252,7 @@ }] }], "tilewidth":32 - }, + }, { "columns":8, "firstgid":65, @@ -273,7 +273,7 @@ "type":"string", "value":"customMenu.json" }] - }, + }, { "id":27, "properties":[ @@ -281,18 +281,18 @@ "name":"jitsiRoom", "type":"string", "value":"TEST" - }, + }, { "name":"jitsiTrigger", "type":"string", "value":"onaction" - }, + }, { "name":"jitsiUrl", "type":"string", "value":"meet.jit.si" }] - }, + }, { "id":34, "properties":[ @@ -300,13 +300,13 @@ "name":"name", "type":"string", "value":"Red" - }, + }, { "name":"openWebsite", "type":"string", "value":"https:\/\/fr.wikipedia.org\/wiki\/Wikip%C3%A9dia:Accueil_principal" }] - }, + }, { "id":40, "properties":[ @@ -315,7 +315,7 @@ "type":"string", "value":"" }] - }, + }, { "id":44, "properties":[ @@ -323,13 +323,13 @@ "name":"collides", "type":"bool", "value":true - }, + }, { "name":"name", "type":"string", "value":"blue" }] - }, + }, { "id":52, "properties":[ diff --git a/maps/tests/index.html b/maps/tests/index.html index 97a3ad07..37458659 100644 --- a/maps/tests/index.html +++ b/maps/tests/index.html @@ -164,10 +164,10 @@ - Success Failure Pending + Success Failure Pending - Test change tiles + Test set tiles From feab5da2ad36d1905ad2cb52b8eea6d29255fbf6 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 28 Jun 2021 15:55:30 +0200 Subject: [PATCH 10/19] Allow a website opened by script to use iframe_api --- docs/maps/api-reference.md | 4 +- front/src/Api/Events/OpenCoWebSiteEvent.ts | 2 + front/src/Api/IframeListener.ts | 2 +- front/src/Api/ScriptUtils.ts | 4 +- front/src/iframe_api.ts | 8 +- maps/tests/Metadata/cowebsiteAllowApi.html | 15 ++++ maps/tests/Metadata/cowebsiteAllowApi.js | 1 + maps/tests/Metadata/cowebsiteAllowApi.json | 98 +++++++++++++++++++++ maps/tests/Metadata/tileset_dungeon.png | Bin 0 -> 9696 bytes 9 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 maps/tests/Metadata/cowebsiteAllowApi.html create mode 100644 maps/tests/Metadata/cowebsiteAllowApi.js create mode 100644 maps/tests/Metadata/cowebsiteAllowApi.json create mode 100644 maps/tests/Metadata/tileset_dungeon.png diff --git a/docs/maps/api-reference.md b/docs/maps/api-reference.md index 9891a88a..49bc9dac 100644 --- a/docs/maps/api-reference.md +++ b/docs/maps/api-reference.md @@ -190,11 +190,11 @@ WA.goToPage('https://www.wikipedia.org/'); ### Opening/closing a web page in an iFrame ``` -openCoWebSite(url: string): void +openCoWebSite(url : string, allowApi: boolean = false, allowPolicy: string = "") : void closeCoWebSite(): void ``` -Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. +Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. `allowApi` allow the webpage to use the "IFrame API" and execute script. `allowPolicy` grant additional access rights to the webpage. Example: diff --git a/front/src/Api/Events/OpenCoWebSiteEvent.ts b/front/src/Api/Events/OpenCoWebSiteEvent.ts index 0fbc0ce2..d2937405 100644 --- a/front/src/Api/Events/OpenCoWebSiteEvent.ts +++ b/front/src/Api/Events/OpenCoWebSiteEvent.ts @@ -5,6 +5,8 @@ import * as tg from "generic-type-guard"; export const isOpenCoWebsite = new tg.IsInterface().withProperties({ url: tg.isString, + allowApi: tg.isBoolean, + allowPolicy: tg.isString, }).get(); /** diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 6c3afa31..47f04aad 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -114,7 +114,7 @@ class IframeListener { this._loadSoundStream.next(payload.data); } else if (payload.type === 'openCoWebSite' && isOpenCoWebsite(payload.data)) { - scriptUtils.openCoWebsite(payload.data.url, foundSrc); + scriptUtils.openCoWebsite(payload.data.url, foundSrc, payload.data.allowApi, payload.data.allowPolicy); } else if (payload.type === 'closeCoWebSite') { diff --git a/front/src/Api/ScriptUtils.ts b/front/src/Api/ScriptUtils.ts index e1c94507..08775e4a 100644 --- a/front/src/Api/ScriptUtils.ts +++ b/front/src/Api/ScriptUtils.ts @@ -11,8 +11,8 @@ class ScriptUtils { } - public openCoWebsite(url: string, base: string) { - coWebsiteManager.loadCoWebsite(url, base); + public openCoWebsite(url: string, base: string, allowApi: boolean, allowPolicy: string) { + coWebsiteManager.loadCoWebsite(url, base, allowApi, allowPolicy); } public closeCoWebSite(){ diff --git a/front/src/iframe_api.ts b/front/src/iframe_api.ts index 17b979df..0264d0a6 100644 --- a/front/src/iframe_api.ts +++ b/front/src/iframe_api.ts @@ -22,7 +22,7 @@ interface WorkAdventureApi { openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[]): Popup; openTab(url : string): void; goToPage(url : string): void; - openCoWebSite(url : string): void; + openCoWebSite(url : string, allowApi: boolean, allowPolicy: string): void; closeCoWebSite(): void; disablePlayerControls(): void; restorePlayerControls(): void; @@ -166,11 +166,13 @@ window.WA = { }, '*'); }, - openCoWebSite(url : string) : void{ + openCoWebSite(url : string, allowApi: boolean = false, allowPolicy: string = "") : void{ window.parent.postMessage({ "type" : 'openCoWebSite', "data" : { - url + url, + allowApi, + allowPolicy, } as OpenCoWebSiteEvent }, '*'); }, diff --git a/maps/tests/Metadata/cowebsiteAllowApi.html b/maps/tests/Metadata/cowebsiteAllowApi.html new file mode 100644 index 00000000..0076b9e4 --- /dev/null +++ b/maps/tests/Metadata/cowebsiteAllowApi.html @@ -0,0 +1,15 @@ + + + + + + + +

Website opened by script.

+ + + \ No newline at end of file diff --git a/maps/tests/Metadata/cowebsiteAllowApi.js b/maps/tests/Metadata/cowebsiteAllowApi.js new file mode 100644 index 00000000..71ba96fa --- /dev/null +++ b/maps/tests/Metadata/cowebsiteAllowApi.js @@ -0,0 +1 @@ +WA.openCoWebSite("cowebsiteAllowApi.html", true, ""); \ No newline at end of file diff --git a/maps/tests/Metadata/cowebsiteAllowApi.json b/maps/tests/Metadata/cowebsiteAllowApi.json new file mode 100644 index 00000000..55ed615f --- /dev/null +++ b/maps/tests/Metadata/cowebsiteAllowApi.json @@ -0,0 +1,98 @@ +{ "compressionlevel":-1, + "height":10, + "infinite":false, + "layers":[ + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":10, + "id":2, + "name":"start", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "data":[33, 34, 34, 34, 34, 34, 34, 34, 34, 35, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 41, 42, 42, 42, 42, 42, 42, 42, 42, 43, 49, 50, 50, 50, 50, 50, 50, 50, 50, 51], + "height":10, + "id":1, + "name":"bottom", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }, + { + "draworder":"topdown", + "id":3, + "name":"floorLayer", + "objects":[ + { + "height":116.5, + "id":1, + "name":"", + "rotation":0, + "text": + { + "text":"Test : \nThe iframe is opened by script.\n\nResult : \nA message is send to the chat.", + "wrap":true + }, + "type":"", + "visible":true, + "width":295.875, + "x":11.8125, + "y":188.5 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 + }, + { + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 0, 0, 0, 16, 16, 16, 0, 0, 16, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 16, 16, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 16, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "height":10, + "id":4, + "name":"mushroom", + "opacity":1, + "type":"tilelayer", + "visible":true, + "width":10, + "x":0, + "y":0 + }], + "nextlayerid":5, + "nextobjectid":2, + "orientation":"orthogonal", + "properties":[ + { + "name":"script", + "type":"string", + "value":"cowebsiteAllowApi.js" + }], + "renderorder":"right-down", + "tiledversion":"1.4.3", + "tileheight":32, + "tilesets":[ + { + "columns":8, + "firstgid":1, + "image":"tileset_dungeon.png", + "imageheight":256, + "imagewidth":256, + "margin":0, + "name":"tileset_dungeon", + "spacing":0, + "tilecount":64, + "tileheight":32, + "tilewidth":32 + }], + "tilewidth":32, + "type":"map", + "version":1.4, + "width":10 +} \ No newline at end of file diff --git a/maps/tests/Metadata/tileset_dungeon.png b/maps/tests/Metadata/tileset_dungeon.png new file mode 100644 index 0000000000000000000000000000000000000000..fcac082c33704b31451bc8a58af5982c06586aa6 GIT binary patch literal 9696 zcmd^l=UWuZ6K>D$!XjZo!9!lwfRd9$Nh_%2ARq#g6p)+|2?B#Cm=Hvg#O084&H}3- zAUT7Gu!=~I0*l1E=lR_)_iwnLdYYDEAx8ADi7y7zt4741y000IJ_3H)zK$J%a z&`?tvbFaJy0N{Ye^=n3cmaD1mJr6$LCZ>-&sKS!B)LD}*xki7NMx46)HOs-=SrwT> zRgixx|6F?w+ens%;LEnXkCM;-)!DyszPMfTNw9-)P0F8!Q|TA3b|# zhqVLyoxd;TeR-{}kX^4)QUB0-hiqdto#qRHQ!-}e%u(IU6->n;kcoB zx%ih_lSx;>nvb4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;~dZ&ONDMg{57q|&r8*0OtexW$pXyyn`~$P62Q101GrH^~O? zcrhLUmLCG6YWLgsRQ&-H4NG#U7n+SeFGWEhGF7UI-_9mk^P6#ul^Nox<%l=}JU%Mr zjvOAMSOHV6574~g^@c7vv&&%i^VOT3{SS4T!Ul@ChHt&mrj%}Fj#J*s3Kt^@`XO>* zK?RLd0xd{F*`HdzWJ+^|8yuWX$Ydr1TD0YyizEOfjV(k1D&N{?d<#ynKSbh z8oA&c%?P_wpq7RrW(7E8>>SxqyuI7TSfx|Pii7SHo|s47 zD40{*-JW@oPb^Abn|^@+O-shz-zX zIIjQx2=K`VcfVtx0{kqAOUgTz`}t&>AjRqxxnFv#^;x!w14?FnCJ*O$2FUV+? zw-PV&!_Dt2DE`UXKJA>GRk(%)?U1@!$Rwk7ICZ&nNPk0aP1DWeAqj&@<>{!!gqE{) zxt_x1Yxh9e^|{8L!XO^>!_)~Uf;_+;PoT$Y&bx=WO8$&qJ4`?!2CXlG`>|g&3_OB-{ejV;9@V(X(C)VY#;gEh!(pY z_NQ+hI1Gej$iguN3K+t5=QOoKN*HKtcsHp}5f)xG$u_}&?0;*d-XpE=1{z;ZK;m9H^;vmx}pM@yVZ(l(V>I{)|%Oe-=|C_X26194I54jKmdZ z7VG|?P>D4i+IgT};Lyk{3u+oe42R@^0mtOl0p+uG(o;VSY)3xng34AP5-{;Skq7@w zpJ3o;jFkP0R|H(3do6_g|Mn#TYu%_;k;a2NYmm@mAPIp5qdyX_PFp@N-#C5*{_8>l z73-xAA+we<&OeUUfyo~5_^*EtOQbMoez2F|sZvmTDAr!l*wT+B@~yX71h`{NdmmWG%weVZQ&Lut1dLCiuPWzhd{O Date: Mon, 28 Jun 2021 16:05:29 +0200 Subject: [PATCH 11/19] Update docs/maps/api-reference.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David NĂ©grier --- docs/maps/api-reference.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/maps/api-reference.md b/docs/maps/api-reference.md index 49bc9dac..e5fc2c48 100644 --- a/docs/maps/api-reference.md +++ b/docs/maps/api-reference.md @@ -194,7 +194,7 @@ openCoWebSite(url : string, allowApi: boolean = false, allowPolicy: string = "") closeCoWebSite(): void ``` -Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. `allowApi` allow the webpage to use the "IFrame API" and execute script. `allowPolicy` grant additional access rights to the webpage. +Opens the webpage at "url" in an iFrame (on the right side of the screen) or close that iFrame. `allowApi` allows the webpage to use the "IFrame API" and execute script (it is equivalent to putting the `openWebsiteAllowApi` property in the map). `allowPolicy` grants additional access rights to the iFrame. The `allowPolicy` parameter is turned into an [`allow` feature policy in the iFrame](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-allow). Example: From 06920a227121597e9bef3bc033827e01ce0b0b16 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 28 Jun 2021 16:13:38 +0200 Subject: [PATCH 12/19] Use dynamic Iframe API --- maps/tests/Metadata/cowebsiteAllowApi.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/maps/tests/Metadata/cowebsiteAllowApi.html b/maps/tests/Metadata/cowebsiteAllowApi.html index 0076b9e4..ded7193e 100644 --- a/maps/tests/Metadata/cowebsiteAllowApi.html +++ b/maps/tests/Metadata/cowebsiteAllowApi.html @@ -1,9 +1,12 @@ - From 65d1e4e76893926b760011fab135e86a07e9347b Mon Sep 17 00:00:00 2001 From: GRL Date: Tue, 29 Jun 2021 09:40:15 +0200 Subject: [PATCH 13/19] Add CHANGELOG and a map for test --- CHANGELOG.md | 8 +++++++- maps/tests/Metadata/cowebsiteAllowApi.html | 4 +++- maps/tests/index.html | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dd2c973..e4b9cf6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -## Version 1.3.9 - in dev +## Version 1.4.2 + +## Updates + +- A script in an iframe opened by another script can use the IFrame API. + +## Version 1.4.0 ### BREAKING CHANGES diff --git a/maps/tests/Metadata/cowebsiteAllowApi.html b/maps/tests/Metadata/cowebsiteAllowApi.html index ded7193e..b9affd75 100644 --- a/maps/tests/Metadata/cowebsiteAllowApi.html +++ b/maps/tests/Metadata/cowebsiteAllowApi.html @@ -12,7 +12,9 @@

Website opened by script.

\ No newline at end of file diff --git a/maps/tests/index.html b/maps/tests/index.html index 9c95c281..b7e88925 100644 --- a/maps/tests/index.html +++ b/maps/tests/index.html @@ -90,6 +90,14 @@
Test the HelpCameraSettingScene + + + Success Failure Pending + + + Test a iframe opened by a script can use Iframe API + +