From 6a7f19363dc432582170e6eb10c1b303b20c79ca Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 23 Jul 2025 14:59:33 +0200 Subject: [PATCH] Fixed removal of features/items propagating --- module/config/itemConfig.mjs | 4 ++-- module/data/item/base.mjs | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/module/config/itemConfig.mjs b/module/config/itemConfig.mjs index d8c39b26..e018af35 100644 --- a/module/config/itemConfig.mjs +++ b/module/config/itemConfig.mjs @@ -1318,8 +1318,7 @@ export const itemLinkFeatureTypes = { class: 'class', foundation: 'foundation', specialization: 'specialization', - mastery: 'mastery', - subclass: 'subclass' + mastery: 'mastery' }; export const itemLinkItemTypes = { @@ -1332,6 +1331,7 @@ export const itemLinkItemTypes = { }; export const itemLinkTypes = { + subclass: 'subclass', ...itemLinkFeatureTypes, ...itemLinkItemTypes }; diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index e24eb28d..3cb05968 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -171,18 +171,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { ); } - // if (this.metadata.isItemLinkable) { - // const linkEntries = Object.entries(this.itemLinks); - // for (let [uuid, type] of linkEntries) { - // const item = await foundry.utils.fromUuid(uuid); - // const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type] ? 'system.features' : 'system.linkedItems'; - // await item.update({ - // [path]: foundry.utils - // .getProperty(item, path) - // .filter(x => x.uuid !== this.parent.uuid) - // .map(x => x.uuid) - // }); - // } - // } + if (this.metadata.isItemLinkable) { + const linkEntries = Object.entries(this.itemLinks); + for (let [type, uuidList] of linkEntries) { + for (let uuid of uuidList) { + const item = await foundry.utils.fromUuid(uuid); + const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type] + ? 'system.features' + : CONFIG.DH.ITEM.itemLinkItemTypes[type] + ? 'system.linkedItems' + : 'system.subclasses'; + await item.update({ + [path]: foundry.utils + .getProperty(item, path) + .filter(x => x.uuid !== this.parent.uuid) + .map(x => x.uuid) + }); + } + } + } } }