summaryrefslogtreecommitdiff
path: root/resources/js/db.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-19 15:32:48 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-19 15:32:48 +0200
commitc1fe94a630a88c4f7203d54f34985c109030791c (patch)
treee6e75fe468dddddcbe440cbd356ddaaaf605144f /resources/js/db.js
parent218da95a4b387ee5ac25f168d1529419039f2e54 (diff)
translations
Diffstat (limited to 'resources/js/db.js')
-rw-r--r--resources/js/db.js78
1 files changed, 77 insertions, 1 deletions
diff --git a/resources/js/db.js b/resources/js/db.js
index 64b2e9b..648c54c 100644
--- a/resources/js/db.js
+++ b/resources/js/db.js
@@ -1,13 +1,74 @@
+/**
+ * @typedef {Object} DB_Evolution
+ * @property {string} path
+ * @property {string} monster_slug
+ * @property {string} at_level
+ * @property {string} item
+ */
+
+//
+
const DB = {
+ /**
+ * @type {string[]}
+ */
allMonsters: [],
+
+ /**
+ * @typedef {Object.<string, string[]>} DB_Animation
+ *
+ * @type {DB_Animation}
+ */
allAnimations: {},
+
+ /**
+ * @type {string[]}
+ */
allItems: [],
+
+ /**
+ * @typedef {Object} DB_Monster
+ *
+ * @type {Object.<MonsterSlug, DB_Monster>}
+ */
monsters: {},
+
+ /**
+ * @typedef {Object} DB_Shape
+ *
+ * @type {Object.<string, DB_Shape>}
+ */
shapes: {},
+
+ /**
+ * @typedef {Object} DB_Element
+ *
+ * @type {Object.<ElementType, DB_Element>}
+ */
elements: {},
+
+ /**
+ * @typedef {Object} DB_Technique
+ *
+ * @type {Object.<TechniqueSlug, DB_Technique>}
+ */
techniques: {},
+
+ /**
+ * @typedef {Object} DB_StatusEffect
+ *
+ * @type {Object.<string, DB_StatusEffect>}
+ */
statusEffects: {},
+
+ /**
+ * @typedef {Object} DB_Item
+ *
+ * @type {Object.<string, DB_Item>}
+ */
items: {},
+
+ translations: {},
};
async function initializeDB () {
@@ -20,6 +81,8 @@ async function initializeDB () {
for (const element of Object.keys(ElementType)) {
DB.elements[element] = await fetch(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json());
}
+
+ await fetchTranslation(Memory.state.language);
}
/**
@@ -67,7 +130,7 @@ async function fetchStatusEffect (slug) {
/**
* @param {string} slug
*
- * @returns {Promise<StatusEffect>}
+ * @returns {Promise<Item>}
*/
async function fetchItem (slug) {
if (! DB.items[slug]) {
@@ -76,3 +139,16 @@ async function fetchItem (slug) {
return new Item(slug);
}
+
+/**
+ * @param {string} locale
+ *
+ * @returns {Promise<Object>}
+ */
+async function fetchTranslation (locale) {
+ if (! DB.translations[locale]) {
+ DB.translations[locale] = await fetch(`/db/i18n/${locale}.json`).then((response) => response.json());
+ }
+
+ return DB.translations[locale];
+}