From 4692596f738ba55087c8a01f7b9f2db66879a7e3 Mon Sep 17 00:00:00 2001 From: psitacus Date: Wed, 9 Jul 2025 00:25:04 -0600 Subject: [PATCH] remove unecessary try catch --- module/applications/sheets/items/armor.mjs | 67 +++++++++++++-------- module/applications/sheets/items/weapon.mjs | 20 ++---- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/module/applications/sheets/items/armor.mjs b/module/applications/sheets/items/armor.mjs index 30493038..8882185d 100644 --- a/module/applications/sheets/items/armor.mjs +++ b/module/applications/sheets/items/armor.mjs @@ -1,5 +1,4 @@ import DHBaseItemSheet from '../api/base-item.mjs'; -import { copyAttachmentEffectsToActor, removeAttachmentEffectsFromActor } from '../../../helpers/attachmentHelper.mjs'; export default class ArmorSheet extends DHBaseItemSheet { /**@inheritdoc */ @@ -62,20 +61,12 @@ export default class ArmorSheet extends DHBaseItemSheet { const attachedUUIDs = this.document.system.attached || []; context.attachedItems = await Promise.all( attachedUUIDs.map(async uuid => { - try { - const item = await fromUuid(uuid); - return { - uuid: uuid, - name: item?.name || 'Unknown Item', - img: item?.img || 'icons/svg/item-bag.svg' - }; - } catch (error) { - return { - uuid: uuid, - name: 'Unknown Item', - img: 'icons/svg/item-bag.svg' - }; - } + const item = await fromUuid(uuid); + return { + uuid: uuid, + name: item?.name || 'Unknown Item', + img: item?.img || 'icons/svg/item-bag.svg' + }; }) ); break; @@ -131,12 +122,28 @@ export default class ArmorSheet extends DHBaseItemSheet { // Both attachment-only and regular effects should be copied when attached const actor = this.document.parent; if (actor && item.effects.size > 0 && this.document.system.equipped) { - await copyAttachmentEffectsToActor({ - parentItem: this.document, - attachedItem: item, - attachedUuid: newUUID, - parentType: 'armor' - }); + const effectsToCreate = []; + for (const effect of item.effects) { + // Copy ALL effects when item is attached - attachment-only flag only matters for non-attached items + const effectData = effect.toObject(); + 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 - await removeAttachmentEffectsFromActor({ - parentItem: this.document, - attachedUuid: uuid, - parentType: 'armor' - }); + const actor = this.document.parent; + if (actor) { + const effectsToRemove = actor.effects.filter(effect => { + 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)); + } + } } } diff --git a/module/applications/sheets/items/weapon.mjs b/module/applications/sheets/items/weapon.mjs index ee14e071..160d1a10 100644 --- a/module/applications/sheets/items/weapon.mjs +++ b/module/applications/sheets/items/weapon.mjs @@ -62,20 +62,12 @@ export default class WeaponSheet extends DHBaseItemSheet { const attachedUUIDs = this.document.system.attached || []; context.attachedItems = await Promise.all( attachedUUIDs.map(async uuid => { - try { - const item = await fromUuid(uuid); - return { - uuid: uuid, - name: item?.name || 'Unknown Item', - img: item?.img || 'icons/svg/item-bag.svg' - }; - } catch (error) { - return { - uuid: uuid, - name: 'Unknown Item', - img: 'icons/svg/item-bag.svg' - }; - } + const item = await fromUuid(uuid); + return { + uuid: uuid, + name: item?.name || 'Unknown Item', + img: item?.img || 'icons/svg/item-bag.svg' + }; }) ); break;