Skip to content

Commit

Permalink
Merge pull request #574 from fantasycalendar/Fixed_custom_categories
Browse files Browse the repository at this point in the history
Fixed categories
  • Loading branch information
Haxxer authored May 19, 2024
2 parents 9442a9a + 9b6e5ae commit c2d5a72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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!)
Expand Down
41 changes: 23 additions & 18 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
});
}
})
Expand Down Expand Up @@ -2158,4 +2163,4 @@ async function getItem(itemToGet) {
}
}
return item;
}
}

0 comments on commit c2d5a72

Please sign in to comment.