From 823ffa6274b61660aad0e19823d4eb4cc1f46015 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Wed, 10 Mar 2021 16:37:29 -0500 Subject: [PATCH] Tile-triggered URLs --- front/src/Phaser/Game/GameScene.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 245b2f3..2b553a4 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -42,6 +42,7 @@ export class GameScene extends Phaser.Scene { circleTexture: CanvasTexture; private initPosition: PositionInterface|null = null; private playersPositionInterpolator = new PlayersPositionInterpolator(); + active: boolean; MapKey: string; MapUrlFile: string; @@ -134,6 +135,7 @@ export class GameScene extends Phaser.Scene { //hook create scene create(): void { //initalise map + this.active = false; this.Map = this.add.tilemap(this.MapKey); this.mapFile.tilesets.forEach((tileset: ITiledTileSet) => { this.Terrains.push(this.Map.addTilesetImage(tileset.name, tileset.name)); @@ -448,6 +450,32 @@ export class GameScene extends Phaser.Scene { this.currentTick = time; this.CurrentPlayer.moveUser(delta); + // get tile under currentUser center position, on layer name "override" + let tile = this.Map.getTileAt(this.Map.worldToTileX(this.CurrentPlayer.x), this.Map.worldToTileY(this.CurrentPlayer.y), true, "override"); + if (tile !== null){ + let active = (tile.index > 0); + if (this.active != active){ + + let url = tile.properties["url"]; + let say = tile.properties["say"]; + + if (url === undefined){ + url="https://play.testansible.fsf.org/resources/welcomepage/index.html"; + this.active = false; + document.getElementById("webRtc").style.pointerEvents="none"; + }else{ + document.getElementById("webRtc").style.pointerEvents="all"; + } + + if (say !== undefined){ + this.CurrentPlayer.say(say) + }; + + document.getElementById("theiframe").src = url; + this.active = active; + } + } + // Let's move all users let updatedPlayersPositions = this.playersPositionInterpolator.getUpdatedPositions(time); updatedPlayersPositions.forEach((moveEvent: HasMovedEvent, userId: string) => { -- 2.25.1