From 9b6e5aef4b2fd145461d6d381eb896af3a4f8ffe Mon Sep 17 00:00:00 2001 From: Haxxer Date: Sat, 18 May 2024 22:28:02 +0100 Subject: [PATCH] Fixed categories --- changelog.md | 4 ++++ src/helpers/pile-utilities.js | 41 ++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index ba74159f..f61f93bd 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Item Piles Changelog +## Version 2.9.2 + +- Fixed rolltables not applying custom categories to items properly + ## Version 2.9.1 - Added support for the Shadowdark system (thank you mrstarbuck007 on github!) diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index afe58785..87147bd8 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -1967,10 +1967,10 @@ export async function rollTable({ const brtOptions = { rollsAmount: roll.total, roll: undefined, - displayChat: displayChat, + displayChat: displayChat, recursive: true } - results = (await game.modules.get("better-rolltables").api.roll(table,brtOptions)).itemsData.map(result => ({ + results = (await game.modules.get("better-rolltables").api.roll(table, brtOptions)).itemsData.map(result => ({ documentCollection: result.documentCollection, documentId: result.documentId, text: result.text || result.name, @@ -2019,12 +2019,14 @@ export async function rollTable({ if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { - setProperty(newItem, CONSTANTS.FLAGS.ITEM, getProperty(newItem.item, CONSTANTS.FLAGS.ITEM)); - if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { - setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); - } + const flags = getProperty(newItem.item, CONSTANTS.FLAGS.ITEM) ?? {}; if (customCategory) { setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, customCategory); + setProperty(flags, "customCategory", customCategory); + } + setProperty(newItem, CONSTANTS.FLAGS.ITEM, flags); + if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { + setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); } items.push({ ...newItem @@ -2108,24 +2110,27 @@ export async function rollMerchantTables({ tableData = false, actor = false } = tableItems.forEach(newItem => { const existingItem = items.find((item) => { - if (item.documentId && newItem.documentId) { - return item.documentId === newItem.documentId; - } else { - return item._id === newItem._id; - } - }); + if (item.documentId && newItem.documentId) { + return item.documentId === newItem.documentId; + } else { + return item._id === newItem._id; + } + }); if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { - setProperty(newItem, CONSTANTS.FLAGS.ITEM, cleanItemFlagData(getProperty(newItem.item, CONSTANTS.FLAGS.ITEM) ?? {})); - if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { - setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); - } + const flags = cleanItemFlagData(getProperty(newItem.item, CONSTANTS.FLAGS.ITEM) ?? {}); if (newItem?.customCategory) { setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, newItem?.customCategory); + setProperty(flags, "customCategory", newItem?.customCategory); + } + setProperty(newItem, CONSTANTS.FLAGS.ITEM, flags); + if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { + setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); } items.push({ - ...newItem, quantity: newItem.quantity + ...newItem, + quantity: newItem.quantity }); } }) @@ -2158,4 +2163,4 @@ async function getItem(itemToGet) { } } return item; -} \ No newline at end of file +}