diff --git a/docs/api.md b/docs/api.md index ad8e87da..ac556692 100644 --- a/docs/api.md +++ b/docs/api.md @@ -889,6 +889,9 @@ game.itempiles.API.updateCurrencies(tokenOrActor, "10gp"); // Set the value on the GP currency with the quantity 10 and on the SP currency with the quantity 5 to the target game.itempiles.API.updateCurrencies(tokenOrActor, "10gp 5sp"); +// Set the value on the GP currency with the quantity 1d4 and on the SP currency with the quantity 1d3 to the target +game.itempiles.API.updateCurrencies(actor, "1d4gp 1d3sp") + ``` --- @@ -918,7 +921,10 @@ const tokenOrActor = game.actors.getName("Bharash"); game.itempiles.API.addCurrencies(tokenOrActor, "10gp"); // Add 10 GP and 5 SP to the target -game.itempiles.API.removeCurrencies(tokenOrActor, "10gp 5sp"); +game.itempiles.API.addCurrencies(tokenOrActor, "10gp 5sp"); + +// Add 1d4 GP to the target +game.itempiles.API.addCurrencies(tokenOrActor, "1d4gp"); ``` @@ -952,6 +958,9 @@ game.itempiles.API.removeCurrencies(tokenOrActor, "10gp"); // Remove 10 GP and 5 SP from the target game.itempiles.API.removeCurrencies(tokenOrActor, "10gp 5sp"); +// Remove 1d4 GP from the target +game.itempiles.API.removeCurrencies(tokenOrActor, "1d4gp"); + ``` --- diff --git a/src/API/api.js b/src/API/api.js index c532e071..bd6bc442 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -1724,6 +1724,9 @@ class API { if (typeof currency.cost !== "number") { throw Helpers.custom_error("getStringFromCurrencies | currency.cost must be of type number"); } + if (currency.cost < 0) { + throw Helpers.custom_error("getStringFromCurrencies | currency.cost cannot be a negative number"); + } // Is optional // if (typeof currency.percent !== "boolean") { // throw Helpers.custom_error("getStringFromCurrencies | currency.percent must be of type boolean"); diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index cebf7379..8e5deb1d 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -791,12 +791,20 @@ export function getCurrenciesAbbreviations() { let primaryAbbreviationsArray = game.itempiles.API.CURRENCIES .filter(currency => currency.abbreviation) .map(currency => { - return currency.abbreviation?.replace("{#}", ""); + if(currency.abbreviation?.includes("{#}")) { + return currency.abbreviation?.replace("{#}", ""); + } else { + return currency.abbreviation || ""; + } }); let secondaryAbbreviationsArray = game.itempiles.API.SECONDARY_CURRENCIES .filter(currency => currency.abbreviation) .map(currency => { - return currency.abbreviation?.replace("{#}", ""); + if(currency.abbreviation?.includes("{#}")) { + return currency.abbreviation?.replace("{#}", ""); + } else { + return currency.abbreviation || ""; + } }); let allAbbreviationsArray = primaryAbbreviationsArray.concat(secondaryAbbreviationsArray); return allAbbreviationsArray; @@ -811,7 +819,7 @@ export function getStringFromCurrencies(currencies) { let cost = price.cost; let abbreviation = price.abbreviation; if (!Helpers.isRealNumber(cost) || !abbreviation) { - Helpers.custom_error(`getStringFromCurrencies | The currency element is not valid with cost '${cost}' and abbreviation '${abbreviation}'`, false); + Helpers.custom_error(`getStringFromCurrencies | The currency element is not valid with cost '${cost}' and abbreviation '${abbreviation}'`, true); return ""; } // Check abbreviation by case unsensitive... @@ -819,13 +827,17 @@ export function getStringFromCurrencies(currencies) { return a?.replace("{#}", "")?.toLowerCase() === abbreviation?.replace("{#}", "")?.toLowerCase(); }); if (indexAbbreviation === -1) { - Helpers.custom_error(`getStringFromCurrencies | The currency abbreviation '${abbreviation?.replace("{#}", "")}' is not registered`, false); + Helpers.custom_error(`getStringFromCurrencies | The currency abbreviation '${abbreviation?.replace("{#}", "")}' is not registered`, true); return ""; } if (price.percent && abbreviation.includes("%")) { abbreviation = abbreviation.replaceAll("%", "") } - return abbreviation.replace("{#}", price.cost) + if(abbreviation.includes("{#}")) { + return abbreviation.replace("{#}", price.cost) + } else { + return price.cost+abbreviation; + } }).join(" "); return priceString ? priceString.trim() : "";