Fixed so that features are deleted from system.features if if the feature itself is deleted

This commit is contained in:
WBHarry 2025-07-20 18:18:58 +02:00
parent 867947c2c5
commit 28efef7951
10 changed files with 241 additions and 179 deletions

View file

@ -136,13 +136,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
}
async _preDelete() {
if (!this.actor || this.actor.type !== 'character') return;
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
if (items.length > 0)
await this.actor.deleteEmbeddedDocuments(
'Item',
items.map(x => x.id)
);
if (this.originId) {
if (this.actor && this.actor.type === 'character') {
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
if (items.length > 0)
await this.actor.deleteEmbeddedDocuments(
'Item',
items.map(x => x.id)
);
} else {
const linkedItem = await foundry.utils.fromUuid(this.originId);
if (linkedItem) {
await linkedItem.update({
'system.features': linkedItem.system.features
.filter(x => x.uuid !== this.parent.uuid)
.map(x => x.uuid)
});
}
}
}
}
}