fix: sanitize weapon feature effect IDs and correctly remove single entries during augment removal
This commit is contained in:
parent
0d4446ece6
commit
204573de13
1 changed files with 15 additions and 3 deletions
|
|
@ -197,10 +197,22 @@ export function patchIkonisSheet() {
|
|||
};
|
||||
|
||||
Weapon.prototype._onRemoveAugment = async function(event, target) {
|
||||
const weaponFeatures = this.document.system.weaponFeatures || [];
|
||||
const weaponFeatures = foundry.utils.deepClone(this.document.system.weaponFeatures || []);
|
||||
const targetId = target.dataset.id;
|
||||
const newFeatures = weaponFeatures.filter(f => f.value !== targetId);
|
||||
await this.document.update({ "system.weaponFeatures": newFeatures });
|
||||
|
||||
// Find the index of the first matching feature to remove
|
||||
const idx = weaponFeatures.findIndex(f => String(f.value) === String(targetId));
|
||||
|
||||
if (idx !== -1) {
|
||||
// Sanitize effectIds to prevent system crash if effects are missing
|
||||
const feature = weaponFeatures[idx];
|
||||
if (Array.isArray(feature.effectIds)) {
|
||||
feature.effectIds = feature.effectIds.filter(id => this.document.effects.has(id));
|
||||
}
|
||||
|
||||
weaponFeatures.splice(idx, 1);
|
||||
await this.document.update({ "system.weaponFeatures": weaponFeatures });
|
||||
}
|
||||
this.render(true);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue