{"version":3,"file":"game_engine.min.js","sources":["https:\/\/moodle.sonsbeekmedia.nl\/caie_39\/mod\/teachingtools\/amd\/src\/game_engine.js"],"sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * The wrapper game engine.\n *\n * @module mod_teachingtools\/game_engine\n * @class GameEngine\n * @copyright 2023 Sonsbeekmedia\n * @author Bas Brands \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport Names from 'mod_teachingtools\/names\/names';\nimport BackGroundElement from 'mod_teachingtools\/names\/background_element';\nimport StoreConfigElement from 'mod_teachingtools\/names\/store_config_element';\nimport NameListElement from 'mod_teachingtools\/names\/name_list_element';\nimport Sync from 'mod_teachingtools\/names\/sync';\nimport ToolSelector from 'mod_teachingtools\/tool_selector';\nimport 'mod_teachingtools\/dragdroptouch';\nimport Notification from 'core\/notification';\nimport {get_string as getString} from 'core\/str';\n\nexport default class GameEngine {\n \/**\n * The game engine.\n * @param {string} app The app name.\n * @param {int} cmid The course module id.\n *\/\n constructor(app, cmid) {\n this.cmid = cmid;\n this.app = app;\n this.rootElement = document.querySelector(`[data-region=\"${app}-${cmid}\"]`);\n this.names = new Names();\n this.sync = new Sync(this.names, this.rootElement, this.app);\n this.storeConfig = new StoreConfigElement(this.names, this.rootElement);\n this.toolSelector = new ToolSelector(this.rootElement, this.app);\n this.error = false;\n }\n\n \/**\n * Check if the font is loaded.\n * @return {Promise} resolve when the font is loaded.\n *\/\n fontLoaded() {\n return new Promise((resolve) => {\n document.fonts.ready.then(() => {\n resolve();\n return '';\n }).catch((err) => {\n window.console.log(err);\n });\n });\n }\n\n \/**\n * Set the error status\n * @param {string} error The error.\n * @return {void}\n *\/\n async setError(error) {\n if (!error) {\n return;\n }\n this.error = error;\n const reason = await getString(error, 'mod_teachingtools');\n\n Notification.alert(this.error, reason);\n }\n\n \/**\n * Setup using the stored names.\n *\/\n async load() {\n if (this.error) {\n return;\n }\n await this.fontLoaded();\n await this.setError(await this.sync.getFeedData());\n await this.storeConfig.getStoredNames();\n this.nameList = new NameListElement(this.names, this.rootElement);\n this.backGroundElement = new BackGroundElement(this.names, this.rootElement);\n this.registerObservers();\n }\n\n \/**\n * Register the observers.\n *\/\n registerObservers() {\n if (this.error) {\n return;\n }\n this.names.addObserver(this.nameList);\n this.names.addObserver(this.sync);\n this.names.addObserver(this.storeConfig);\n this.names.addObserver(this.backGroundElement);\n }\n\n \/**\n * Run the game.\n * @param {object} game The game object.\n *\/\n run(game) {\n if (this.error) {\n return;\n }\n this.names.addObserver(game);\n const configButton = this.rootElement.querySelector('[data-action=\"configurator\"]');\n const namesInput = this.rootElement.querySelector('[data-action=\"names-editor\"]');\n if (this.names.names.length === 0 && configButton && namesInput) {\n configButton.click();\n }\n document.dispatchEvent(new Event('app-ready'));\n this.rootElement.dataset.gameready = true;\n }\n\n}\n"],"names":["constructor","app","cmid","rootElement","document","querySelector","names","Names","sync","Sync","this","storeConfig","StoreConfigElement","toolSelector","ToolSelector","error","fontLoaded","Promise","resolve","fonts","ready","then","catch","err","window","console","log","reason","alert","setError","getFeedData","getStoredNames","nameList","NameListElement","backGroundElement","BackGroundElement","registerObservers","addObserver","run","game","configButton","namesInput","length","click","dispatchEvent","Event","dataset","gameready"],"mappings":";;;;;;;;;yeAyCIA,YAAYC,IAAKC,WACRA,KAAOA,UACPD,IAAMA,SACNE,YAAcC,SAASC,sCAA+BJ,gBAAOC,iBAC7DI,MAAQ,IAAIC,oBACZC,KAAO,IAAIC,cAAKC,KAAKJ,MAAOI,KAAKP,YAAaO,KAAKT,UACnDU,YAAc,IAAIC,8BAAmBF,KAAKJ,MAAOI,KAAKP,kBACtDU,aAAe,IAAIC,uBAAaJ,KAAKP,YAAaO,KAAKT,UACvDc,OAAQ,EAOjBC,oBACW,IAAIC,SAASC,UAChBd,SAASe,MAAMC,MAAMC,MAAK,KACtBH,UACO,MACRI,OAAOC,MACNC,OAAOC,QAAQC,IAAIH,0BAUhBR,WACNA,kBAGAA,MAAQA,YACPY,aAAe,mBAAUZ,MAAO,2CAEzBa,MAAMlB,KAAKK,MAAOY,qBAO3BjB,KAAKK,cAGHL,KAAKM,mBACLN,KAAKmB,eAAenB,KAAKF,KAAKsB,qBAC9BpB,KAAKC,YAAYoB,sBAClBC,SAAW,IAAIC,2BAAgBvB,KAAKJ,MAAOI,KAAKP,kBAChD+B,kBAAoB,IAAIC,4BAAkBzB,KAAKJ,MAAOI,KAAKP,kBAC3DiC,qBAMTA,oBACQ1B,KAAKK,aAGJT,MAAM+B,YAAY3B,KAAKsB,eACvB1B,MAAM+B,YAAY3B,KAAKF,WACvBF,MAAM+B,YAAY3B,KAAKC,kBACvBL,MAAM+B,YAAY3B,KAAKwB,oBAOhCI,IAAIC,SACI7B,KAAKK,kBAGJT,MAAM+B,YAAYE,YACjBC,aAAe9B,KAAKP,YAAYE,cAAc,gCAC9CoC,WAAa\/B,KAAKP,YAAYE,cAAc,gCAClB,IAA5BK,KAAKJ,MAAMA,MAAMoC,QAAgBF,cAAgBC,YACjDD,aAAaG,QAEjBvC,SAASwC,cAAc,IAAIC,MAAM,mBAC5B1C,YAAY2C,QAAQC,WAAY"}