From b22b891aa9fa0d040c3b455ec2e2a68cff9948c6 Mon Sep 17 00:00:00 2001 From: marvin9257 <72580196+marvin9257@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:53:36 -0600 Subject: [PATCH] fix: changing item type in compendium throws error (#1683) This update fixes an issue when changing an item type in a world compendium. The item should stay in the compendium now. Thanks to IanE for finding. --- src/module/sheets/TwodsixItemSheet.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/module/sheets/TwodsixItemSheet.ts b/src/module/sheets/TwodsixItemSheet.ts index 4dfa226e5..e5432b2f2 100644 --- a/src/module/sheets/TwodsixItemSheet.ts +++ b/src/module/sheets/TwodsixItemSheet.ts @@ -190,9 +190,19 @@ export class TwodsixItemSheet extends AbstractTwodsixItemSheet { duplicateItem.system.priorType = this.item.type; duplicateItem.system.type = newType; duplicateItem.type = newType; - const newItem = await TwodsixItem.create(duplicateItem, {renderSheet: true, parent: this.item.parent}); + const options = {renderSheet: true}; + if (this.item.pack) { + options.pack = this.item.pack; + } else { + options.parent = this.item.parent; + } + const newItem = await TwodsixItem.create(duplicateItem, options); if (newItem) { - this.item.delete(); + if (this.item.pack) { + this.item.delete({pack: this.item.pack}); + } else { + this.item.delete(); + } } }