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;
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<DS4CheckFactoryOptions>} */
@ -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<IntermediateInteractiveRollData>}
*/
function parseDialogFormData(formData) {
// Handle cancelled dialog
if (!formData) {
return {};
}
const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.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 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;
},
},
});
}

View file

@ -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) => {