/** * @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.} DB_Animation * * @type {DB_Animation} */ allAnimations: {}, /** * @type {string[]} */ allItems: [], /** * @typedef {Object} DB_Monster * * @type {Object.} */ monsters: {}, /** * @typedef {Object} DB_Shape * * @type {Object.} */ shapes: {}, /** * @typedef {Object} DB_Element * * @type {Object.} */ elements: {}, /** * @typedef {Object} DB_Technique * * @type {Object.} */ techniques: {}, /** * @typedef {Object} DB_StatusEffect * * @type {Object.} */ statusEffects: {}, /** * @typedef {Object} DB_Item * * @type {Object.} */ items: {}, areas: {}, translations: {}, currencies : {}, }; async function initializeDB () { DB.allMonsters = await fetch('/db/_generated/all-monsters.json').then((response) => response.json()); DB.allAnimations = await fetch('/db/_generated/animations.json').then((response) => response.json()); DB.allItems = await fetch('/db/_generated/all-items.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()); } await fetchTranslation(Memory.state.Settings.language); applyTranslation(); DB.currencies = await fetch('/db/_generated/currencies.json').then((response) => response.json()); } /** * @param {MonsterSlug} slug * * @returns {Promise} */ 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} */ 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} */ 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); } /** * @param {string} slug * * @returns {Promise} */ async function fetchItem (slug) { if (! DB.items[slug]) { DB.items[slug] = await fetch(`/modules/tuxemon/mods/tuxemon/db/item/${slug}.json`).then((response) => response.json()); } return new Item(slug); } /** * @param {string} locale * * @returns {Promise} */ async function fetchTranslation (locale) { if (! DB.translations[locale]) { DB.translations[locale] = await fetch(`/db/_generated/i18n/${locale}.json`).then((response) => response.json()); } return DB.translations[locale]; } /** * @param {string} slug * * @returns {Promise} */ async function fetchArea (slug) { if (Memory.state.areaProgress[slug]) { return Memory.state.areaProgress[slug]; } if (! DB.areas[slug]) { DB.areas[slug] = await fetch(`/db/_generated/areas/${slug}.json`).then((response) => response.json()); } const area = new Area(slug); return area; }