{"version":3,"file":"game_engine.min.js","sources":["https:\/\/moodle.sonsbeekmedia.nl\/caie_test\/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.token = this.rootElement.dataset.token;\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 if (this.token) {\n await this.sync.loadToken(this.token);\n } else {\n await this.storeConfig.getStoredNames();\n }\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","token","dataset","error","fontLoaded","Promise","resolve","fonts","ready","then","catch","err","window","console","log","reason","alert","setError","getFeedData","loadToken","getStoredNames","nameList","NameListElement","backGroundElement","BackGroundElement","registerObservers","addObserver","run","game","configButton","namesInput","length","click","dispatchEvent","Event","gameready"],"mappings":";;;;;;;;;yeAyCIA,YAAYC,IAAKC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