refactor: improve embedded document creation

This commit is contained in:
Johannes Loher 2021-09-22 12:32:18 +02:00
parent eb2bbe1282
commit 8f3a72a7f4
2 changed files with 5 additions and 4 deletions

View file

@ -92,14 +92,15 @@ export class DS4ActiveEffect extends ActiveEffect {
/**
* Create a new {@link DS4ActiveEffect} using default data.
*
* @param context The context for the creation of the effect, requiring a parent {@link DS4Actor} or {@link DS4Item}.
* @param parent The parent {@link DS4Actor} or {@link DS4Item} of the effect.
* @returns A promise that resolved to the created effect or udifined of the creation was prevented.
*/
static async createDefault(parent: DS4Actor | DS4Item): Promise<DS4ActiveEffect[]> {
static async createDefault(parent: DS4Actor | DS4Item): Promise<DS4ActiveEffect | undefined> {
const createData = {
label: getGame().i18n.localize(`DS4.NewEffectLabel`),
icon: this.FALLBACK_ICON,
};
return parent.createEmbeddedDocuments("ActiveEffect", [createData]) as Promise<DS4ActiveEffect[]>;
return this.create(createData, { parent, pack: parent.pack ?? undefined });
}
}

View file

@ -141,7 +141,7 @@ export class DS4ActorSheet extends ActorSheet<ActorSheet.Options, DS4ActorSheetD
type: type,
data: data,
};
this.actor.createEmbeddedDocuments("Item", [itemData]);
Item.create(itemData, { parent: this.actor, pack: this.actor.pack ?? undefined });
}
/**