nordeck-workadventure

git clone git://archive.git.mtrnord.blog/MTRNord/nordeck-workadventure.git
Log | Files | Refs | README

main.ts (1086B)


      1 /// <reference types="@workadventure/iframe-api-typings" />
      2 
      3 import { bootstrapExtra } from "@workadventure/scripting-api-extra";
      4 
      5 console.log('Script started successfully');
      6 
      7 let currentPopup: any = undefined;
      8 
      9 // Waiting for the API to be ready
     10 WA.onInit().then(() => {
     11     console.log('Scripting API ready');
     12     console.log('Player tags: ',WA.player.tags)
     13 
     14     WA.room.area.onEnter('clock').subscribe(() => {
     15         const today = new Date();
     16         const time = today.getHours() + ":" + today.getMinutes();
     17         currentPopup = WA.ui.openPopup("clockPopup", "It's " + time, []);
     18     })
     19 
     20     WA.room.area.onLeave('clock').subscribe(closePopup)
     21 
     22     // The line below bootstraps the Scripting API Extra library that adds a number of advanced properties/features to WorkAdventure
     23     bootstrapExtra().then(() => {
     24         console.log('Scripting API Extra ready');
     25     }).catch(e => console.error(e));
     26 
     27 }).catch(e => console.error(e));
     28 
     29 function closePopup(){
     30     if (currentPopup !== undefined) {
     31         currentPopup.close();
     32         currentPopup = undefined;
     33     }
     34 }
     35 
     36 export {};