summaryrefslogtreecommitdiff
path: root/resources/js/db.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-17 02:53:14 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-17 17:42:15 +0200
commitcc685bfe02b42b592987117fa008a4461785f53c (patch)
tree625c1c9573b178e574bb70cac042c35da4036cf1 /resources/js/db.js
parent717fde1c48c7221da986ac02d2b806b2fee6f2d5 (diff)
refactorrefactor
Diffstat (limited to 'resources/js/db.js')
-rw-r--r--resources/js/db.js62
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);
+}