diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index b343eb62..c78e5670 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -84,24 +84,26 @@ export default function DHApplicationMixin(Base) { useItem: DHSheetV2.#useItem, useAction: DHSheetV2.#useAction, toggleEffect: DHSheetV2.#toggleEffect, - toggleExtended: DHSheetV2.#toggleExtended, + toggleExtended: DHSheetV2.#toggleExtended }, - contextMenus: [{ - handler: DHSheetV2.#getEffectContextOptions, - selector: '[data-item-uuid][data-type="effect"]', - options: { - parentClassHooks: false, - fixed: true + contextMenus: [ + { + handler: DHSheetV2.#getEffectContextOptions, + selector: '[data-item-uuid][data-type="effect"]', + options: { + parentClassHooks: false, + fixed: true + } }, - }, - { - handler: DHSheetV2.#getActionContextOptions, - selector: '[data-item-uuid][data-type="action"]', - options: { - parentClassHooks: false, - fixed: true + { + handler: DHSheetV2.#getActionContextOptions, + selector: '[data-item-uuid][data-type="action"]', + options: { + parentClassHooks: false, + fixed: true + } } - }], + ], dragDrop: [], tagifyConfigs: [] }; @@ -132,13 +134,13 @@ export default function DHApplicationMixin(Base) { /**@inheritdoc */ _syncPartState(partId, newElement, priorElement, state) { super._syncPartState(partId, newElement, priorElement, state); - for (const el of priorElement.querySelectorAll(".extensible.extended")) { + for (const el of priorElement.querySelectorAll('.extensible.extended')) { const { actionId, itemUuid } = el.parentElement.dataset; const selector = `${actionId ? `[data-action-id="${actionId}"]` : `[data-item-uuid="${itemUuid}"]`} .extensible`; const newExtensible = newElement.querySelector(selector); if (!newExtensible) continue; - newExtensible.classList.add("extended"); + newExtensible.classList.add('extended'); const descriptionElement = newExtensible.querySelector('.invetory-description'); if (descriptionElement) { this.#prepareInventoryDescription(newExtensible, descriptionElement); @@ -209,14 +211,14 @@ export default function DHApplicationMixin(Base) { * @param {DragEvent} event * @protected */ - _onDragStart(event) { } + _onDragStart(event) {} /** * Handle drop event. * @param {DragEvent} event * @protected */ - _onDrop(event) { } + _onDrop(event) {} /* -------------------------------------------- */ /* Context Menu */ @@ -251,7 +253,7 @@ export default function DHApplicationMixin(Base) { icon: 'fa-regular fa-lightbulb', condition: target => getDocFromElement(target).disabled, callback: target => getDocFromElement(target).update({ disabled: false }) - }, + } ].map(option => ({ ...option, name: `DAGGERHEART.APPLICATIONS.ContextMenu.${option.name}`, @@ -269,7 +271,7 @@ export default function DHApplicationMixin(Base) { */ static #getActionContextOptions() { /**@type {import('@client/applications/ux/context-menu.mjs').ContextMenuEntry[]} */ - const getAction = (target) => { + const getAction = target => { const { actionId } = target.closest('[data-action-id]').dataset; const { actions, attack } = this.document.system; return attack?.id === actionId ? attack : actions?.find(a => a.id === actionId); @@ -279,30 +281,31 @@ export default function DHApplicationMixin(Base) { { name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', icon: 'fa-solid fa-burst', - condition: this.document instanceof foundry.documents.Actor || + condition: + this.document instanceof foundry.documents.Actor || (this.document instanceof foundry.documents.Item && this.document.parent), - callback: (target, event) => getAction(target).use(event), + callback: (target, event) => getAction(target).use(event) }, { name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat', icon: 'fa-solid fa-message', - callback: (target) => getAction(target).toChat(this.document.id), + callback: target => getAction(target).toChat(this.document.id) }, { name: 'CONTROLS.CommonEdit', icon: 'fa-solid fa-pen-to-square', - callback: (target) => new DHActionConfig(getAction(target)).render({ force: true }) + callback: target => new DHActionConfig(getAction(target)).render({ force: true }) }, { name: 'CONTROLS.CommonDelete', icon: 'fa-solid fa-trash', - condition: (target) => { + condition: target => { const { actionId } = target.closest('[data-action-id]').dataset; const { attack } = this.document.system; - return attack?.id !== actionId + return attack?.id !== actionId; }, - callback: async (target) => { - const action = getAction(target) + callback: async target => { + const action = getAction(target); const confirmed = await foundry.applications.api.DialogV2.confirm({ window: { title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { @@ -310,12 +313,14 @@ export default function DHApplicationMixin(Base) { name: action.name }) }, - content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: action.name }) + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { + name: action.name + }) }); if (!confirmed) return; return this.document.update({ - 'system.actions': this.document.system.actions.filter((a) => a.id !== action.id) + 'system.actions': this.document.system.actions.filter(a => a.id !== action.id) }); } } @@ -337,35 +342,38 @@ export default function DHApplicationMixin(Base) { name: 'CONTROLS.CommonEdit', icon: 'fa-solid fa-pen-to-square', callback: target => getDocFromElement(target).sheet.render({ force: true }) - }, + } ]; - if (usable) options.unshift({ - name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', - icon: 'fa-solid fa-burst', - callback: (target, event) => getDocFromElement(target).use(event), - }); + if (usable) + options.unshift({ + name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', + icon: 'fa-solid fa-burst', + callback: (target, event) => getDocFromElement(target).use(event) + }); - if (toChat) options.unshift({ - name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat', - icon: 'fa-solid fa-message', - callback: (target) => getDocFromElement(target).toChat(this.document.id), - }); + if (toChat) + options.unshift({ + name: 'DAGGERHEART.APPLICATIONS.ContextMenu.sendToChat', + icon: 'fa-solid fa-message', + callback: target => getDocFromElement(target).toChat(this.document.id) + }); - if (deletable) options.push({ - name: 'CONTROLS.CommonDelete', - icon: 'fa-solid fa-trash', - callback: (target, event) => { - const doc = getDocFromElement(target); - if (event.shiftKey) return doc.delete(); - else return doc.deleteDialog(); - } - }) + if (deletable) + options.push({ + name: 'CONTROLS.CommonDelete', + icon: 'fa-solid fa-trash', + callback: (target, event) => { + const doc = getDocFromElement(target); + if (event.shiftKey) return doc.delete(); + else return doc.deleteDialog(); + } + }); return options.map(option => ({ ...option, icon: `` - })) + })); } /* -------------------------------------------- */ @@ -400,17 +408,20 @@ export default function DHApplicationMixin(Base) { const doc = itemUuid ? getDocFromElement(extensibleElement) : this.document.system.attack?.id === actionId - ? this.document.system.attack - : this.document.system.actions?.find(a => a.id === actionId); + ? this.document.system.attack + : this.document.system.actions?.find(a => a.id === actionId); if (!doc) return; const description = doc.system?.description ?? doc.description; const isAction = !!actionId; - descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML(description, { - relativeTo: isAction ? doc.parent : doc, - rollData: doc.getRollData?.(), - secrets: isAction ? doc.parent.isOwner : doc.isOwner - }); + descriptionElement.innerHTML = await foundry.applications.ux.TextEditor.implementation.enrichHTML( + description, + { + relativeTo: isAction ? doc.parent : doc, + rollData: doc.getRollData?.(), + secrets: isAction ? doc.parent.isOwner : doc.isOwner + } + ); } /* -------------------------------------------- */ @@ -427,26 +438,28 @@ export default function DHApplicationMixin(Base) { const parent = parentIsItem && documentClass === 'Item' ? null : this.document; if (type === 'action') { - const { type: actionType } = await foundry.applications.api.DialogV2.input({ - window: { title: 'Select Action Type' }, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/actionTypes/actionType.hbs', - { types: CONFIG.DH.ACTIONS.actionTypes } - ), - ok: { - label: game.i18n.format('DOCUMENT.Create', { - type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single') - }), - } - }) ?? {}; + const { type: actionType } = + (await foundry.applications.api.DialogV2.input({ + window: { title: 'Select Action Type' }, + content: await foundry.applications.handlebars.renderTemplate( + 'systems/daggerheart/templates/actionTypes/actionType.hbs', + { types: CONFIG.DH.ACTIONS.actionTypes } + ), + ok: { + label: game.i18n.format('DOCUMENT.Create', { + type: game.i18n.localize('DAGGERHEART.GENERAL.Action.single') + }) + } + })) ?? {}; if (!actionType) return; - const cls = game.system.api.models.actions.actionsTypes[actionType] - const action = new cls({ - _id: foundry.utils.randomID(), - type: actionType, - name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name), - ...cls.getSourceConfig(this.document) - }, + const cls = game.system.api.models.actions.actionsTypes[actionType]; + const action = new cls( + { + _id: foundry.utils.randomID(), + type: actionType, + name: game.i18n.localize(CONFIG.DH.ACTIONS.actionTypes[actionType].name), + ...cls.getSourceConfig(this.document) + }, { parent: this.document } @@ -456,25 +469,32 @@ export default function DHApplicationMixin(Base) { force: true }); return action; - } else { const cls = getDocumentClass(documentClass); const data = { name: cls.defaultName({ type, parent }), - type, - } - if (inVault) data["system.inVault"] = true; + type + }; + if (inVault) data['system.inVault'] = true; if (disabled) data.disabled = true; + const isItemFeature = parentIsItem && type === 'feature'; + if (isItemFeature) { + data.system = { + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + }; + } + const doc = await cls.create(data, { parent, renderSheet: !event.shiftKey }); - if (parentIsItem && type === 'feature') { + + if (isItemFeature) { await this.document.update({ 'system.features': this.document.system.toObject().features.concat(doc.uuid) }); } return doc; } - } /** @@ -489,7 +509,7 @@ export default function DHApplicationMixin(Base) { const { actionId } = target.closest('[data-action-id]').dataset; const { actions, attack } = this.document.system; const action = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId); - new DHActionConfig(action).render({ force: true }) + new DHActionConfig(action).render({ force: true }); } /** @@ -500,8 +520,8 @@ export default function DHApplicationMixin(Base) { const doc = getDocFromElement(target); if (doc) { - if (event.shiftKey) return doc.delete() - else return await doc.deleteDialog() + if (event.shiftKey) return doc.delete(); + else return await doc.deleteDialog(); } // TODO: REDO this @@ -524,7 +544,7 @@ export default function DHApplicationMixin(Base) { } return await this.document.update({ - 'system.actions': actions.filter((a) => a.id !== action.id) + 'system.actions': actions.filter(a => a.id !== action.id) }); } @@ -555,7 +575,7 @@ export default function DHApplicationMixin(Base) { const { actionId } = target.closest('[data-action-id]').dataset; const { actions, attack } = this.document.system; doc = attack?.id === actionId ? attack : actions?.find(a => a.id === actionId); - if(this.document instanceof foundry.documents.Item && !this.document.parent) return; + if (this.document instanceof foundry.documents.Item && !this.document.parent) return; } await doc.use(event); @@ -573,7 +593,6 @@ export default function DHApplicationMixin(Base) { await action.use(event); } - /** * Toggle a ActiveEffect * @type {ApplicationClickAction} @@ -604,7 +623,6 @@ export default function DHApplicationMixin(Base) { const descriptionElement = extensible?.querySelector('.invetory-description'); if (t && !!descriptionElement) this.#prepareInventoryDescription(extensible, descriptionElement); } - } return DHSheetV2; diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index 766b443c..610586cb 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -72,10 +72,10 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { secrets: this.item.isOwner }); break; - case "effects": - await this._prepareEffectsContext(context, options) + case 'effects': + await this._prepareEffectsContext(context, options); break; - case "features": + case 'features': context.isGM = game.user.isGM; break; } @@ -93,7 +93,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { async _prepareEffectsContext(context, _options) { context.effects = { actives: [], - inactives: [], + inactives: [] }; for (const effect of this.item.effects) { @@ -113,30 +113,38 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { * @protected */ static #getFeatureContextOptions() { - const options = this._getContextMenuCommonOptions({ usable: true, toChat: true, deletable: false }) - options.push( - { - name: 'CONTROLS.CommonDelete', - icon: '', - callback: async (target) => { - const feature = getDocFromElement(target); - if (!feature) return; - const confirmed = await foundry.applications.api.DialogV2.confirm({ - window: { - title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { - type: game.i18n.localize(`TYPES.Item.feature`), - name: feature.name - }) - }, - content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: feature.name }) - }); - if (!confirmed) return; - await this.document.update({ - 'system.features': this.document.system.toObject().features.filter(uuid => uuid !== feature.uuid) - }); - }, + const options = this._getContextMenuCommonOptions({ usable: true, toChat: true, deletable: false }); + options.push({ + name: 'CONTROLS.CommonDelete', + icon: '', + callback: async target => { + const feature = getDocFromElement(target); + if (!feature) return; + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { + type: game.i18n.localize(`TYPES.Item.feature`), + name: feature.name + }) + }, + content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { + name: feature.name + }) + }); + if (!confirmed) return; + + await feature.update({ + system: { + originItemType: null, + originId: null, + subType: null + } + }); + await this.document.update({ + 'system.features': this.document.system.toObject().features.filter(uuid => uuid !== feature.uuid) + }); } - ) + }); return options; } @@ -153,7 +161,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { const actionIndex = button.closest('[data-index]').dataset.index; const action = this.document.system.actions[actionIndex]; - if(!event.shiftKey) { + if (!event.shiftKey) { const confirmed = await foundry.applications.api.DialogV2.confirm({ window: { title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', { @@ -166,7 +174,6 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { if (!confirmed) return; } - await this.document.update({ 'system.actions': this.document.system.actions.filter((_, index) => index !== Number.parseInt(actionIndex)) }); @@ -182,7 +189,11 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { const feature = await cls.create({ type: 'feature', name: cls.defaultName({ type: 'feature' }), - "system.subType": CONFIG.DH.ITEM.featureSubTypes[type] + system: { + subType: CONFIG.DH.ITEM.featureSubTypes[type], + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } }); await this.document.update({ 'system.features': [...this.document.system.features, feature].map(f => f.uuid) @@ -196,11 +207,15 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { static async #deleteFeature(_, target) { const feature = getDocFromElement(target); if (!feature) return ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing')); - await feature.update({ 'system.subType': null }); + await feature.update({ + system: { + originItemType: null, + originId: null, + subType: null + } + }); await this.document.update({ - 'system.features': this.document.system.features - .map(x => x.uuid) - .filter(uuid => uuid !== feature.uuid) + 'system.features': this.document.system.features.map(x => x.uuid).filter(uuid => uuid !== feature.uuid) }); } @@ -275,6 +290,12 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { const item = await fromUuid(data.uuid); if (item?.type === 'feature') { + await item.update({ + system: { + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); const current = this.document.system.features.map(x => x.uuid); await this.document.update({ 'system.features': [...current, item.uuid] }); } diff --git a/module/applications/sheets/items/ancestry.mjs b/module/applications/sheets/items/ancestry.mjs index fc0b8a52..e69a7288 100644 --- a/module/applications/sheets/items/ancestry.mjs +++ b/module/applications/sheets/items/ancestry.mjs @@ -5,8 +5,7 @@ export default class AncestrySheet extends DHHeritageSheet { static DEFAULT_OPTIONS = { classes: ['ancestry'], actions: { - editFeature: AncestrySheet.#editFeature, - removeFeature: AncestrySheet.#removeFeature + editFeature: AncestrySheet.#editFeature }, dragDrop: [{ dragSelector: null, dropSelector: '.tab.features .drop-section' }] }; @@ -37,21 +36,6 @@ export default class AncestrySheet extends DHHeritageSheet { feature.sheet.render(true); } - /** - * Remove a feature from the item. - * @type {ApplicationClickAction} - */ - static async #removeFeature(event, button) { - event.stopPropagation(); - const target = button.closest('.feature-item'); - const feature = this.document.system[`${target.dataset.type}Feature`]; - - if (feature) await feature.update({ 'system.subType': null }); - await this.document.update({ - 'system.features': this.document.system.features.filter(x => x && x.uuid !== feature.uuid).map(x => x.uuid) - }); - } - /* -------------------------------------------- */ /* Application Drag/Drop */ /* -------------------------------------------- */ @@ -73,7 +57,14 @@ export default class AncestrySheet extends DHHeritageSheet { return; } - await item.update({ 'system.subType': subType }); + await item.update({ + system: { + subType: subType, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); + await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); diff --git a/module/applications/sheets/items/class.mjs b/module/applications/sheets/items/class.mjs index 11feb1b2..ec1fff21 100644 --- a/module/applications/sheets/items/class.mjs +++ b/module/applications/sheets/items/class.mjs @@ -9,7 +9,7 @@ export default class ClassSheet extends DHBaseItemSheet { position: { width: 700 }, actions: { removeItemFromCollection: ClassSheet.#removeItemFromCollection, - removeSuggestedItem: ClassSheet.#removeSuggestedItem, + removeSuggestedItem: ClassSheet.#removeSuggestedItem }, tagifyConfigs: [ { @@ -93,7 +93,13 @@ export default class ClassSheet extends DHBaseItemSheet { return; } - await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.hope }); + await item.update({ + system: { + subType: CONFIG.DH.ITEM.featureSubTypes.hope, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); @@ -103,7 +109,13 @@ export default class ClassSheet extends DHBaseItemSheet { return; } - await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.class }); + await item.update({ + system: { + subType: CONFIG.DH.ITEM.featureSubTypes.class, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); diff --git a/module/applications/sheets/items/subclass.mjs b/module/applications/sheets/items/subclass.mjs index 585bd6cb..5593737d 100644 --- a/module/applications/sheets/items/subclass.mjs +++ b/module/applications/sheets/items/subclass.mjs @@ -68,7 +68,13 @@ export default class SubclassSheet extends DHBaseItemSheet { return; } - await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.foundation }); + await item.update({ + system: { + subType: CONFIG.DH.ITEM.featureSubTypes.foundation, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); @@ -78,7 +84,13 @@ export default class SubclassSheet extends DHBaseItemSheet { return; } - await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.specialization }); + await item.update({ + system: { + subType: CONFIG.DH.ITEM.featureSubTypes.specialization, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); @@ -88,7 +100,13 @@ export default class SubclassSheet extends DHBaseItemSheet { return; } - await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.mastery }); + await item.update({ + system: { + subType: CONFIG.DH.ITEM.featureSubTypes.mastery, + originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id, + originId: this.document.uuid + } + }); await this.document.update({ 'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid] }); diff --git a/module/data/item/ancestry.mjs b/module/data/item/ancestry.mjs index 71b7683d..483dbb94 100644 --- a/module/data/item/ancestry.mjs +++ b/module/data/item/ancestry.mjs @@ -20,18 +20,10 @@ export default class DHAncestry extends BaseDataItem { } get primaryFeature() { - return ( - this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ?? - (this.features.filter(x => !x).length > 0 ? {} : null) - ); + return this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.primary) ?? null; } get secondaryFeature() { - return ( - this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ?? - (this.features.filter(x => !x || x.system.subType === CONFIG.DH.ITEM.featureSubTypes.primary).length > 1 - ? {} - : null) - ); + return this.features.find(x => x?.system?.subType === CONFIG.DH.ITEM.featureSubTypes.secondary) ?? null; } } diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index 24e5e0cc..92e12040 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -136,13 +136,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { } async _preDelete() { - if (!this.actor || this.actor.type !== 'character') return; - - const items = this.actor.items.filter(item => item.system.originId === this.parent.id); - if (items.length > 0) - await this.actor.deleteEmbeddedDocuments( - 'Item', - items.map(x => x.id) - ); + if (this.originId) { + if (this.actor && this.actor.type === 'character') { + const items = this.actor.items.filter(item => item.system.originId === this.parent.id); + if (items.length > 0) + await this.actor.deleteEmbeddedDocuments( + 'Item', + items.map(x => x.id) + ); + } else { + const linkedItem = await foundry.utils.fromUuid(this.originId); + if (linkedItem) { + await linkedItem.update({ + 'system.features': linkedItem.system.features + .filter(x => x.uuid !== this.parent.uuid) + .map(x => x.uuid) + }); + } + } + } } } diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 62b955e9..31c415dc 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -22,9 +22,8 @@ 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(), + subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }), actions: new fields.ArrayField(new ActionField()) }; } diff --git a/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs b/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs index aa58aad8..730dcc98 100644 --- a/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs +++ b/templates/sheets/global/partials/inventory-fieldset-items-V2.hbs @@ -26,14 +26,14 @@ Parameters: {{localize title}} {{#if canCreate}} - - - + + + {{/if }} {{#if (and cardView (eq type 'domainCard'))}} diff --git a/templates/sheets/items/ancestry/features.hbs b/templates/sheets/items/ancestry/features.hbs index 6bc108b1..431cf8c4 100644 --- a/templates/sheets/items/ancestry/features.hbs +++ b/templates/sheets/items/ancestry/features.hbs @@ -17,7 +17,7 @@ {{document.system.primaryFeature.name}}
- +
{{/if}} @@ -38,7 +38,7 @@ {{document.system.secondaryFeature.name}}
- +
{{/if}}