diff --git a/front/src/Phaser/Game/GameMapPropertyChange.ts b/front/src/Phaser/Game/GameMapPropertyChange.ts new file mode 100644 index 00000000..929b94c8 --- /dev/null +++ b/front/src/Phaser/Game/GameMapPropertyChange.ts @@ -0,0 +1,56 @@ +import type { GameScene } from "./GameScene"; +import type { GameMap } from "./GameMap"; +import { scriptUtils } from "../../Api/ScriptUtils"; +import { coWebsiteManager } from "../../WebRtc/CoWebsiteManager"; +import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore"; +import { + ON_ACTION_TRIGGER_BUTTON, + TRIGGER_WEBSITE_PROPERTIES, + WEBSITE_MESSAGE_PROPERTIES, +} from "../../WebRtc/LayoutManager"; + +export class GameMapPropertyChange { + constructor(private scene: GameScene, private gameMap: GameMap) {} + + register() { + this.gameMap.onPropertyChange("openTab", (newValue) => { + if (typeof newValue == "string" && newValue.length) { + scriptUtils.openTab(newValue); + } + }); + + this.gameMap.onPropertyChange("openWebsite", (newValue, oldValue, allProps) => { + if (newValue === undefined) { + layoutManagerActionStore.removeAction("openWebsite"); + coWebsiteManager.closeCoWebsite(); + } else { + const openWebsiteFunction = () => { + coWebsiteManager.loadCoWebsite( + newValue as string, + this.scene.MapUrlFile, + allProps.get("openWebsiteAllowApi") as boolean | undefined, + allProps.get("openWebsitePolicy") as string | undefined + ); + layoutManagerActionStore.removeAction("openWebsite"); + }; + + const openWebsiteTriggerValue = allProps.get(TRIGGER_WEBSITE_PROPERTIES); + if (openWebsiteTriggerValue && openWebsiteTriggerValue === ON_ACTION_TRIGGER_BUTTON) { + let message = allProps.get(WEBSITE_MESSAGE_PROPERTIES); + if (message === undefined) { + message = "Press SPACE or touch here to open web site"; + } + layoutManagerActionStore.addAction({ + uuid: "openWebsite", + type: "message", + message: message, + callback: () => openWebsiteFunction(), + userInputManager: this.scene.userInputManager, + }); + } else { + openWebsiteFunction(); + } + } + }); + } +} diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 7ba97175..9ab097c5 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -92,6 +92,7 @@ import Tileset = Phaser.Tilemaps.Tileset; import { userIsAdminStore } from "../../Stores/GameStore"; import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore"; import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager"; +import { GameMapPropertyChange } from "./GameMapPropertyChange"; export interface GameSceneInitInterface { initPosition: PointInterface | null; @@ -580,6 +581,7 @@ export class GameScene extends DirtyScene { this.updateCameraOffset(box) ); + new GameMapPropertyChange(this, this.gameMap).register(); this.triggerOnMapLayerPropertyChange(); if (!this.room.isDisconnected()) { @@ -825,39 +827,7 @@ export class GameScene extends DirtyScene { }, 2000); } }); - this.gameMap.onPropertyChange("openWebsite", (newValue, oldValue, allProps) => { - if (newValue === undefined) { - layoutManagerActionStore.removeAction("openWebsite"); - coWebsiteManager.closeCoWebsite(); - } else { - const openWebsiteFunction = () => { - coWebsiteManager.loadCoWebsite( - newValue as string, - this.MapUrlFile, - allProps.get("openWebsiteAllowApi") as boolean | undefined, - allProps.get("openWebsitePolicy") as string | undefined - ); - layoutManagerActionStore.removeAction("openWebsite"); - }; - const openWebsiteTriggerValue = allProps.get(TRIGGER_WEBSITE_PROPERTIES); - if (openWebsiteTriggerValue && openWebsiteTriggerValue === ON_ACTION_TRIGGER_BUTTON) { - let message = allProps.get(WEBSITE_MESSAGE_PROPERTIES); - if (message === undefined) { - message = "Press SPACE or touch here to open web site"; - } - layoutManagerActionStore.addAction({ - uuid: "openWebsite", - type: "message", - message: message, - callback: () => openWebsiteFunction(), - userInputManager: this.userInputManager, - }); - } else { - openWebsiteFunction(); - } - } - }); this.gameMap.onPropertyChange("jitsiRoom", (newValue, oldValue, allProps) => { if (newValue === undefined) { layoutManagerActionStore.removeAction("jitsi");