FEAT: improvement of DHApplicationMixin

FEAT: create a new DHBaseItemSheet
This commit is contained in:
Joaquin Pereyra 2025-06-23 14:27:27 -03:00
parent 3464717958
commit 8574a1d93f
15 changed files with 381 additions and 162 deletions

View file

@ -1,14 +1,14 @@
import { armorFeatures } from '../../../config/itemConfig.mjs';
import DHBaseItemSheet from '../api/base-item.mjs';
import { tagifyElement } from '../../../helpers/utils.mjs';
import DHItemSheetV2 from '../item.mjs';
const { ItemSheetV2 } = foundry.applications.sheets;
export default class ArmorSheet extends DHItemSheetV2(ItemSheetV2) {
export default class ArmorSheet extends DHBaseItemSheet {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['armor'],
dragDrop: [{ dragSelector: null, dropSelector: null }]
};
/**@override */
static PARTS = {
header: { template: 'systems/daggerheart/templates/sheets/items/armor/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
@ -23,6 +23,7 @@ export default class ArmorSheet extends DHItemSheetV2(ItemSheetV2) {
}
};
/**@inheritdoc */
async _preparePartContext(partId, context) {
super._preparePartContext(partId, context);
@ -35,15 +36,20 @@ export default class ArmorSheet extends DHItemSheetV2(ItemSheetV2) {
return context;
}
/**@inheritdoc */
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
const featureInput = htmlElement.querySelector('.features-input');
tagifyElement(featureInput, armorFeatures, this.onFeatureSelect.bind(this));
tagifyElement(featureInput, CONFIG.daggerheart.ITEM.armorFeatures, ArmorSheet.onFeatureSelect.bind(this));
}
async onFeatureSelect(features) {
await this.document.update({ 'system.features': features.map(x => ({ value: x.value })) });
this.render(true);
/**
* Callback function used by `tagifyElement`.
* @param {Array<Object>} selectedOptions - The currently selected tag objects.
*/
static async onFeatureSelect(selectedOptions ) {
await this.document.update({ 'system.features': selectedOptions .map(x => ({ value: x.value })) });
this.render({force: false, parts: ["settings"]});
}
}