From 801975cc66b1ac8d9eba5d10e3bd229a6014a8cf Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 20 Oct 2023 22:04:54 +0100 Subject: [PATCH] fixed shit --- changelog.md | 4 ++++ src/helpers/compendium-utilities.js | 17 ++++++++++++++++- src/helpers/pile-utilities.js | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 239ad04b..084291b8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Item Piles Changelog +## Version 2.7.20 Hotfix + +- Fixed item based currencies breaking AGAIN + ## Version 2.7.19 - Added support for the Star Wars FFG system (thanks Grumpkin on the Foundry discord server!) diff --git a/src/helpers/compendium-utilities.js b/src/helpers/compendium-utilities.js index 8cdf74a6..23a6bb4b 100644 --- a/src/helpers/compendium-utilities.js +++ b/src/helpers/compendium-utilities.js @@ -1,3 +1,6 @@ +import SETTINGS from "../constants/settings.js"; +import { getSetting } from "./helpers.js"; + const PACK_ID = `world.item-piles-item-backup-do-not-delete`; const COMPENDIUM_CACHE = {}; @@ -17,6 +20,19 @@ export async function initializeCompendiumCache() { } } + Hooks.on("updateCompendium", updateCache); + + updateCache(); + +} + +async function updateCache() { + const currencies = getSetting(SETTINGS.CURRENCIES); + const secondaryCurrencies = getSetting(SETTINGS.SECONDARY_CURRENCIES); + for (const currency of currencies.concat(secondaryCurrencies)) { + if (!currency.data?.uuid) continue; + COMPENDIUM_CACHE[currency.data?.uuid] = (await fromUuid(currency.data.uuid)).toObject(); + } } export async function getItemCompendium() { @@ -42,7 +58,6 @@ export async function findSimilarItemInCompendium(itemToFind) { } export function getItemFromCache(uuid) { - if (!game.packs.get(PACK_ID)) return false; return COMPENDIUM_CACHE[uuid] ?? false; } diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index a975652b..9b4ba99c 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -230,7 +230,7 @@ export function getActorCurrencies(target, { item, index } - })) + })).filter(Boolean); cachedActorCurrencies.set(actorUuid, currencies);