add mixin to armor

This commit is contained in:
psitacus 2025-07-11 19:31:06 -06:00
parent 83c43ec013
commit 3d25d412a2
2 changed files with 6 additions and 60 deletions

View file

@ -1,16 +1,10 @@
import DHBaseItemSheet from '../api/base-item.mjs'; import DHBaseItemSheet from '../api/base-item.mjs';
import { copyAttachmentEffectsToActor, removeAttachmentFromItem, prepareAttachmentContext, addAttachmentToItem } from '../../../helpers/attachmentHelper.mjs'; import ItemAttachmentSheet from '../api/item-attachment-sheet.mjs';
export default class ArmorSheet extends DHBaseItemSheet { export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
/**@inheritdoc */ /**@inheritdoc */
static DEFAULT_OPTIONS = { static DEFAULT_OPTIONS = {
classes: ['armor'], classes: ['armor'],
dragDrop: [
{ dragSelector: null, dropSelector: '.attachments-section' }
],
actions: {
removeAttachment: ArmorSheet.#removeAttachment
},
tagifyConfigs: [ tagifyConfigs: [
{ {
selector: '.features-input', selector: '.features-input',
@ -33,10 +27,7 @@ export default class ArmorSheet extends DHBaseItemSheet {
template: 'systems/daggerheart/templates/sheets/items/armor/settings.hbs', template: 'systems/daggerheart/templates/sheets/items/armor/settings.hbs',
scrollable: ['.settings'] scrollable: ['.settings']
}, },
attachments: { ...super.PARTS,
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-attachments.hbs',
scrollable: ['.attachments']
}
}; };
/** @override */ /** @override */
@ -56,9 +47,6 @@ export default class ArmorSheet extends DHBaseItemSheet {
case 'settings': case 'settings':
context.features = this.document.system.features.map(x => x.value); context.features = this.document.system.features.map(x => x.value);
break; break;
case 'attachments':
context.attachedItems = await prepareAttachmentContext(this.document);
break;
} }
return context; return context;
@ -71,48 +59,4 @@ export default class ArmorSheet extends DHBaseItemSheet {
static async #onFeatureSelect(selectedOptions) { static async #onFeatureSelect(selectedOptions) {
await this.document.update({ 'system.features': selectedOptions.map(x => ({ value: x.value })) }); await this.document.update({ 'system.features': selectedOptions.map(x => ({ value: x.value })) });
} }
/* -------------------------------------------- */
/* Drag and Drop */
/* -------------------------------------------- */
/**
* Handle dropping items onto the attachments section
* @param {DragEvent} event - The drop event
*/
async _onDrop(event) {
const data = TextEditor.getDragEventData(event);
const attachmentsSection = event.target.closest('.attachments-section');
if (!attachmentsSection) return super._onDrop(event);
event.preventDefault();
event.stopPropagation();
const item = await Item.implementation.fromDropData(data);
if (!item) return;
await addAttachmentToItem({
parentItem: this.document,
droppedItem: item,
parentType: 'armor'
});
}
/* -------------------------------------------- */
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
* Remove an attached item
* @param {Event} event - The click event
* @param {HTMLElement} target - The clicked element
*/
static async #removeAttachment(event, target) {
await removeAttachmentFromItem({
parentItem: this.document,
attachedUuid: target.dataset.uuid,
parentType: 'armor'
});
}
} }

View file

@ -1,5 +1,6 @@
import DHBaseItemSheet from '../api/base-item.mjs'; import DHBaseItemSheet from '../api/base-item.mjs';
import ItemAttachmentSheet from '../api/item-attachment-sheet.mjs'; import ItemAttachmentSheet from '../api/item-attachment-sheet.mjs';
import { copyAttachmentEffectsToActor, removeAttachmentFromItem, prepareAttachmentContext, addAttachmentToItem } from '../../../helpers/attachmentHelper.mjs';
export default class WeaponSheet extends ItemAttachmentSheet(DHBaseItemSheet) { export default class WeaponSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
/**@inheritdoc */ /**@inheritdoc */
@ -26,7 +27,8 @@ export default class WeaponSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
settings: { settings: {
template: 'systems/daggerheart/templates/sheets/items/weapon/settings.hbs', template: 'systems/daggerheart/templates/sheets/items/weapon/settings.hbs',
scrollable: ['.settings'] scrollable: ['.settings']
} },
...super.PARTS,
}; };
/** @override */ /** @override */