From 6b3a8aef783368d0ed9a2c104eea3ff5cf9984da Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 1 Sep 2023 21:40:11 +0200 Subject: story as json in db --- resources/js/db.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'resources/js/db.js') 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} 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.} + * @type {Object.} */ items: {}, + /** + * @typedef {Object} DB_NPC + * + * @type {Object.} + */ npcs: {}, + /** + * @typedef {Object} DB_Area + * + * @type {Object.} + */ areas: {}, + /** + * @type {Object.} + */ + story: {}, + + /** + * @typedef {string} DB_Translation + * + * @type {Object.} + */ translations: {}, - currencies : {}, + currencies: {}, }; async function initializeDB () { @@ -152,7 +187,7 @@ async function fetchStatusEffect (slug) { } /** - * @param {string} slug + * @param {ItemSlug} slug * * @returns {Promise} */ @@ -167,7 +202,7 @@ async function fetchItem (slug) { /** * @param {string} slug * - * @returns {Promise} + * @returns {Promise} */ async function fetchNpc (slug) { if (! DB.npcs[slug]) { @@ -177,10 +212,23 @@ async function fetchNpc (slug) { return new Npc(slug); } +/** + * @param {StorySlug} slug + * + * @returns {Promise} + */ +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} + * @returns {Promise} */ async function fetchTranslation (locale) { if (! DB.translations[locale]) { @@ -191,7 +239,7 @@ async function fetchTranslation (locale) { } /** - * @param {string} slug + * @param {AreaSlug} slug * * @returns {Promise} */ -- cgit v1.2.3