diff options
Diffstat (limited to 'resources/js/db.js')
-rw-r--r-- | resources/js/db.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/resources/js/db.js b/resources/js/db.js new file mode 100644 index 0000000..96b971a --- /dev/null +++ b/resources/js/db.js @@ -0,0 +1,62 @@ +const DB = { + allMonsters: [], + allAnimations: {}, + monsters: {}, + shapes: {}, + elements: {}, + techniques: {}, + statusEffects: {}, +}; + +async function initializeDB () { + DB.allMonsters = await fetch('/db/all-monsters.json').then((response) => response.json()); + DB.allAnimations = await fetch('/db/animations.json').then((response) => response.json()); + + DB.shapes = await fetch('/modules/tuxemon/mods/tuxemon/db/shape/shapes.json').then((response) => response.json()); + + for (const element of Object.keys(ElementType)) { + DB.elements[element] = await fetch(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json()); + } +} + +/** + * @param {MonsterSlug} slug + * + * @returns {Promise<Monster>} + */ +async function fetchMonster (slug) { + if (! DB.monsters[slug]) { + DB.monsters[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/monster/${slug}.json`).then((response) => response.json()); + } + + const monster = new Monster(slug); + await monster.initialize(); + + return monster; +} + +/** + * @param {TechniqueSlug} slug + * + * @returns {Promise<Technique>} + */ +async function fetchTechnique (slug) { + if (! DB.techniques[slug]) { + DB.techniques[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/${slug}.json`).then((response) => response.json()); + } + + return new Technique(slug); +} + +/** + * @param {string} slug + * + * @returns {Promise<StatusEffect>} + */ +async function fetchStatusEffect (slug) { + if (! DB.statusEffects[slug]) { + DB.statusEffects[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/technique/status_${slug}.json`).then((response) => response.json()); + } + + return new StatusEffect(slug); +} |