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

@ -5,8 +5,7 @@ export default class AncestrySheet extends DHHeritageSheet {
static DEFAULT_OPTIONS = {
classes: ['ancestry'],
actions: {
editFeature: AncestrySheet.#editFeature,
removeFeature: AncestrySheet.#removeFeature
editFeature: AncestrySheet.#editFeature
},
dragDrop: [{ dragSelector: null, dropSelector: '.tab.features .drop-section' }]
};
@ -37,21 +36,6 @@ export default class AncestrySheet extends DHHeritageSheet {
feature.sheet.render(true);
}
/**
* Remove a feature from the item.
* @type {ApplicationClickAction}
*/
static async #removeFeature(event, button) {
event.stopPropagation();
const target = button.closest('.feature-item');
const feature = this.document.system[`${target.dataset.type}Feature`];
if (feature) await feature.update({ 'system.subType': null });
await this.document.update({
'system.features': this.document.system.features.filter(x => x && x.uuid !== feature.uuid).map(x => x.uuid)
});
}
/* -------------------------------------------- */
/* Application Drag/Drop */
/* -------------------------------------------- */
@ -73,7 +57,14 @@ export default class AncestrySheet extends DHHeritageSheet {
return;
}
await item.update({ 'system.subType': subType });
await item.update({
system: {
subType: subType,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});

View file

@ -9,7 +9,7 @@ export default class ClassSheet extends DHBaseItemSheet {
position: { width: 700 },
actions: {
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
removeSuggestedItem: ClassSheet.#removeSuggestedItem,
removeSuggestedItem: ClassSheet.#removeSuggestedItem
},
tagifyConfigs: [
{
@ -93,7 +93,13 @@ export default class ClassSheet extends DHBaseItemSheet {
return;
}
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.hope });
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.hope,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
@ -103,7 +109,13 @@ export default class ClassSheet extends DHBaseItemSheet {
return;
}
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.class });
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.class,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});

View file

@ -68,7 +68,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return;
}
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.foundation });
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.foundation,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
@ -78,7 +84,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return;
}
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.specialization });
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.specialization,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});
@ -88,7 +100,13 @@ export default class SubclassSheet extends DHBaseItemSheet {
return;
}
await item.update({ 'system.subType': CONFIG.DH.ITEM.featureSubTypes.mastery });
await item.update({
system: {
subType: CONFIG.DH.ITEM.featureSubTypes.mastery,
originItemType: CONFIG.DH.ITEM.featureTypes[this.document.type].id,
originId: this.document.uuid
}
});
await this.document.update({
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
});