mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Fixes links upon being embedded
This commit is contained in:
parent
df8b96e9bc
commit
b1aca218c2
3 changed files with 64 additions and 14 deletions
|
|
@ -6,6 +6,7 @@
|
|||
* @property {boolean} hasDescription - Indicates whether items of this type have description field
|
||||
* @property {boolean} isQuantifiable - Indicates whether items of this type have quantity field
|
||||
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
|
||||
* @property {boolean} isItemLinkable - Indicates whether items of this type can have links to other items.
|
||||
*/
|
||||
|
||||
import ItemLinksField from '../fields/itemLinksField.mjs';
|
||||
|
|
@ -123,9 +124,11 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
|
||||
this.updateSource({ actions: [action] });
|
||||
}
|
||||
|
||||
options.origUuid = data.uuid;
|
||||
}
|
||||
|
||||
_onCreate(data) {
|
||||
_onCreate(data, options) {
|
||||
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
|
||||
|
||||
this.actor.createEmbeddedDocuments(
|
||||
|
|
@ -134,12 +137,28 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
...feature,
|
||||
system: {
|
||||
...feature.system,
|
||||
itemLinks: Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
||||
const type = feature.system.itemLinks[uuid];
|
||||
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
originItemType: this.parent.type,
|
||||
originId: data._id,
|
||||
identifier: feature.identifier
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
for (let feature of this.features) {
|
||||
feature.update({
|
||||
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
||||
const type = feature.system.itemLinks[uuid];
|
||||
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
||||
return acc;
|
||||
}, {})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async _preDelete() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue