This commit is contained in:
_Bastler 2022-01-26 12:44:08 +01:00
parent 31f6847b53
commit e3b58a0d56
23 changed files with 131 additions and 94 deletions

View File

@ -6,7 +6,8 @@ export const isButtonClickedEvent = new tg.IsInterface()
buttonId: tg.isNumber, buttonId: tg.isNumber,
input: tg.isBoolean, input: tg.isBoolean,
inputValue: tg.isString, inputValue: tg.isString,
}).get(); })
.get();
/** /**
* A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property. * A message sent from the game to the iFrame when a user enters or leaves a zone marked with the "zone" property.
*/ */

View File

@ -4,7 +4,8 @@ export const isClosePopupEvent = new tg.IsInterface()
.withProperties({ .withProperties({
popupId: tg.isNumber, popupId: tg.isNumber,
inputValue: tg.isString, inputValue: tg.isString,
}).get(); })
.get();
/** /**
* A message sent from the iFrame to the game to add a message in the chat. * A message sent from the iFrame to the game to add a message in the chat.

View File

@ -14,8 +14,9 @@ export const isOpenPopupEvent = new tg.IsInterface()
message: tg.isString, message: tg.isString,
buttons: tg.isArray(isButtonDescriptor), buttons: tg.isArray(isButtonDescriptor),
popupClass: tg.isString, popupClass: tg.isString,
input: tg.isBoolean input: tg.isBoolean,
}).get(); })
.get();
/** /**
* A message sent from the iFrame to the game to add a message in the chat. * A message sent from the iFrame to the game to add a message in the chat.

View File

@ -283,7 +283,7 @@ class IframeListener {
unregisterIframe(iframe: HTMLIFrameElement): void { unregisterIframe(iframe: HTMLIFrameElement): void {
this._unregisterIFrameStream.next(); this._unregisterIFrameStream.next();
this.iframeCloseCallbacks.get(iframe)?.forEach(callback => { this.iframeCloseCallbacks.get(iframe)?.forEach((callback) => {
callback(); callback();
}); });
this.iframes.delete(iframe); this.iframes.delete(iframe);
@ -486,7 +486,7 @@ class IframeListener {
buttonId, buttonId,
input, input,
inputValue, inputValue,
} as ButtonClickedEvent } as ButtonClickedEvent,
}); });
} }

View File

@ -2,11 +2,10 @@ import { sendToWorkadventure } from "../IframeApiContribution";
import type { ClosePopupEvent } from "../../Events/ClosePopupEvent"; import type { ClosePopupEvent } from "../../Events/ClosePopupEvent";
export class Popup { export class Popup {
inputValue: string; inputValue: string;
constructor(private id: number) { constructor(private id: number) {
this.inputValue = ''; this.inputValue = "";
} }
/** /**
@ -14,11 +13,11 @@ export class Popup {
*/ */
public close(): void { public close(): void {
sendToWorkadventure({ sendToWorkadventure({
'type': 'closePopup', type: "closePopup",
'data': { data: {
'popupId': this.id, popupId: this.id,
'inputValue': this.inputValue, inputValue: this.inputValue,
} as ClosePopupEvent } as ClosePopupEvent,
}); });
} }
} }

View File

@ -132,11 +132,12 @@ export class WorkadventureRoomCommands extends IframeApiContribution<Workadventu
async getProperty(layerName: string, propertyName: string): Promise<string | number | boolean | undefined> { async getProperty(layerName: string, propertyName: string): Promise<string | number | boolean | undefined> {
const event = await queryWorkadventure({ const event = await queryWorkadventure({
type: "getProperty", data: { type: "getProperty",
data: {
layerName: layerName, layerName: layerName,
propertyName: propertyName, propertyName: propertyName,
propertyValue: undefined, propertyValue: undefined,
} },
}); });
return event.propertyValue; return event.propertyValue;
} }

View File

@ -85,7 +85,13 @@ export class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventure
}), }),
]; ];
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], popupClass : string = "", input: boolean = false): Popup { openPopup(
targetObject: string,
message: string,
buttons: ButtonDescriptor[],
popupClass: string = "",
input: boolean = false
): Popup {
popupId++; popupId++;
const popup = new Popup(popupId); const popup = new Popup(popupId);
const btnMap = new Map<number, () => void>(); const btnMap = new Map<number, () => void>();
@ -114,7 +120,7 @@ export class WorkAdventureUiCommands extends IframeApiContribution<WorkAdventure
}; };
}), }),
popupClass, popupClass,
input input,
}, },
}); });

View File

@ -360,7 +360,6 @@ class ConnectionManager {
} }
async getWorlds() { async getWorlds() {
const token = localUserStore.getAuthToken(); const token = localUserStore.getAuthToken();
if (!token) { if (!token) {
throw new Error("No token provided"); throw new Error("No token provided");
@ -368,8 +367,7 @@ class ConnectionManager {
const { worlds } = await Axios.get(`${PUSHER_URL}/worlds`, { params: { token } }).then((res) => { const { worlds } = await Axios.get(`${PUSHER_URL}/worlds`, { params: { token } }).then((res) => {
return res.data; return res.data;
} });
);
return worlds; return worlds;
} }

View File

@ -167,7 +167,7 @@ export class Room {
//const match = /@\/([^/]+)\/([^/]+)\/.+/.exec(this.id); //const match = /@\/([^/]+)\/([^/]+)\/.+/.exec(this.id);
//if (!match) throw new Error('Could not extract instance from "' + this.id + '"'); //if (!match) throw new Error('Could not extract instance from "' + this.id + '"');
//this.instance = match[1] + "/" + match[2]; //this.instance = match[1] + "/" + match[2];
this.instance = "" this.instance = "";
return this.instance; return this.instance;
} }
} }

View File

@ -182,7 +182,7 @@ export const HAIR_RESOURCES: BodyResourceDescriptionListInterface = {
hair_72: { name: "hair_72", img: "resources/customisation/character_hairs/character_hairs71.png" }, hair_72: { name: "hair_72", img: "resources/customisation/character_hairs/character_hairs71.png" },
hair_73: { name: "hair_73", img: "resources/customisation/character_hairs/character_hairs72.png" }, hair_73: { name: "hair_73", img: "resources/customisation/character_hairs/character_hairs72.png" },
hair_74: { name: "hair_74", img: "resources/customisation/character_hairs/character_hairs73.png" }, hair_74: { name: "hair_74", img: "resources/customisation/character_hairs/character_hairs73.png" },
hair_75: { name: "hair_75", img: "resources/customisation/character_hairs/character_hairs74.png" } hair_75: { name: "hair_75", img: "resources/customisation/character_hairs/character_hairs74.png" },
}; };
export const CLOTHES_RESOURCES: BodyResourceDescriptionListInterface = { export const CLOTHES_RESOURCES: BodyResourceDescriptionListInterface = {

View File

@ -255,10 +255,7 @@ export class GameMap {
} }
} }
public getLayerProperty( public getLayerProperty(layerName: string, propertyName: string): string | number | undefined | boolean {
layerName: string,
propertyName: string
) : string | number | undefined | boolean {
const layer = this.findLayer(layerName); const layer = this.findLayer(layerName);
if (layer === undefined) { if (layer === undefined) {
console.warn('Could not find layer "' + layerName + '" when calling setProperty'); console.warn('Could not find layer "' + layerName + '" when calling setProperty');

View File

@ -161,17 +161,26 @@ export class GameMapPropertiesListener {
callback: () => openWebsiteFunction(), callback: () => openWebsiteFunction(),
userInputManager: this.scene.userInputManager, userInputManager: this.scene.userInputManager,
}); });
} };
this.coWebsitesIframeListeners.set(layer, iframeListener.unregisterIFrameStream.subscribe(() => { this.coWebsitesIframeListeners.set(
layer,
iframeListener.unregisterIFrameStream.subscribe(() => {
const coWebsiteOpen = this.coWebsitesOpenByLayer.get(layer); const coWebsiteOpen = this.coWebsitesOpenByLayer.get(layer);
if (coWebsiteOpen?.coWebsite?.state == CoWebsiteState.CLOSED && (!websiteTriggerProperty || websiteTriggerProperty !== ON_ACTION_TRIGGER_DISABLE)) { if (
coWebsiteOpen?.coWebsite?.state == CoWebsiteState.CLOSED &&
(!websiteTriggerProperty || websiteTriggerProperty !== ON_ACTION_TRIGGER_DISABLE)
) {
createWebsiteTrigger(); createWebsiteTrigger();
} }
})); })
);
const forceTrigger = localUserStore.getForceCowebsiteTrigger(); const forceTrigger = localUserStore.getForceCowebsiteTrigger();
if (forceTrigger || websiteTriggerProperty && websiteTriggerProperty === ON_ACTION_TRIGGER_BUTTON) { if (
forceTrigger ||
(websiteTriggerProperty && websiteTriggerProperty === ON_ACTION_TRIGGER_BUTTON)
) {
createWebsiteTrigger(); createWebsiteTrigger();
} else { } else {
this.coWebsitesOpenByLayer.set(layer, { this.coWebsitesOpenByLayer.set(layer, {
@ -215,7 +224,6 @@ export class GameMapPropertiesListener {
const coWebsiteIframeListener = this.coWebsitesIframeListeners.get(layer); const coWebsiteIframeListener = this.coWebsitesIframeListeners.get(layer);
if (coWebsiteIframeListener) { if (coWebsiteIframeListener) {
coWebsiteIframeListener.unsubscribe(); coWebsiteIframeListener.unsubscribe();
this.coWebsitesIframeListeners.delete(layer); this.coWebsitesIframeListeners.delete(layer);
@ -232,7 +240,10 @@ export class GameMapPropertiesListener {
return; return;
} }
if (coWebsiteOpen.state !== OpenCoWebsiteState.OPENED && coWebsiteOpen.state !== OpenCoWebsiteState.TRIGGER) { if (
coWebsiteOpen.state !== OpenCoWebsiteState.OPENED &&
coWebsiteOpen.state !== OpenCoWebsiteState.TRIGGER
) {
return; return;
} }

View File

@ -1070,7 +1070,7 @@ export class GameScene extends DirtyScene {
let html = `<div id="container" hidden><div class="nes-container with-title is-centered">`; let html = `<div id="container" hidden><div class="nes-container with-title is-centered">`;
html += escapedMessage; html += escapedMessage;
if (openPopupEvent.input) { if (openPopupEvent.input) {
html += `<input id="popupinput-${openPopupEvent.popupId}" class="nes-input" />` html += `<input id="popupinput-${openPopupEvent.popupId}" class="nes-input" />`;
} }
html += `</div>`; html += `</div>`;
@ -1102,11 +1102,18 @@ export class GameScene extends DirtyScene {
); );
const btnId = id; const btnId = id;
button.onclick = () => { button.onclick = () => {
let inputValue = ''; let inputValue = "";
if (openPopupEvent.input) { if (openPopupEvent.input) {
inputValue = HtmlUtils.getElementByIdOrFail<HTMLInputElement>(`popupinput-${openPopupEvent.popupId}`).value; inputValue = HtmlUtils.getElementByIdOrFail<HTMLInputElement>(
`popupinput-${openPopupEvent.popupId}`
).value;
} }
iframeListener.sendButtonClickedEvent(openPopupEvent.popupId, btnId, openPopupEvent.input, inputValue); iframeListener.sendButtonClickedEvent(
openPopupEvent.popupId,
btnId,
openPopupEvent.input,
inputValue
);
// Disable for a short amount of time to let time to the script to remove the popup // Disable for a short amount of time to let time to the script to remove the popup
button.disabled = true; button.disabled = true;
setTimeout(() => { setTimeout(() => {
@ -1370,11 +1377,13 @@ export class GameScene extends DirtyScene {
}) })
); );
this.iframeSubscriptionList.push(iframeListener.setTilesStream.subscribe((eventTiles) => { this.iframeSubscriptionList.push(
iframeListener.setTilesStream.subscribe((eventTiles) => {
for (const eventTile of eventTiles) { for (const eventTile of eventTiles) {
this.gameMap.putTile(eventTile.tile, eventTile.x, eventTile.y, eventTile.layer); this.gameMap.putTile(eventTile.tile, eventTile.x, eventTile.y, eventTile.layer);
} }
})) })
);
iframeListener.registerAnswerer("loadTileset", (eventTileset) => { iframeListener.registerAnswerer("loadTileset", (eventTileset) => {
return this.connectionAnswerPromise.then(() => { return this.connectionAnswerPromise.then(() => {
@ -2191,7 +2200,10 @@ export class GameScene extends DirtyScene {
layoutManagerActionStore.removeAction("jitsi"); layoutManagerActionStore.removeAction("jitsi");
} else { } else {
const openJitsiRoomFunction = () => { const openJitsiRoomFunction = () => {
const roomName = jitsiFactory.getRoomName(allProps.get(GameMapProperties.JITSI_ROOM) as string, this.instance); const roomName = jitsiFactory.getRoomName(
allProps.get(GameMapProperties.JITSI_ROOM) as string,
this.instance
);
const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined; const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined;
if (JITSI_PRIVATE_MODE && !jitsiUrl) { if (JITSI_PRIVATE_MODE && !jitsiUrl) {
const adminTag = allProps.get(GameMapProperties.JITSI_ADMIN_ROOM_TAG) as string | undefined; const adminTag = allProps.get(GameMapProperties.JITSI_ADMIN_ROOM_TAG) as string | undefined;
@ -2201,7 +2213,7 @@ export class GameScene extends DirtyScene {
this.startJitsi(roomName, undefined); this.startJitsi(roomName, undefined);
} }
layoutManagerActionStore.removeAction("jitsi"); layoutManagerActionStore.removeAction("jitsi");
} };
let message = allProps.get(GameMapProperties.JITSI_TRIGGER_MESSAGE); let message = allProps.get(GameMapProperties.JITSI_TRIGGER_MESSAGE);
if (message === undefined) { if (message === undefined) {

View File

@ -53,15 +53,14 @@ export class StartPositionCalculator {
selectedOrDefaultLayer = defaultStartLayerName; selectedOrDefaultLayer = defaultStartLayerName;
} }
selectedOrDefaultLayer = selectedOrDefaultLayer.replace('#',''); selectedOrDefaultLayer = selectedOrDefaultLayer.replace("#", "");
let foundLayer: ITiledMapLayer | null = null; let foundLayer: ITiledMapLayer | null = null;
for (const layer of this.gameMap.flatLayers) { for (const layer of this.gameMap.flatLayers) {
if (layer.type !== "tilelayer") continue; if (layer.type !== "tilelayer") continue;
//we want to prioritize the selectedLayer other the start layer //we want to prioritize the selectedLayer other the start layer
if ( if (
(selectedOrDefaultLayer === layer.name || (selectedOrDefaultLayer === layer.name || layer.name.endsWith("/" + selectedOrDefaultLayer)) &&
layer.name.endsWith("/" + selectedOrDefaultLayer)) &&
layer.type === "tilelayer" && layer.type === "tilelayer" &&
(selectedOrDefaultLayer === defaultStartLayerName || this.isStartLayer(layer)) (selectedOrDefaultLayer === defaultStartLayerName || this.isStartLayer(layer))
) { ) {

View File

@ -1,4 +1,4 @@
const sanitizeHtml = require('sanitize-html'); const sanitizeHtml = require("sanitize-html");
export class HtmlUtils { export class HtmlUtils {
public static getElementByIdOrFail<T extends HTMLElement>(id: string): T { public static getElementByIdOrFail<T extends HTMLElement>(id: string): T {
@ -37,14 +37,14 @@ export class HtmlUtils {
if (typeof html === "string") { if (typeof html === "string") {
return sanitizeHtml(html, { return sanitizeHtml(html, {
allowedAttributes: { allowedAttributes: {
'span': ['style'], span: ["style"],
}, },
allowedStyles: { allowedStyles: {
'span': { span: {
'color': [/^#(0x)?[0-9a-f]+$/i, /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/], color: [/^#(0x)?[0-9a-f]+$/i, /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/],
'font-size': [/^\d+(?:px|em|%)$/] "font-size": [/^\d+(?:px|em|%)$/],
} },
} },
}); });
} }
return ""; return "";

View File

@ -129,7 +129,7 @@ class JitsiFactory {
* Slugifies the room name and prepends the room name with the instance * Slugifies the room name and prepends the room name with the instance
*/ */
public getRoomName(roomName: string, instance: string): string { public getRoomName(roomName: string, instance: string): string {
if (!instance || instance == '') { if (!instance || instance == "") {
return slugify(roomName); return slugify(roomName);
} }
return slugify(instance.replace("/", "-") + "-" + roomName); return slugify(instance.replace("/", "-") + "-" + roomName);

View File

@ -1,7 +1,7 @@
import type { Translation } from "../i18n-types"; import type { Translation } from "../i18n-types";
const emoji: NonNullable<Translation["emoji"]> = { const emoji: NonNullable<Translation["emoji"]> = {
search: "Emojis suchent...", search: "Emojis suchen...",
categories: { categories: {
recents: "Letzte Emojis", recents: "Letzte Emojis",
smileys: "Smileys & Emotionen", smileys: "Smileys & Emotionen",

View File

@ -4,15 +4,18 @@ const error: NonNullable<Translation["error"]> = {
accessLink: { accessLink: {
title: "Ungültiger Zugangslink", title: "Ungültiger Zugangslink",
subTitle: "Karte konnte nicht gefunden werden. Prüfe bitte deinen Zugangslink.", subTitle: "Karte konnte nicht gefunden werden. Prüfe bitte deinen Zugangslink.",
details: "Für weitere Information kannst du die Administratoren kontaktieren oder melde dich bei uns unter: prty@bstly.de", details:
"Für weitere Information kannst du die Administratoren kontaktieren oder melde dich bei uns unter: prty@bstly.de",
}, },
connectionRejected: { connectionRejected: {
title: "Verbindungen zurückgewiesen", title: "Verbindungen zurückgewiesen",
subTitle: "Du kannst diese Welt nicht betreten. Versuche es später noch einmal {error}.", subTitle: "Du kannst diese Welt nicht betreten. Versuche es später noch einmal {error}.",
details: "Für weitere Information kannst du die Administratoren kontaktieren oder melde dich bei uns unter: prty.bstly.de", details:
"Für weitere Information kannst du die Administratoren kontaktieren oder melde dich bei uns unter: prty.bstly.de",
}, },
connectionRetry: { connectionRetry: {
unableConnect: "Es konnte keine Verbindung zu WorkAdventure erstellt werden. Bist du mit dem Internet verbunden?", unableConnect:
"Es konnte keine Verbindung zu WorkAdventure erstellt werden. Bist du mit dem Internet verbunden?",
}, },
error: "Fehler", error: "Fehler",
}; };

View File

@ -90,7 +90,8 @@ const menu: NonNullable<Translation["menu"]> = {
}, },
createMap: { createMap: {
title: "Eigene Karte erstellen ", title: "Eigene Karte erstellen ",
description: "Du kannst auch deine eigene Karte erstellen. Folge dazu unserer Schritt-für-Schritt Anleitung.", description:
"Du kannst auch deine eigene Karte erstellen. Folge dazu unserer Schritt-für-Schritt Anleitung.",
}, },
}, },
about: { about: {

View File

@ -7,7 +7,8 @@ const warning: NonNullable<Translation["warning"]> = {
limit: "Diese Welt erreicht bald die maximale Kapazität!", limit: "Diese Welt erreicht bald die maximale Kapazität!",
accessDenied: { accessDenied: {
camera: "Zugriff auf die Kamera verweigert. Hier klicken um deine Browser Berechtigungen zu prüfen.", camera: "Zugriff auf die Kamera verweigert. Hier klicken um deine Browser Berechtigungen zu prüfen.",
screenSharing: "Zugriff auf die Bildschirmfreigabe verweigert. Hier klicken um deine Browser Berechtigungen zu prüfen.", screenSharing:
"Zugriff auf die Bildschirmfreigabe verweigert. Hier klicken um deine Browser Berechtigungen zu prüfen.",
}, },
importantMessage: "Wichtige Nachricht", importantMessage: "Wichtige Nachricht",
connectionLost: "Verbindungen unterbrochen. Wiederverbinden...", connectionLost: "Verbindungen unterbrochen. Wiederverbinden...",

View File

@ -153,7 +153,13 @@ const wa = {
/** /**
* @deprecated Use WA.ui.openPopup instead * @deprecated Use WA.ui.openPopup instead
*/ */
openPopup(targetObject: string, message: string, buttons: ButtonDescriptor[], popupClass : string, input : boolean): Popup { openPopup(
targetObject: string,
message: string,
buttons: ButtonDescriptor[],
popupClass: string,
input: boolean
): Popup {
console.warn("Method WA.openPopup is deprecated. Please use WA.ui.openPopup instead"); console.warn("Method WA.openPopup is deprecated. Please use WA.ui.openPopup instead");
return ui.openPopup(targetObject, message, buttons, popupClass, input); return ui.openPopup(targetObject, message, buttons, popupClass, input);
}, },