summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-18 16:41:25 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-18 16:41:25 +0200
commit09ee1f7594eb4a3fc9507f05e36bd47cd296e358 (patch)
treefcb660e7435b9ee330fb7071a466b7b4596be0ca
parentd3e65b98ca932aef1e05e33d74eaf62be520cdd4 (diff)
save/load inventory and items
-rw-r--r--resources/js/game.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/resources/js/game.js b/resources/js/game.js
index e383677..1ca9387 100644
--- a/resources/js/game.js
+++ b/resources/js/game.js
@@ -400,9 +400,28 @@ const Game = {
};
/**
+ * @param {InventoryItem} inventoryItemData
+ */
+ const loadInventoryItem = async (inventoryItemData) => {
+ const inventoryItem = new InventoryItem(await fetchItem(inventoryItemData.item.slug));
+
+ inventoryItem.quantity = inventoryItemData.quantity;
+
+ return inventoryItem;
+ };
+
+ /**
* @param {Item} itemData
*/
- const loadItem = async (itemData) => {};
+ const loadItem = async (itemData) => {
+ if (!itemData) {
+ return null;
+ }
+
+ const item = await fetchItem(itemData.slug);
+
+ return item;
+ };
/**
* @param {StatusEffect} statusEffectData
@@ -435,7 +454,7 @@ const Game = {
state.money = loadedState.money;
state.monsters = await Promise.all(loadedState.monsters.map(async (monsterData) => await loadMonster(monsterData)));
- state.inventory = await Promise.all(loadedState.inventory.map(async (itemData) => await loadItem(itemData)));
+ state.inventory = await Promise.all(loadedState.inventory.map(async (itemData) => await loadInventoryItem(itemData)));
state.partyMonsters = await Promise.all(loadedState.partyMonsters.map(async (monsterData) => await loadMonster(monsterData)));
state.activeMonster = state.partyMonsters[loadedState.activeMonsterIdx];
state.activeTechnique = await loadTechnique(loadedState.activeTechnique);