From 09ee1f7594eb4a3fc9507f05e36bd47cd296e358 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Fri, 18 Aug 2023 16:41:25 +0200 Subject: save/load inventory and items --- resources/js/game.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'resources') 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 @@ -399,10 +399,29 @@ const Game = { return monster; }; + /** + * @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); -- cgit v1.2.3