change armor and weapon to be attachableItem

This commit is contained in:
psitacus 2025-07-11 19:11:04 -06:00
parent 1fc136c81b
commit a78e1533d7
5 changed files with 82 additions and 19 deletions

View file

@ -1,4 +1,5 @@
import BaseDataItem from './base.mjs';
import { handleAttachmentEffectsOnEquipChange } from '../../helpers/attachmentHelper.mjs';
export default class AttachableItem extends BaseDataItem {
static defineSchema() {
@ -8,4 +9,18 @@ export default class AttachableItem extends BaseDataItem {
attached: new fields.ArrayField(new fields.DocumentUUIDField({ type: "Item", nullable: true }))
};
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;
// Handle equipped status changes for attachment effects
if (changes.system?.equipped !== undefined && changes.system.equipped !== this.equipped) {
await handleAttachmentEffectsOnEquipChange({
parentItem: this.parent,
newEquippedStatus: changes.system.equipped,
parentType: this.parent.type
});
}
}
}