mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Fixed links on character deletion
This commit is contained in:
parent
6f860c9db6
commit
67eff5d512
2 changed files with 43 additions and 7 deletions
|
|
@ -535,5 +535,36 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
if (this.companion) {
|
if (this.companion) {
|
||||||
this.companion.updateLevel(1);
|
this.companion.updateLevel(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const featureLinks = [
|
||||||
|
...(this.ancestry?.system?.features?.map(x => ({ linkUuid: this.ancestry.uuid, feature: x })) ?? []),
|
||||||
|
...(this.community?.system?.features?.map(x => ({ linkUuid: this.community.uuid, feature: x })) ?? []),
|
||||||
|
...(this.class?.value?.system?.features?.map(x => ({ linkUuid: this.class.value.uuid, feature: x })) ?? []),
|
||||||
|
...(this.class?.subclass?.system?.features?.map(x => ({
|
||||||
|
linkUuid: this.class.subclass.uuid,
|
||||||
|
feature: x
|
||||||
|
})) ?? [])
|
||||||
|
];
|
||||||
|
for (let { linkUuid, feature } of featureLinks) {
|
||||||
|
await feature.update({
|
||||||
|
'system.itemLinks': Object.keys(CONFIG.DH.ITEM.itemLinkFeatureTypes).reduce((acc, type) => {
|
||||||
|
acc[type] = (feature.system.itemLinks[type] ?? []).filter(uuid => uuid !== linkUuid);
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemLinks = this.class?.value?.system?.linkedItems?.map(x => ({
|
||||||
|
linkUuid: this.class.value.uuid,
|
||||||
|
item: x
|
||||||
|
}));
|
||||||
|
for (let { linkUuid, item } of itemLinks) {
|
||||||
|
await item.update({
|
||||||
|
'system.itemLinks': Object.keys(CONFIG.DH.ITEM.itemLinkItemTypes).reduce((acc, type) => {
|
||||||
|
acc[type] = (item.system.itemLinks[type] ?? []).filter(uuid => uuid !== linkUuid);
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,10 +137,10 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
...feature,
|
...feature,
|
||||||
system: {
|
system: {
|
||||||
...feature.system,
|
...feature.system,
|
||||||
itemLinks: Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
itemLinks: Object.keys(feature.system.itemLinks).reduce((acc, type) => {
|
||||||
const type = feature.system.itemLinks[uuid];
|
acc[type] = feature.system.itemLinks[type].map(uuid =>
|
||||||
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
uuid === options.origUuid ? this.parent.uuid : uuid
|
||||||
|
);
|
||||||
return acc;
|
return acc;
|
||||||
}, {}),
|
}, {}),
|
||||||
originItemType: this.parent.type,
|
originItemType: this.parent.type,
|
||||||
|
|
@ -152,9 +152,10 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
for (let feature of this.features) {
|
for (let feature of this.features) {
|
||||||
feature.update({
|
feature.update({
|
||||||
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, uuid) => {
|
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, type) => {
|
||||||
const type = feature.system.itemLinks[uuid];
|
acc[type] = Array.from(feature.system.itemLinks[type]).flatMap(uuid =>
|
||||||
acc[uuid === options.origUuid ? this.parent.uuid : uuid] = type;
|
uuid === options.origUuid ? [uuid, this.parent.uuid] : [uuid]
|
||||||
|
);
|
||||||
return acc;
|
return acc;
|
||||||
}, {})
|
}, {})
|
||||||
});
|
});
|
||||||
|
|
@ -176,6 +177,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
for (let [type, uuidList] of linkEntries) {
|
for (let [type, uuidList] of linkEntries) {
|
||||||
for (let uuid of uuidList) {
|
for (let uuid of uuidList) {
|
||||||
const item = await foundry.utils.fromUuid(uuid);
|
const item = await foundry.utils.fromUuid(uuid);
|
||||||
|
if (!item) return;
|
||||||
|
|
||||||
const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type]
|
const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type]
|
||||||
? 'system.features'
|
? 'system.features'
|
||||||
: CONFIG.DH.ITEM.itemLinkItemTypes[type]
|
: CONFIG.DH.ITEM.itemLinkItemTypes[type]
|
||||||
|
|
@ -193,6 +196,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
if (this.features?.length) {
|
if (this.features?.length) {
|
||||||
for (let feature of this.features) {
|
for (let feature of this.features) {
|
||||||
|
if (!feature) continue;
|
||||||
await feature.update({
|
await feature.update({
|
||||||
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, type) => {
|
'system.itemLinks': Object.keys(feature.system.itemLinks).reduce((acc, type) => {
|
||||||
acc[type] = feature.system.itemLinks[type].filter(uuid => uuid !== this.parent.uuid);
|
acc[type] = feature.system.itemLinks[type].filter(uuid => uuid !== this.parent.uuid);
|
||||||
|
|
@ -204,6 +208,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
if (this.linkedItems?.length) {
|
if (this.linkedItems?.length) {
|
||||||
for (let item of this.linkedItems) {
|
for (let item of this.linkedItems) {
|
||||||
|
if (!item) continue;
|
||||||
await item.update({
|
await item.update({
|
||||||
'system.itemLinks': Object.keys(item.system.itemLinks).reduce((acc, type) => {
|
'system.itemLinks': Object.keys(item.system.itemLinks).reduce((acc, type) => {
|
||||||
acc[type] = item.system.itemLinks[type].filter(uuid => uuid !== this.parent.uuid);
|
acc[type] = item.system.itemLinks[type].filter(uuid => uuid !== this.parent.uuid);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue