feat: update Dialog implementation to use DialogV2

This commit is contained in:
Alexander Minges 2025-07-13 14:27:46 +02:00
parent 0f464f6081
commit 27f40b1d96
Signed by: Athemis
GPG key ID: 31FBDEF92DDB162B
2 changed files with 34 additions and 32 deletions

View file

@ -463,9 +463,9 @@ export class DS4Actor extends Actor {
async selectAttributeAndTrait() { async selectAttributeAndTrait() {
const attributeIdentifier = "attribute-trait-selection-attribute"; const attributeIdentifier = "attribute-trait-selection-attribute";
const traitIdentifier = "attribute-trait-selection-trait"; const traitIdentifier = "attribute-trait-selection-trait";
return Dialog.prompt({ return foundry.applications.api.DialogV2.prompt({
title: getGame().i18n.localize("DS4.DialogAttributeTraitSelection"), window: { title: getGame().i18n.localize("DS4.DialogAttributeTraitSelection") },
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.Attribute"), label: getGame().i18n.localize("DS4.Attribute"),
@ -489,9 +489,10 @@ export class DS4Actor extends Actor {
}, },
], ],
}), }),
ok: {
label: getGame().i18n.localize("DS4.GenericOkButton"), label: getGame().i18n.localize("DS4.GenericOkButton"),
callback: (html) => { callback: (event, button, dialog) => {
const selectedAttribute = html.find(`#${attributeIdentifier}`).val(); const selectedAttribute = button.form.elements[attributeIdentifier].value;
if (!isAttribute(selectedAttribute)) { if (!isAttribute(selectedAttribute)) {
throw new Error( throw new Error(
getGame().i18n.format("DS4.ErrorUnexpectedAttribute", { getGame().i18n.format("DS4.ErrorUnexpectedAttribute", {
@ -502,7 +503,7 @@ export class DS4Actor extends Actor {
}), }),
); );
} }
const selectedTrait = html.find(`#${traitIdentifier}`).val(); const selectedTrait = button.form.elements[traitIdentifier].value;
if (!isTrait(selectedTrait)) { if (!isTrait(selectedTrait)) {
throw new Error( throw new Error(
getGame().i18n.format("DS4.ErrorUnexpectedTrait", { getGame().i18n.format("DS4.ErrorUnexpectedTrait", {
@ -518,6 +519,7 @@ export class DS4Actor extends Actor {
trait: selectedTrait, trait: selectedTrait,
}; };
}, },
},
rejectClose: false, rejectClose: false,
}); });
} }

View file

@ -30,7 +30,7 @@ export function enforce(value, message) {
* @returns {Canvas} * @returns {Canvas}
*/ */
export function getCanvas() { export function getCanvas() {
enforce(canvas instanceof Canvas && canvas.ready, getGame().i18n.localize("DS4.ErrorCanvasIsNotInitialized")); enforce(canvas instanceof foundry.canvas.Canvas && canvas.ready, getGame().i18n.localize("DS4.ErrorCanvasIsNotInitialized"));
return canvas; return canvas;
} }