Tile-triggered URLs
authorRuben Rodriguez <ruben@gnu.org>
Wed, 10 Mar 2021 21:37:29 +0000 (16:37 -0500)
committerRuben Rodriguez <ruben@gnu.org>
Wed, 10 Mar 2021 21:37:29 +0000 (16:37 -0500)
front/src/Phaser/Game/GameScene.ts

index 245b2f32db1555c000061024065ee70a1d041489..2b553a4d263447a54df0fcb06db1b0605f5a72d6 100644 (file)
@@ -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) => {