From 682ffc04d7ffed4ab5f42ded6c6f744238955520 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Thu, 31 Jul 2025 18:47:22 +0200 Subject: [PATCH] Adding features on CharacterItems now adds them on the Character and relinks --- .../sheets/api/application-mixin.mjs | 24 ++++++++++++++----- module/applications/sheets/api/base-item.mjs | 22 +++++++++++++---- module/data/item/base.mjs | 3 +-- module/data/item/feature.mjs | 1 - 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 50c93617..94877683 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -413,17 +413,29 @@ export default function DHApplicationMixin(Base) { const { documentClass, type, inVault, disabled } = target.dataset; const parentIsItem = this.document.documentName === 'Item'; const parent = - parentIsItem && documentClass === 'Item' - ? type === 'action' - ? this.document.system - : null - : this.document; + this.document.parent?.type === 'character' + ? this.document.parent + : parentIsItem && documentClass === 'Item' + ? type === 'action' + ? this.document.system + : null + : this.document; + + let systemData = {}; + if (parent?.type === 'character' && type === 'feature') { + systemData = { + originItemType: this.document.type, + originId: this.document.id, + identifier: this.document.system.isMulticlass ? 'multiclass' : null + }; + } const cls = type === 'action' ? game.system.api.models.actions.actionsTypes.base : getDocumentClass(documentClass); const data = { name: cls.defaultName({ type, parent }), - type + type, + system: systemData }; if (inVault) data['system.inVault'] = true; if (disabled) data.disabled = true; diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index ed63956b..b5573a0c 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -150,10 +150,24 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { static async #addFeature(_, target) { const { type } = target.dataset; const cls = foundry.documents.Item.implementation; - const item = await cls.create({ - type: 'feature', - name: cls.defaultName({ type: 'feature' }) - }); + + let systemData = {}; + if (this.document.parent?.type === 'character') { + systemData = { + originItemType: this.document.type, + originId: this.document.id, + identifier: this.document.system.isMulticlass ? 'multiclass' : null + }; + } + + const item = await cls.create( + { + type: 'feature', + name: cls.defaultName({ type: 'feature' }), + system: systemData + }, + { parent: this.document.parent?.type === 'character' ? this.document.parent : undefined } + ); await this.document.update({ 'system.features': [...this.document.system.features, { type, item }].map(x => ({ ...x, diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index 1f1c06fd..ee638c66 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -134,8 +134,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { system: { originItemType: this.parent.type, originId: data._id, - identifier: this.isMulticlass ? 'multiclass' : null, - subType: feature.item ? feature.type : undefined + identifier: this.isMulticlass ? 'multiclass' : null } }, { inplace: false } diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 93a2c0bd..53e4d2d6 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -23,7 +23,6 @@ export default class DHFeature extends BaseDataItem { nullable: true, initial: null }), - subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }), originId: new fields.StringField({ nullable: true, initial: null }), identifier: new fields.StringField() };