feat: add method to handle form changes for items and effects

This commit is contained in:
Alexander Minges 2025-07-12 21:39:34 +02:00
parent c363295e0f
commit 76a0df49e8
Signed by: Athemis
GPG key ID: 31FBDEF92DDB162B

View file

@ -43,6 +43,7 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
editeffect: DS4ActorSheet.prototype._onEditEffect,
deleteeffect: DS4ActorSheet.prototype._onDeleteEffect,
createeffect: DS4ActorSheet.prototype._onCreateEffect,
},
};
@ -197,6 +198,25 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
return submitData;
}
/** @override */
async _onChangeForm(formConfig, event) {
const target = event.target;
// Handle embedded document changes (items and effects)
if (target.dataset.action === "changeItem") {
await this._onChangeItem(event, target);
return; // Don't call super to avoid double updates
}
if (target.dataset.action === "changeEffect") {
await this._onChangeEffect(event, target);
return; // Don't call super to avoid double updates
}
// Let the default form handling process other changes
return super._onChangeForm(formConfig, event);
}
/**
* Parse a value from a form field
* @param {string} value - The value to parse
@ -324,6 +344,7 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
}
}
/**
* Handle changing an item property
* @param {Event} event - The triggering event
@ -403,30 +424,6 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
await effect.sheet.render(true);
}
}
/**
* Handle deleting an effect
* @param {Event} event - The triggering event
* @param {HTMLElement} target - The target element
*/
async _onDeleteEffect(event, target) {
const effectId = target.closest("[data-effect-id]")?.dataset.effectId;
if (!effectId) return;
const effect = this.document.effects.get(effectId);
if (!effect) return;
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("DS4.UserInteractionDeleteEffectTitle") },
content: game.i18n.format("DS4.UserInteractionDeleteEffectContent", { effect: effect.name }),
defaultYes: false,
});
if (confirmed) {
await effect.delete();
}
}
/**
* Handle changing an effect property
* @param {Event} event - The triggering event
@ -456,6 +453,31 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 {
await effect.update({ [property]: value });
}
/**
* Handle deleting an effect
* @param {Event} event - The triggering event
* @param {HTMLElement} target - The target element
*/
async _onDeleteEffect(event, target) {
const effectId = target.closest("[data-effect-id]")?.dataset.effectId;
if (!effectId) return;
const effect = this.document.effects.get(effectId);
if (!effect) return;
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("DS4.UserInteractionDeleteEffectTitle") },
content: game.i18n.format("DS4.UserInteractionDeleteEffectContent", { effect: effect.name }),
defaultYes: false,
});
if (confirmed) {
await effect.delete();
}
}
/**
* Handle sorting items
* @param {Event} event - The triggering event