mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Changed ItemLinksField makeup
This commit is contained in:
parent
600c08cb23
commit
30f31e77dd
13 changed files with 120 additions and 96 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue