From bdea7de7f3f505a021ab881cef2360bd83e7d7aa Mon Sep 17 00:00:00 2001
From: Johannes Loher <johannes.loher@fg4f.de>
Date: Wed, 22 Sep 2021 02:34:50 +0200
Subject: [PATCH] fix: make it possible to add embedded effects/items to items
 and actors in packs

---
 src/module/active-effect.ts            | 7 ++-----
 src/module/actor/sheets/actor-sheet.ts | 4 ++--
 src/module/item/item-sheet.ts          | 2 +-
 3 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/module/active-effect.ts b/src/module/active-effect.ts
index 8a029c4..965f9f8 100644
--- a/src/module/active-effect.ts
+++ b/src/module/active-effect.ts
@@ -95,14 +95,11 @@ export class DS4ActiveEffect extends ActiveEffect {
      * @param context The context for the creation of the effect, requiring a parent {@link DS4Actor} or {@link DS4Item}.
      * @returns A promise that resolved to the created effect or udifined of the creation was prevented.
      */
-    static async createDefault(
-        context: DocumentModificationContext & { parent: DS4Actor | DS4Item },
-    ): Promise<DS4ActiveEffect | undefined> {
+    static async createDefault(parent: DS4Actor | DS4Item): Promise<DS4ActiveEffect[]> {
         const createData = {
             label: getGame().i18n.localize(`DS4.NewEffectLabel`),
             icon: this.FALLBACK_ICON,
         };
-
-        return this.create(createData, context);
+        return parent.createEmbeddedDocuments("ActiveEffect", [createData]) as Promise<DS4ActiveEffect[]>;
     }
 }
diff --git a/src/module/actor/sheets/actor-sheet.ts b/src/module/actor/sheets/actor-sheet.ts
index e192e49..58651f4 100644
--- a/src/module/actor/sheets/actor-sheet.ts
+++ b/src/module/actor/sheets/actor-sheet.ts
@@ -141,7 +141,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
             type: type,
             data: data,
         };
-        Item.create(itemData, { parent: this.actor });
+        this.actor.createEmbeddedDocuments("Item", [itemData]);
     }
 
     /**
@@ -205,7 +205,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
      * @param event - The originating click event
      */
     protected onCreateEffect(): void {
-        DS4ActiveEffect.createDefault({ parent: this.actor });
+        DS4ActiveEffect.createDefault(this.actor);
     }
 
     /**
diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts
index 943ac08..4c535c7 100644
--- a/src/module/item/item-sheet.ts
+++ b/src/module/item/item-sheet.ts
@@ -99,7 +99,7 @@ export class DS4ItemSheet extends ItemSheet<ItemSheet.Options, DS4ItemSheetData>
      * Create a new ActiveEffect for the item using default data.
      */
     protected createActiveEffect(): void {
-        DS4ActiveEffect.createDefault({ parent: this.item });
+        DS4ActiveEffect.createDefault(this.item);
     }
 }