diff options
Diffstat (limited to 'resources/js/db.js')
-rw-r--r-- | resources/js/db.js | 78 |
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]; +} |