import DHBaseItemSheet from '../api/base-item.mjs'; import ItemAttachmentSheet from '../api/item-attachment-sheet.mjs'; export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) { /**@inheritdoc */ static DEFAULT_OPTIONS = { classes: ['armor'], tagifyConfigs: [ { selector: '.features-input', options: () => CONFIG.DH.ITEM.orderedArmorFeatures(), callback: ArmorSheet.#onFeatureSelect } ] }; /**@override */ static PARTS = { header: { template: 'systems/daggerheart/templates/sheets/items/armor/header.hbs' }, tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' }, description: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-description.hbs' }, actions: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-actions.hbs', scrollable: ['.actions'] }, settings: { template: 'systems/daggerheart/templates/sheets/items/armor/settings.hbs', scrollable: ['.settings'] }, effects: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-effects.hbs', scrollable: ['.effects'] }, ...super.PARTS }; _attachPartListeners(partId, htmlElement, options) { super._attachPartListeners(partId, htmlElement, options); for (const element of htmlElement.querySelectorAll('.base-score-input')) element.addEventListener('change', this.updateArmorEffect.bind(this)); } /**@inheritdoc */ async _preparePartContext(partId, context) { await super._preparePartContext(partId, context); switch (partId) { case 'settings': context.features = this.document.system.armorFeatures.map(x => x.value); context.armorScore = this.document.system.armorData.max; break; case 'effects': context.effects.actives = context.effects.actives.filter(x => x.type !== 'armor'); context.effects.inactives = context.effects.actives.filter(x => x.type !== 'armor'); break; } return context; } async updateArmorEffect(event) { const value = Number.parseInt(event.target.value); const armorEffect = this.document.system.armorEffect; if (Number.isNaN(value) || !armorEffect) return; await armorEffect.system.updateArmorMax(value); this.render(); } /** * Callback function used by `tagifyElement`. * @param {Array} selectedOptions - The currently selected tag objects. */ static async #onFeatureSelect(selectedOptions) { await this.document.update({ 'system.armorFeatures': selectedOptions.map(x => ({ value: x.value })) }); } }