summaryrefslogtreecommitdiff
path: root/resources/js/db.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-09-01 21:40:11 +0200
committerDaniel Weipert <code@drogueronin.de>2023-09-01 21:40:11 +0200
commit6b3a8aef783368d0ed9a2c104eea3ff5cf9984da (patch)
tree7da1f4a6ad2bc0d549579678900eaf9c9a3f572f /resources/js/db.js
parent94cf76f8968cf81a06d70fe329b5edf4ec07f94f (diff)
story as json in db
Diffstat (limited to 'resources/js/db.js')
-rw-r--r--resources/js/db.js60
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>}
*/