fix: migrate Dialog.prompt to DialogV2 and fix deprecation warnings

This commit is contained in:
Alexander Minges 2025-07-13 14:18:54 +02:00
parent c1f9db6095
commit 0f464f6081
Signed by: Athemis
GPG key ID: 31FBDEF92DDB162B
3 changed files with 38 additions and 15 deletions

View file

@ -111,6 +111,11 @@ export async function createCheckRoll(checkTargetNumber, options = {}) {
// Ask for additional required data; // Ask for additional required data;
const interactiveRollData = await askForInteractiveRollData(checkTargetNumber, options); const interactiveRollData = await askForInteractiveRollData(checkTargetNumber, options);
// Handle cancelled dialog
if (!interactiveRollData) {
return undefined;
}
const newTargetValue = interactiveRollData.checkTargetNumber ?? checkTargetNumber; const newTargetValue = interactiveRollData.checkTargetNumber ?? checkTargetNumber;
const checkModifier = interactiveRollData.checkModifier ?? 0; const checkModifier = interactiveRollData.checkModifier ?? 0;
/** @type {Partial<DS4CheckFactoryOptions>} */ /** @type {Partial<DS4CheckFactoryOptions>} */
@ -220,6 +225,12 @@ async function askForInteractiveRollData(checkTargetNumber, options = {}, { temp
}).render(true); }).render(true);
}); });
const dialogForm = await dialogPromise; const dialogForm = await dialogPromise;
// Handle cancelled dialog
if (!dialogForm) {
return null;
}
return parseDialogFormData(dialogForm); return parseDialogFormData(dialogForm);
} }
@ -229,6 +240,11 @@ async function askForInteractiveRollData(checkTargetNumber, options = {}, { temp
* @returns {Partial<IntermediateInteractiveRollData>} * @returns {Partial<IntermediateInteractiveRollData>}
*/ */
function parseDialogFormData(formData) { function parseDialogFormData(formData) {
// Handle cancelled dialog
if (!formData) {
return {};
}
const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.value); const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.value);
const chosenCheckModifier = formData["check-modifier"]?.value; const chosenCheckModifier = formData["check-modifier"]?.value;

View file

@ -83,9 +83,9 @@ export class DS4Weapon extends DS4Item {
const { melee, ranged } = { ...DS4.i18n.attackTypes }; const { melee, ranged } = { ...DS4.i18n.attackTypes };
const identifier = `attack-type-selection-${foundry.utils.randomID()}`; const identifier = `attack-type-selection-${foundry.utils.randomID()}`;
return Dialog.prompt({ return foundry.applications.api.DialogV2.prompt({
title: getGame().i18n.localize("DS4.DialogAttackTypeSelection"), window: { title: getGame().i18n.localize("DS4.DialogAttackTypeSelection") },
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", { content: await foundry.applications.handlebars.renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
selects: [ selects: [
{ {
label: getGame().i18n.localize("DS4.AttackType"), label: getGame().i18n.localize("DS4.AttackType"),
@ -94,9 +94,10 @@ export class DS4Weapon extends DS4Item {
}, },
], ],
}), }),
ok: {
label: getGame().i18n.localize("DS4.GenericOkButton"), label: getGame().i18n.localize("DS4.GenericOkButton"),
callback: (html) => { callback: (event, button, dialog) => {
const selectedAttackType = html.find(`#${identifier}`).val(); const selectedAttackType = button.form.elements[identifier].value;
if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") { if (selectedAttackType !== "melee" && selectedAttackType !== "ranged") {
throw new Error( throw new Error(
getGame().i18n.format("DS4.ErrorUnexpectedAttackType", { getGame().i18n.format("DS4.ErrorUnexpectedAttackType", {
@ -107,6 +108,7 @@ export class DS4Weapon extends DS4Item {
} }
return selectedAttackType; return selectedAttackType;
}, },
},
}); });
} }
} }

View file

@ -20,6 +20,11 @@ export function registerForRenderHooks() {
* @param {HTMLElement} element The HTML element representing the HTML of the application. * @param {HTMLElement} element The HTML element representing the HTML of the application.
*/ */
function selectTargetInputOnFocus(app, element) { function selectTargetInputOnFocus(app, element) {
// V13: element is always a plain DOM element
if (!element || typeof element.querySelectorAll !== 'function') {
return;
}
const inputs = element.querySelectorAll("input"); const inputs = element.querySelectorAll("input");
inputs.forEach(input => { inputs.forEach(input => {
input.addEventListener("focus", (ev) => { input.addEventListener("focus", (ev) => {