diff --git a/front/src/Phaser/Game/GameMapPropertiesListener.ts b/front/src/Phaser/Game/GameMapPropertiesListener.ts index 950e1ebc..29084d2a 100644 --- a/front/src/Phaser/Game/GameMapPropertiesListener.ts +++ b/front/src/Phaser/Game/GameMapPropertiesListener.ts @@ -37,37 +37,44 @@ export class GameMapPropertiesListener { } }); 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, - allProps.get("openWebsiteWidth") as number | undefined - ); + const handler = async () => { + if (newValue === undefined || newValue !== oldValue) { 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(); + await coWebsiteManager.closeCoWebsites(); } - } + + if (newValue !== undefined) { + const openWebsiteFunction = () => { + coWebsiteManager.loadCoWebsite( + newValue as string, + this.scene.MapUrlFile, + allProps.get("openWebsiteAllowApi") as boolean | undefined, + allProps.get("openWebsitePolicy") as string | undefined, + allProps.get("openWebsiteWidth") as number | 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(); + } + } + }; + + handler(); }); } }