From 9a516f55e9c66f69a0d814918f5700afbe075c1e Mon Sep 17 00:00:00 2001 From: kai Date: Fri, 25 Oct 2024 15:55:46 +0200 Subject: [PATCH] Dateien nach "src" hochladen --- src/README.md | 3 +++ src/main.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/README.md create mode 100644 src/main.ts diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..b1269ad --- /dev/null +++ b/src/README.md @@ -0,0 +1,3 @@ +# WorkAdventure Map Starter Kit - Src Folder + +In this directory you can put your scripts and other source code files. \ No newline at end of file diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..dedc20b --- /dev/null +++ b/src/main.ts @@ -0,0 +1,36 @@ +/// + +import { bootstrapExtra } from "@workadventure/scripting-api-extra"; + +console.log('Script started successfully'); + +let currentPopup: any = undefined; + +// Waiting for the API to be ready +WA.onInit().then(() => { + console.log('Scripting API ready'); + console.log('Player tags: ',WA.player.tags) + + WA.room.area.onEnter('clock').subscribe(() => { + const today = new Date(); + const time = today.getHours() + ":" + today.getMinutes(); + currentPopup = WA.ui.openPopup("clockPopup", "It's " + time, []); + }) + + WA.room.area.onLeave('clock').subscribe(closePopup) + + // The line below bootstraps the Scripting API Extra library that adds a number of advanced properties/features to WorkAdventure + bootstrapExtra().then(() => { + console.log('Scripting API Extra ready'); + }).catch(e => console.error(e)); + +}).catch(e => console.error(e)); + +function closePopup(){ + if (currentPopup !== undefined) { + currentPopup.close(); + currentPopup = undefined; + } +} + +export {};