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

View file

@ -30,7 +30,7 @@ export function enforce(value, message) {
* @returns {Canvas}
*/
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;
}