34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
let tokens = [];
|
|
if (canvas.tokens.controlled.length > 0) {
|
|
tokens = canvas.tokens.controlled;
|
|
}
|
|
if (tokens.length > 0) {
|
|
main(tokens);
|
|
} else {
|
|
ui.notifications.error('Please select or target a token');
|
|
}
|
|
|
|
async function main(tokens) {
|
|
const currencies = ['Copper', 'Silver', 'Gold', 'Platinum'];
|
|
let template = '<div><table><thead><tr><th>Actor</th><th>Currency</th></tr></thead><tbody>';
|
|
const fmtOptions = {
|
|
minimumIntegerDigits: 1,
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2,
|
|
};
|
|
const fmt = Intl.NumberFormat('en-US', fmtOptions);
|
|
for (const token of tokens) {
|
|
const actor = token.actor;
|
|
let total = 0;
|
|
for (const item of actor.items.filter((i) => currencies.indexOf(i.name) > -1)) {
|
|
total += item.system.price * item.system.quantity;
|
|
}
|
|
template += `<tr><td>${actor.name}</td><td>${fmt.format(total)}</td></tr>`;
|
|
}
|
|
template += '</thead></tbody>';
|
|
foundry.applications.api.DialogV2.prompt({
|
|
window: { title: 'Currency Totals' },
|
|
content: template,
|
|
});
|
|
}
|