diff options
Diffstat (limited to 'resources/js/db.js')
-rw-r--r-- | resources/js/db.js | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/resources/js/db.js b/resources/js/db.js index 35ed7bd..6e53b7e 100644 --- a/resources/js/db.js +++ b/resources/js/db.js @@ -4,6 +4,21 @@ * @property {string} monster_slug * @property {string} at_level * @property {string} item + * + * @typedef {Object} DB_NPC + * @property {string} slug + * @property {Object[]} template + * @property {string} template[].sprite_name + * + * @typedef {Object} DB_Story + * @property {number} money + * @property {string} area + * @property {Object<string, DB_StoryCharacter>} characters + * + * @typedef {Object} DB_StoryCharacter + * @property {string} slug + * @property {string[]} text + * @property {Object[]} monsters */ // @@ -64,17 +79,37 @@ const DB = { /** * @typedef {Object} DB_Item * - * @type {Object.<string, DB_Item>} + * @type {Object.<ItemSlug, DB_Item>} */ items: {}, + /** + * @typedef {Object} DB_NPC + * + * @type {Object.<string, DB_NPC>} + */ npcs: {}, + /** + * @typedef {Object} DB_Area + * + * @type {Object.<AreaSlug, DB_Area>} + */ areas: {}, + /** + * @type {Object.<StorySlug, DB_Story>} + */ + story: {}, + + /** + * @typedef {string} DB_Translation + * + * @type {Object.<string, DB_Translation>} + */ translations: {}, - currencies : {}, + currencies: {}, }; async function initializeDB () { @@ -152,7 +187,7 @@ async function fetchStatusEffect (slug) { } /** - * @param {string} slug + * @param {ItemSlug} slug * * @returns {Promise<Item>} */ @@ -167,7 +202,7 @@ async function fetchItem (slug) { /** * @param {string} slug * - * @returns {Promise<Object>} + * @returns {Promise<Npc>} */ async function fetchNpc (slug) { if (! DB.npcs[slug]) { @@ -178,9 +213,22 @@ async function fetchNpc (slug) { } /** + * @param {StorySlug} slug + * + * @returns {Promise<DB_Story>} + */ +async function fetchStory (slug) { + if (! DB.story[slug]) { + DB.story[slug] = await fetchDBData(`/db/story/${slug}.json`).then((response) => response.json()); + } + + return DB.story[slug]; +} + +/** * @param {string} locale * - * @returns {Promise<Object>} + * @returns {Promise<DB_Translation>} */ async function fetchTranslation (locale) { if (! DB.translations[locale]) { @@ -191,7 +239,7 @@ async function fetchTranslation (locale) { } /** - * @param {string} slug + * @param {AreaSlug} slug * * @returns {Promise<Area>} */ |