diff --git a/module/applications/sheets/items/ancestry.mjs b/module/applications/sheets/items/ancestry.mjs index d104811e..7a55166d 100644 --- a/module/applications/sheets/items/ancestry.mjs +++ b/module/applications/sheets/items/ancestry.mjs @@ -19,19 +19,6 @@ export default class AncestrySheet extends DHHeritageSheet { features: { template: 'systems/daggerheart/templates/sheets/items/ancestry/features.hbs' } }; - async _preparePartContext(partId, context) { - await super._preparePartContext(partId, context); - - switch (partId) { - case 'features': - context.primaryFeature = this.document.system.features.find(x => x.primary)?.value; - context.secondaryFeature = this.document.system.features.find(x => !x.primary)?.value; - break; - } - - return context; - } - /* -------------------------------------------- */ /* Application Clicks Actions */ /* -------------------------------------------- */ @@ -45,13 +32,10 @@ export default class AncestrySheet extends DHHeritageSheet { type: 'feature', name: game.i18n.format('DOCUMENT.New', { type: game.i18n.localize('TYPES.Item.feature') }) }); - await this.document.update({ system: { - features: [ - ...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })), - { primary: button.dataset.type === 'primary', value: feature.uuid } - ] + features: [...this.document.system.features.map(x => x.uuid), feature.uuid], + [`${button.dataset.type}Feature`]: feature.uuid } }); } @@ -62,9 +46,7 @@ export default class AncestrySheet extends DHHeritageSheet { */ static async #editFeature(_event, button) { const target = button.closest('.feature-item'); - const feature = this.document.system.features.find(x => - target.dataset.type === 'primary' ? x.primary : !x.primary - )?.value; + const feature = this.document.system[`${target.dataset.type}Feature`]; if (!feature) { ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing')); return; @@ -80,9 +62,7 @@ export default class AncestrySheet extends DHHeritageSheet { static async #removeFeature(event, button) { event.stopPropagation(); const target = button.closest('.feature-item'); - const feature = this.document.system.features.find(x => - target.dataset.type === 'primary' ? x.primary : !x.primary - )?.value; + const feature = this.document.system[`${target.dataset.type}Feature`]; if (feature) { const confirmed = await foundry.applications.api.DialogV2.confirm({ @@ -98,9 +78,10 @@ export default class AncestrySheet extends DHHeritageSheet { } await this.document.update({ - 'system.features': this.document.system.features - .filter(x => x.value.uuid !== feature.uuid) - .map(x => ({ ...x, value: x.value.uuid })) + system: { + features: this.document.system.features.filter(x => x.uuid !== feature.uuid).map(x => x.uuid), + [`${target.dataset.type}Feature`]: null + } }); } @@ -120,12 +101,19 @@ export default class AncestrySheet extends DHHeritageSheet { const item = await fromUuid(data.uuid); if (item?.type === 'feature') { - await this.document.update({ - 'system.features': [ - ...this.document.system.features.map(x => ({ ...x, value: x.value.uuid })), - { primary: Boolean(event.target.closest('.primary-feature')), value: item.uuid } - ] - }); + const update = { + system: { + features: [...this.document.system.features.map(x => x.uuid), item.uuid] + } + }; + + if (event.target.closest('.primary-feature')) { + update.system.primaryFeature = item.uuid; + } else if (event.target.closest('.secondary-feature')) { + update.system.secondaryFeature = item.uuid; + } + + await this.document.update(update); } } } diff --git a/module/data/item/ancestry.mjs b/module/data/item/ancestry.mjs index bfe21200..7de44124 100644 --- a/module/data/item/ancestry.mjs +++ b/module/data/item/ancestry.mjs @@ -1,3 +1,4 @@ +import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs'; import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs'; import BaseDataItem from './base.mjs'; @@ -13,15 +14,11 @@ export default class DHAncestry extends BaseDataItem { /** @inheritDoc */ static defineSchema() { - const fields = foundry.data.fields; return { ...super.defineSchema(), - features: new fields.ArrayField( - new fields.SchemaField({ - primary: new fields.BooleanField(), - value: new ForeignDocumentUUIDField({ type: 'Item' }) - }) - ) + features: new ForeignDocumentUUIDArrayField({ type: 'Item' }), + primaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }), + secondaryFeature: new ForeignDocumentUUIDField({ type: 'Item' }) }; } } diff --git a/templates/sheets/items/ancestry/features.hbs b/templates/sheets/items/ancestry/features.hbs index 952174b1..9f1694b6 100644 --- a/templates/sheets/items/ancestry/features.hbs +++ b/templates/sheets/items/ancestry/features.hbs @@ -6,13 +6,13 @@