remove unecessary try catch

This commit is contained in:
psitacus 2025-07-09 00:25:04 -06:00
parent 745e68b4e2
commit 4692596f73
2 changed files with 47 additions and 40 deletions

View file

@ -1,5 +1,4 @@
import DHBaseItemSheet from '../api/base-item.mjs'; import DHBaseItemSheet from '../api/base-item.mjs';
import { copyAttachmentEffectsToActor, removeAttachmentEffectsFromActor } from '../../../helpers/attachmentHelper.mjs';
export default class ArmorSheet extends DHBaseItemSheet { export default class ArmorSheet extends DHBaseItemSheet {
/**@inheritdoc */ /**@inheritdoc */
@ -62,20 +61,12 @@ export default class ArmorSheet extends DHBaseItemSheet {
const attachedUUIDs = this.document.system.attached || []; const attachedUUIDs = this.document.system.attached || [];
context.attachedItems = await Promise.all( context.attachedItems = await Promise.all(
attachedUUIDs.map(async uuid => { attachedUUIDs.map(async uuid => {
try { const item = await fromUuid(uuid);
const item = await fromUuid(uuid); return {
return { uuid: uuid,
uuid: uuid, name: item?.name || 'Unknown Item',
name: item?.name || 'Unknown Item', img: item?.img || 'icons/svg/item-bag.svg'
img: item?.img || 'icons/svg/item-bag.svg' };
};
} catch (error) {
return {
uuid: uuid,
name: 'Unknown Item',
img: 'icons/svg/item-bag.svg'
};
}
}) })
); );
break; break;
@ -131,12 +122,28 @@ export default class ArmorSheet extends DHBaseItemSheet {
// Both attachment-only and regular effects should be copied when attached // Both attachment-only and regular effects should be copied when attached
const actor = this.document.parent; const actor = this.document.parent;
if (actor && item.effects.size > 0 && this.document.system.equipped) { if (actor && item.effects.size > 0 && this.document.system.equipped) {
await copyAttachmentEffectsToActor({ const effectsToCreate = [];
parentItem: this.document, for (const effect of item.effects) {
attachedItem: item, // Copy ALL effects when item is attached - attachment-only flag only matters for non-attached items
attachedUuid: newUUID, const effectData = effect.toObject();
parentType: 'armor' effectData.origin = `${this.document.uuid}:${newUUID}`; // Track which armor and which item this came from
}); effectData.flags = {
...effectData.flags,
daggerheart: {
...effectData.flags?.daggerheart,
attachmentSource: {
armorUuid: this.document.uuid,
itemUuid: newUUID,
originalEffectId: effect.id
}
}
};
effectsToCreate.push(effectData);
}
if (effectsToCreate.length > 0) {
await actor.createEmbeddedDocuments('ActiveEffect', effectsToCreate);
}
} }
} }
@ -155,10 +162,18 @@ export default class ArmorSheet extends DHBaseItemSheet {
}); });
// Remove any effects on the actor that came from this attached item // Remove any effects on the actor that came from this attached item
await removeAttachmentEffectsFromActor({ const actor = this.document.parent;
parentItem: this.document, if (actor) {
attachedUuid: uuid, const effectsToRemove = actor.effects.filter(effect => {
parentType: 'armor' const attachmentSource = effect.flags?.daggerheart?.attachmentSource;
}); return attachmentSource &&
attachmentSource.armorUuid === this.document.uuid &&
attachmentSource.itemUuid === uuid;
});
if (effectsToRemove.length > 0) {
await actor.deleteEmbeddedDocuments('ActiveEffect', effectsToRemove.map(e => e.id));
}
}
} }
} }

View file

@ -62,20 +62,12 @@ export default class WeaponSheet extends DHBaseItemSheet {
const attachedUUIDs = this.document.system.attached || []; const attachedUUIDs = this.document.system.attached || [];
context.attachedItems = await Promise.all( context.attachedItems = await Promise.all(
attachedUUIDs.map(async uuid => { attachedUUIDs.map(async uuid => {
try { const item = await fromUuid(uuid);
const item = await fromUuid(uuid); return {
return { uuid: uuid,
uuid: uuid, name: item?.name || 'Unknown Item',
name: item?.name || 'Unknown Item', img: item?.img || 'icons/svg/item-bag.svg'
img: item?.img || 'icons/svg/item-bag.svg' };
};
} catch (error) {
return {
uuid: uuid,
name: 'Unknown Item',
img: 'icons/svg/item-bag.svg'
};
}
}) })
); );
break; break;