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] 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