From 6dcb0d3750f78838ac03f89131bce9132489869c Mon Sep 17 00:00:00 2001 From: GRL Date: Thu, 27 May 2021 17:06:39 +0200 Subject: [PATCH 1/8] 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 a666bf310b59761aaf8902af4c7e41def0597ada Mon Sep 17 00:00:00 2001 From: GRL Date: Thu, 24 Jun 2021 11:31:29 +0200 Subject: [PATCH 2/8] Change Tiles --- CHANGELOG.md | 1 + docs/maps/api-room.md | 23 +++++++++++ front/src/Phaser/Game/GameMap.ts | 13 ++++++ front/src/Phaser/Game/GameScene.ts | 60 +++++++++++++++++---------- maps/tests/Metadata/changeTile.html | 24 +++++------ maps/tests/Metadata/changeTile.json | 64 +++++++++++++++++++++++++++-- 6 files changed, 146 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41f72510..e4bc7ba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +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 ## Version 1.4.1 diff --git a/docs/maps/api-room.md b/docs/maps/api-room.md index d8381cc6..3bb01cc0 100644 --- a/docs/maps/api-room.md +++ b/docs/maps/api-room.md @@ -112,3 +112,26 @@ WA.room.getCurrentUser().then((user) => { } }) ``` + +### Changing tiles +``` +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`. +`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. +* **tile (number | string) :** The id of the tile that will be placed in the map. +* **layer (string) :** The name of the layer where the tile will be placed. + +**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([ + {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'} + ]); +``` \ No newline at end of file diff --git a/front/src/Phaser/Game/GameMap.ts b/front/src/Phaser/Game/GameMap.ts index fba410d9..ab3e6010 100644 --- a/front/src/Phaser/Game/GameMap.ts +++ b/front/src/Phaser/Game/GameMap.ts @@ -130,6 +130,10 @@ export class GameMap { return this.map; } + public getTilesetProperties(): { [tile_index: number]: Array } { + return this.tileSetPropertyMap; + } + private trigger(propName: string, oldValue: string | number | boolean | undefined, newValue: string | number | boolean | undefined, allProps: Map) { const callbacksArray = this.callbacks.get(propName); if (callbacksArray !== undefined) { @@ -165,4 +169,13 @@ export class GameMap { } } + public putTileInFlatLayer(index: number, x: number, y: number, layer: string): void { + const fLayer = this.findLayer(layer); + if (fLayer?.type !== 'tilelayer') { + return; + } + // @ts-ignore + fLayer.data[x+y*fLayer.height] = index; + } + } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 0202773d..8f199c3e 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -958,6 +958,23 @@ ${escapedMessage} tags: this.connection ? this.connection.getAllTags() : [] }) })); + 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); + } + } + } + } + } + })) } @@ -986,18 +1003,21 @@ ${escapedMessage} this.dirty = true; } - private getIndexForTileType(tileType: string): number | null { - 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 - } + 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 } + return null + } private getMapDirUrl(): string { return this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/')); @@ -1205,21 +1225,19 @@ ${escapedMessage} createCollisionWithPlayer() { //add collision layer for (const phaserLayer of this.gameMap.phaserLayers) { - if (phaserLayer.type == "tilelayer") { - this.physics.add.collider(this.CurrentPlayer, phaserLayer, (object1: GameObject, object2: GameObject) => { - //this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name) + this.physics.add.collider(this.CurrentPlayer, phaserLayer, (object1: GameObject, object2: GameObject) => { + //this.CurrentPlayer.say("Collision with layer : "+ (object2 as Tile).layer.name) + }); + phaserLayer.setCollisionByProperty({collides: true}); + if (DEBUG_MODE) { + //debug code to see the collision hitbox of the object in the top layer + phaserLayer.renderDebug(this.add.graphics(), { + tileColor: null, //non-colliding tiles + collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles, + faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges }); - phaserLayer.setCollisionByProperty({collides: true}); - if (DEBUG_MODE) { - //debug code to see the collision hitbox of the object in the top layer - phaserLayer.renderDebug(this.add.graphics(), { - tileColor: null, //non-colliding tiles - collidingTileColor: new Phaser.Display.Color(243, 134, 48, 200), // Colliding tiles, - faceColor: new Phaser.Display.Color(40, 39, 37, 255) // Colliding face edges - }); - } - //}); } + //}); } } diff --git a/maps/tests/Metadata/changeTile.html b/maps/tests/Metadata/changeTile.html index 214908a9..2813aa1d 100644 --- a/maps/tests/Metadata/changeTile.html +++ b/maps/tests/Metadata/changeTile.html @@ -5,22 +5,18 @@ 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 3/8] 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 4/8] 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 5/8] 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 7/8] 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 95bd6391249b8ae366e4792fdb0997d963843d95 Mon Sep 17 00:00:00 2001 From: GRL Date: Tue, 29 Jun 2021 16:50:33 +0200 Subject: [PATCH 8/8] More statement --- front/src/Phaser/Game/GameMap.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/Game/GameMap.ts b/front/src/Phaser/Game/GameMap.ts index aeb4cb62..f68c414a 100644 --- a/front/src/Phaser/Game/GameMap.ts +++ b/front/src/Phaser/Game/GameMap.ts @@ -183,7 +183,10 @@ export class GameMap { console.error("The layer that you want to change is not a tilelayer. Tile can only be put in tilelayer."); return; } - // @ts-ignore + if (typeof fLayer.data === "string") { + console.error("Data of the layer that you want to change is only readable."); + return; + } fLayer.data[x+y*fLayer.height] = index; } @@ -195,7 +198,7 @@ export class GameMap { this.putTileInFlatLayer(tileIndex, x, y, layer); const phaserTile = phaserLayer.putTileAt(tileIndex, x, y); for (const property of this.getTileProperty(tileIndex)) { - if ( property.name === "collides" ) { + if ( property.name === "collides" && property.value === "true") { phaserTile.setCollision(true); } }