feat: add method to handle form changes for items and effects
This commit is contained in:
parent
c363295e0f
commit
76a0df49e8
1 changed files with 46 additions and 24 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue