Skip to content

Commit

Permalink
Fixed custom categories not being applied on items when populating me…
Browse files Browse the repository at this point in the history
…rchants
  • Loading branch information
Haxxer committed Mar 3, 2024
1 parent 43abd16 commit b55cddb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed compatibility with Better Rolltables
- Fixed vault styles not being editable
- Fixed merchant activity log events being incorrectly displayed
- Fixed custom categories not being applied on items when populating merchants

## Version 2.8.20

Expand Down
23 changes: 12 additions & 11 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ export function getCurrenciesAbbreviations() {
let primaryAbbreviationsArray = game.itempiles.API.CURRENCIES
.filter(currency => currency.abbreviation)
.map(currency => {
if(currency.abbreviation?.includes("{#}")) {
if (currency.abbreviation?.includes("{#}")) {
return currency.abbreviation?.replace("{#}", "");
} else {
return currency.abbreviation || "";
Expand All @@ -825,7 +825,7 @@ export function getCurrenciesAbbreviations() {
let secondaryAbbreviationsArray = game.itempiles.API.SECONDARY_CURRENCIES
.filter(currency => currency.abbreviation)
.map(currency => {
if(currency.abbreviation?.includes("{#}")) {
if (currency.abbreviation?.includes("{#}")) {
return currency.abbreviation?.replace("{#}", "");
} else {
return currency.abbreviation || "";
Expand Down Expand Up @@ -858,10 +858,10 @@ export function getStringFromCurrencies(currencies) {
if (price.percent && abbreviation.includes("%")) {
abbreviation = abbreviation.replaceAll("%", "")
}
if(abbreviation.includes("{#}")) {
if (abbreviation.includes("{#}")) {
return abbreviation.replace("{#}", price.cost)
} else {
return price.cost+abbreviation;
return price.cost + abbreviation;
}
}).join(" ");

Expand Down Expand Up @@ -2040,6 +2040,7 @@ export async function rollMerchantTables({ tableData = false, actor = false } =
}

let tableItems = [];
const customCategory = table?.customCategory ?? false;

if (table.addAll) {

Expand All @@ -2052,7 +2053,7 @@ export async function rollMerchantTables({ tableData = false, actor = false } =
const subTable = await getTable(rollResult);
items.push(...(await rollMerchantTables({
tableData: [{
uuid: subTable.uuid, addAll: false, timesToRoll: roll.total, customCategory: table.customCategory
uuid: subTable.uuid, addAll: false, timesToRoll: roll.total, customCategory: customCategory
}], actor
})))
continue;
Expand All @@ -2061,7 +2062,7 @@ export async function rollMerchantTables({ tableData = false, actor = false } =
if (!item) continue;
const quantity = roll.total * Math.max(Utilities.getItemQuantity(item), 1);
tableItems.push({
...rollResult, customCategory: table.customCategory, item, quantity
...rollResult, customCategory: customCategory, item, quantity
})
}

Expand All @@ -2074,12 +2075,12 @@ export async function rollMerchantTables({ tableData = false, actor = false } =
}

tableItems = await rollTable({
tableUuid: table.uuid, formula: roll.total
tableUuid: table.uuid, formula: roll.total, customCategory: customCategory
})

tableItems.forEach(item => {
if (table.customCategory) {
setProperty(item, CONSTANTS.FLAGS.CUSTOM_CATEGORY, table.customCategory);
if (table?.customCategory) {
setProperty(item, CONSTANTS.FLAGS.CUSTOM_CATEGORY, table?.customCategory);
}
});

Expand All @@ -2094,8 +2095,8 @@ export async function rollMerchantTables({ tableData = false, actor = false } =
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));
}
if (newItem.customCategory) {
setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, newItem.customCategory);
if (newItem?.customCategory) {
setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, newItem?.customCategory);
}
items.push({
...newItem, quantity: newItem.quantity
Expand Down

0 comments on commit b55cddb

Please sign in to comment.