mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
remove unecessary try catch
This commit is contained in:
parent
745e68b4e2
commit
4692596f73
2 changed files with 47 additions and 40 deletions
|
|
@ -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'
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue