Skip to content

Commit

Permalink
add some double check
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Mar 2, 2024
1 parent 1e72550 commit c4844a6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -811,15 +819,15 @@ 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...
const indexAbbreviation = allAbbreviationsArray.findIndex(a => {
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("%")) {
Expand Down

0 comments on commit c4844a6

Please sign in to comment.