{"version":3,"file":"names.min.js","sources":["https:\/\/moodle.sonsbeekmedia.nl\/caie_39\/mod\/teachingtools\/amd\/src\/names\/names.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 * Default input for the games.\n *\n * @module mod_teachingtools\/names\/names\n * @class Names\n * @copyright 2023 Sonsbeekmedia\n * @author Bas Brands \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nexport default class Names {\n names = [];\n observers = [];\n\n constructor(names) {\n this.names = names || [];\n }\n\n add(name) {\n \/\/ Check if the name is an comma separated list.\n if (name instanceof Array) {\n name.forEach((n) => {\n this.names.push(n);\n });\n } else if (name instanceof Object) {\n this.names.push(name);\n } else if (name.includes(',')) {\n name.split(',').forEach(splitName => {\n this.names.push(splitName);\n });\n } else {\n this.names.push(name);\n }\n this.updateListeners();\n }\n\n save(i, name) {\n this.names[i] = name;\n }\n\n update(i, name) {\n this.names[i] = name;\n this.updateListeners();\n }\n\n remove(i) {\n this.names.splice(i, 1);\n this.updateListeners(this.names);\n }\n\n addObserver(observer) {\n this.observers.push(observer);\n if (this.names && this.names.length !== 0) {\n this.updateListeners();\n }\n }\n\n updateListeners() {\n this.observers.forEach((obs) => {\n if (obs.update !== undefined && typeof obs.update === 'function') {\n obs.update(this.names);\n }\n });\n }\n\n resetGame() {\n let gameReset = false;\n this.observers.forEach((obs) => {\n \/\/ If the observer has a reset function, call it.\n if (obs.reset !== undefined && typeof obs.reset === 'function') {\n obs.reset();\n gameReset = true;\n }\n });\n return gameReset;\n }\n\n shuffle() {\n const shuffledNames = this.names;\n for (let i = shuffledNames.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [shuffledNames[i], shuffledNames[j]] = [shuffledNames[j], shuffledNames[i]];\n }\n return shuffledNames;\n }\n}"],"names":["constructor","names","add","name","Array","forEach","n","push","Object","includes","split","splitName","updateListeners","save","i","update","remove","splice","this","addObserver","observer","observers","length","obs","undefined","resetGame","gameReset","reset","shuffle","shuffledNames","j","Math","floor","random"],"mappings":";;;;;;;;;mHA6BIA,YAAYC,oCAHJ,qCACI,SAGHA,MAAQA,OAAS,GAG1BC,IAAIC,MAEIA,gBAAgBC,MAChBD,KAAKE,SAASC,SACLL,MAAMM,KAAKD,MAEbH,gBAAgBK,YAClBP,MAAMM,KAAKJ,MACTA,KAAKM,SAAS,KACrBN,KAAKO,MAAM,KAAKL,SAAQM,iBACfV,MAAMM,KAAKI,mBAGfV,MAAMM,KAAKJ,WAEfS,kBAGTC,KAAKC,EAAGX,WACCF,MAAMa,GAAKX,KAGpBY,OAAOD,EAAGX,WACDF,MAAMa,GAAKX,UACXS,kBAGTI,OAAOF,QACEb,MAAMgB,OAAOH,EAAG,QAChBF,gBAAgBM,KAAKjB,OAG9BkB,YAAYC,eACHC,UAAUd,KAAKa,UAChBF,KAAKjB,OAA+B,IAAtBiB,KAAKjB,MAAMqB,aACpBV,kBAIbA,uBACSS,UAAUhB,SAASkB,WACDC,IAAfD,IAAIR,QAA8C,mBAAfQ,IAAIR,QACvCQ,IAAIR,OAAOG,KAAKjB,UAK5BwB,gBACQC,WAAY,cACXL,UAAUhB,SAASkB,WAEFC,IAAdD,IAAII,OAA4C,mBAAdJ,IAAII,QACtCJ,IAAII,QACJD,WAAY,MAGbA,UAGXE,gBACUC,cAAgBX,KAAKjB,UACtB,IAAIa,EAAIe,cAAcP,OAAS,EAAGR,EAAI,EAAGA,IAAK,OACzCgB,EAAIC,KAAKC,MAAMD,KAAKE,UAAYnB,EAAI,KACzCe,cAAcf,GAAIe,cAAcC,IAAM,CAACD,cAAcC,GAAID,cAAcf,WAErEe"}