81 lines
3.6 KiB
TypeScript
81 lines
3.6 KiB
TypeScript
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 GameMapPropertiesListener {
|
|
constructor(private scene: GameScene, private gameMap: GameMap) {}
|
|
|
|
register() {
|
|
this.gameMap.onPropertyChange("openTab", (newValue, oldvalue, allProps) => {
|
|
if (newValue === undefined) {
|
|
layoutManagerActionStore.removeAction("openTab");
|
|
}
|
|
if (typeof newValue == "string" && newValue.length) {
|
|
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 in new tab";
|
|
}
|
|
layoutManagerActionStore.addAction({
|
|
uuid: "openTab",
|
|
type: "message",
|
|
message: message,
|
|
callback: () => scriptUtils.openTab(newValue),
|
|
userInputManager: this.scene.userInputManager,
|
|
});
|
|
} else {
|
|
scriptUtils.openTab(newValue);
|
|
}
|
|
}
|
|
});
|
|
this.gameMap.onPropertyChange("openWebsite", (newValue, oldValue, allProps) => {
|
|
const handler = async () => {
|
|
if (newValue === undefined || newValue !== oldValue) {
|
|
layoutManagerActionStore.removeAction("openWebsite");
|
|
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();
|
|
});
|
|
}
|
|
}
|