macro cleanup DialogV2
This commit is contained in:
+20
-20
@@ -1,33 +1,33 @@
|
||||
let tokens = []
|
||||
let tokens = [];
|
||||
if (canvas.tokens.controlled.length > 0) {
|
||||
tokens = canvas.tokens.controlled
|
||||
tokens = canvas.tokens.controlled;
|
||||
}
|
||||
if (tokens.length > 0) {
|
||||
main(tokens)
|
||||
main(tokens);
|
||||
} else {
|
||||
ui.notifications.error('Please select or target a token')
|
||||
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>'
|
||||
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)
|
||||
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
|
||||
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 += `<tr><td>${actor.name}</td><td>${fmt.format(total)}</td></tr>`;
|
||||
}
|
||||
template += '</thead></tbody>'
|
||||
Dialog.prompt({
|
||||
title: 'Currency Totals',
|
||||
content: template
|
||||
})
|
||||
template += '</thead></tbody>';
|
||||
foundry.applications.api.DialogV2.prompt({
|
||||
window: { title: 'Currency Totals' },
|
||||
content: template,
|
||||
});
|
||||
}
|
||||
|
||||
+23
-19
@@ -1,5 +1,5 @@
|
||||
new Dialog({
|
||||
title: 'Damage Roll Configuration',
|
||||
new foundry.applications.api.DialogV2({
|
||||
window: { title: "Damage Roll Configuration" },
|
||||
content: `
|
||||
<form>
|
||||
<div class="form-group">
|
||||
@@ -16,24 +16,28 @@ new Dialog({
|
||||
</div>
|
||||
</form>
|
||||
`,
|
||||
buttons: {
|
||||
ok: {
|
||||
label: 'Roll Damage',
|
||||
callback: (html) => {
|
||||
const damageRoll = html.find('input[name="damageRoll"]').val()
|
||||
let flavor = html.find('input[name="flavor"]').val()
|
||||
const ap = parseInt(html.find('input[name="ap"]').val()) || 0
|
||||
const options = {}
|
||||
buttons: [
|
||||
{
|
||||
action: "ok",
|
||||
label: "Roll Damage",
|
||||
callback: (event, button, dialog) => {
|
||||
const form = new foundry.applications.ux.FormDataExtended(button.form);
|
||||
console.log(form)
|
||||
const damageRoll = form.object.damageRoll;
|
||||
let flavor = form.object.flavor;
|
||||
const ap = parseInt(form.object.ap) || 0;
|
||||
const options = {};
|
||||
if (ap > 0) {
|
||||
flavor = `${flavor ? flavor + ' - ' : ''}AP: ${ap}`
|
||||
options.ap = ap
|
||||
flavor = `${flavor ? flavor + " - " : ""}AP: ${ap}`
|
||||
options.ap = ap;
|
||||
}
|
||||
// Perform the damage roll and send the message
|
||||
new CONFIG.Dice.DamageRoll(damageRoll, null, options).toMessage({ flavor })
|
||||
}
|
||||
new CONFIG.Dice.DamageRoll(damageRoll, null, options).toMessage({ flavor });
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: 'Cancel'
|
||||
}
|
||||
}
|
||||
}).render(true)
|
||||
{
|
||||
action: "cancel",
|
||||
label: "Cancel",
|
||||
},
|
||||
],
|
||||
}).render(true);
|
||||
|
||||
@@ -10,8 +10,8 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
new Dialog({
|
||||
title: 'Request Fear roll...',
|
||||
new foundry.applications.api.DialogV2({
|
||||
window: { title: 'Request Fear roll...' },
|
||||
content: `
|
||||
<form>
|
||||
<p>Requesting Fear roll from ${tokens.map((t) => t.name).join(', ')}.</p>
|
||||
@@ -21,19 +21,21 @@ async function main() {
|
||||
</label>
|
||||
</div>
|
||||
</form>`,
|
||||
buttons: {
|
||||
ok: {
|
||||
buttons: [
|
||||
{
|
||||
action: "submit",
|
||||
label: 'Request Roll',
|
||||
callback: (html) => {
|
||||
const fear = parseInt(html.find('input[name="fear"]').val()) || 0;
|
||||
callback: (event, button, dialog) => {
|
||||
formdata = new foundry.applications.ux.FormDataExtended(button.form).object
|
||||
const fear = parseInt(formdata.fear) || 0;
|
||||
const options = { targetNumber: 4, fear };
|
||||
requestFearRollFromTokens(tokens, options);
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: 'Cancel',
|
||||
{
|
||||
action: "cancel", label: 'Cancel',
|
||||
},
|
||||
},
|
||||
],
|
||||
}).render(true);
|
||||
}
|
||||
|
||||
|
||||
+12
-10
@@ -60,12 +60,14 @@ async function main() {
|
||||
</div>
|
||||
</form>
|
||||
`;
|
||||
const buttons = {
|
||||
ok: {
|
||||
const buttons = [
|
||||
{
|
||||
action: "submit",
|
||||
label: 'Request Roll',
|
||||
callback: (html) => {
|
||||
const form = html[0].querySelector('form');
|
||||
const formDataObject = new FormDataExtended(form).object;
|
||||
callback: (event, button, dialog) => {
|
||||
const form = button.form;
|
||||
const formDataObject = new foundry.applications.ux.FormDataExtended(form).object;
|
||||
console.log(formDataObject);
|
||||
const rollMod = parseInt(formDataObject.mod);
|
||||
const rollModDesc = formDataObject.modDesc;
|
||||
const rollParts = formDataObject.trait.split('|');
|
||||
@@ -79,12 +81,12 @@ async function main() {
|
||||
requestRollFromTokens(tokens, rollType, rollDesc, options);
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: 'Cancel',
|
||||
{
|
||||
action: "cancel", label: 'Cancel',
|
||||
},
|
||||
};
|
||||
new Dialog({
|
||||
title: 'Request roll',
|
||||
];
|
||||
new foundry.applications.api.DialogV2({
|
||||
window { title: 'Request roll' },
|
||||
content,
|
||||
buttons,
|
||||
}).render(true);
|
||||
|
||||
+12
-13
@@ -1,4 +1,3 @@
|
||||
/* globals args */
|
||||
const argBright = typeof args === 'undefined' ? null : args.length > 0 ? args[0] : null;
|
||||
// argument can be one of 'bright', 'dim', 'dark', 'pitchdark'. Other values
|
||||
// will guess based on scene darkness
|
||||
@@ -58,7 +57,7 @@ function findAbility(token, swid) {
|
||||
return token.actor.items.find((i) => i.type === 'ability' && i.system.swid === swid);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
async function main() {
|
||||
const scene = game.scenes.current;
|
||||
let sceneBright = BRIGHT_LEVELS[0];
|
||||
if (scene.darkness > THRESHOLDS.pitchdark) {
|
||||
@@ -73,8 +72,8 @@ async function main() {
|
||||
bright = argBright;
|
||||
}
|
||||
|
||||
new Dialog({
|
||||
title: 'Select scene brightness',
|
||||
new foundry.applications.api.DialogV2({
|
||||
window: { title: 'Select scene brightness' },
|
||||
content: `
|
||||
<form>
|
||||
<h2>Set token vision</h2>
|
||||
@@ -109,14 +108,16 @@ async function main() {
|
||||
</div>
|
||||
</form>
|
||||
`,
|
||||
buttons: {
|
||||
ok: {
|
||||
buttons: [
|
||||
{
|
||||
action: "submit",
|
||||
label: 'Select scene Brightness',
|
||||
value: 'ok',
|
||||
callback: (html) => {
|
||||
const form = html[0].querySelector('form');
|
||||
const formDataObject = new FormDataExtended(form).Object;
|
||||
callback: (event, button, dialog) => {
|
||||
const form = button.form;
|
||||
const formDataObject = new foundry.applications.ux.FormDataExtended(form).object;
|
||||
console.log('form data', formDataObject, form);
|
||||
|
||||
bright = formDataObject.bright;
|
||||
for (const tokenId of scene.tokens.map((t) => t.id)) {
|
||||
const token = scene.tokens.get(tokenId);
|
||||
@@ -147,10 +148,8 @@ async function main() {
|
||||
}
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
label: 'Cancel',
|
||||
},
|
||||
},
|
||||
{ action: "cancel", label: 'Cancel' },
|
||||
],
|
||||
}).render(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user