Changed ItemLinksField makeup

This commit is contained in:
WBHarry 2025-07-23 14:50:24 +02:00
parent 600c08cb23
commit 30f31e77dd
13 changed files with 120 additions and 96 deletions

View file

@ -20,6 +20,27 @@ export default class DHItem extends foundry.documents.Item {
for (const action of this.system.actions ?? []) action.prepareData();
}
async addItemLink(documentUuid, type, replace) {
if (!this.system.metadata.isItemLinkable) return;
let existing = false;
if (replace) {
await this.update({
'system.itemLinks': Object.keys(CONFIG.DH.ITEM.itemLinkTypes).reduce((acc, key) => {
const filtered = (this.system.itemLinks[key] ?? []).filter(uuid => uuid !== documentUuid);
acc[key] = key === type ? [...filtered, documentUuid] : filtered;
existing = existing ? existing : (this.system.itemLinks[key] ?? []).size > filtered.size;
return acc;
}, {})
});
} else {
await this.update({ [`system.itemLinks.${type}`]: [...(this.system.itemLinks[type] ?? []), documentUuid] });
}
return existing;
}
/**
* @inheritdoc
* @param {object} options - Options which modify the getRollData method.