diff --git a/src/dice/check-factory.js b/src/dice/check-factory.js index b76469e7..d5a64c10 100644 --- a/src/dice/check-factory.js +++ b/src/dice/check-factory.js @@ -111,6 +111,11 @@ export async function createCheckRoll(checkTargetNumber, options = {}) { // Ask for additional required data; const interactiveRollData = await askForInteractiveRollData(checkTargetNumber, options); + // Handle cancelled dialog + if (!interactiveRollData) { + return undefined; + } + const newTargetValue = interactiveRollData.checkTargetNumber ?? checkTargetNumber; const checkModifier = interactiveRollData.checkModifier ?? 0; /** @type {Partial} */ @@ -220,6 +225,12 @@ async function askForInteractiveRollData(checkTargetNumber, options = {}, { temp }).render(true); }); const dialogForm = await dialogPromise; + + // Handle cancelled dialog + if (!dialogForm) { + return null; + } + return parseDialogFormData(dialogForm); } @@ -229,6 +240,11 @@ async function askForInteractiveRollData(checkTargetNumber, options = {}, { temp * @returns {Partial} */ function parseDialogFormData(formData) { + // Handle cancelled dialog + if (!formData) { + return {}; + } + const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.value); const chosenCheckModifier = formData["check-modifier"]?.value; diff --git a/src/documents/item/weapon/weapon.js b/src/documents/item/weapon/weapon.js index 09a734d0..9bcbbdbd 100644 --- a/src/documents/item/weapon/weapon.js +++ b/src/documents/item/weapon/weapon.js @@ -83,9 +83,9 @@ export class DS4Weapon extends DS4Item { const { melee, ranged } = { ...DS4.i18n.attackTypes }; const identifier = `attack-type-selection-${foundry.utils.randomID()}`; - return Dialog.prompt({ - title: getGame().i18n.localize("DS4.DialogAttackTypeSelection"), - content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { + return foundry.applications.api.DialogV2.prompt({ + window: { title: getGame().i18n.localize("DS4.DialogAttackTypeSelection") }, + content: await foundry.applications.handlebars.renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { selects: [ { label: getGame().i18n.localize("DS4.AttackType"), @@ -94,18 +94,20 @@ export class DS4Weapon extends DS4Item { }, ], }), - label: getGame().i18n.localize("DS4.GenericOkButton"), - callback: (html) => { - const selectedAttackType = html.find(`#${identifier}`).val(); - if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") { - throw new Error( - getGame().i18n.format("DS4.ErrorUnexpectedAttackType", { - actualType: selectedAttackType, - expectedTypes: "'melee', 'ranged'", - }), - ); - } - return selectedAttackType; + ok: { + label: getGame().i18n.localize("DS4.GenericOkButton"), + callback: (event, button, dialog) => { + const selectedAttackType = button.form.elements[identifier].value; + if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") { + throw new Error( + getGame().i18n.format("DS4.ErrorUnexpectedAttackType", { + actualType: selectedAttackType, + expectedTypes: "'melee', 'ranged'", + }), + ); + } + return selectedAttackType; + }, }, }); } diff --git a/src/hooks/render.js b/src/hooks/render.js index 1714f6d5..1c8c580a 100644 --- a/src/hooks/render.js +++ b/src/hooks/render.js @@ -20,6 +20,11 @@ export function registerForRenderHooks() { * @param {HTMLElement} element The HTML element representing the HTML of the application. */ function selectTargetInputOnFocus(app, element) { + // V13: element is always a plain DOM element + if (!element || typeof element.querySelectorAll !== 'function') { + return; + } + const inputs = element.querySelectorAll("input"); inputs.forEach(input => { input.addEventListener("focus", (ev) => {