From e4143446aa893fe7eb60e1702bdeb7757f3a107e Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 8 Jul 2021 07:10:34 +0200 Subject: [PATCH] Fix migration --- src/module/migrations/003.ts | 4 +++- src/module/migrations/004.ts | 17 +++++++++-------- src/module/migrations/migrationHelpers.ts | 6 +++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/module/migrations/003.ts b/src/module/migrations/003.ts index 0735a6e2..1ebc46f8 100644 --- a/src/module/migrations/003.ts +++ b/src/module/migrations/003.ts @@ -22,7 +22,9 @@ export async function migrate(): Promise { function getItemUpdateData(itemData: Partial) { if (!["loot"].includes(itemData.type ?? "")) return undefined; return { - "-=data.equipped": null, + data: { + "-=equipped": null, + }, }; } diff --git a/src/module/migrations/004.ts b/src/module/migrations/004.ts index 6dc396f4..97f3d155 100644 --- a/src/module/migrations/004.ts +++ b/src/module/migrations/004.ts @@ -21,16 +21,17 @@ export async function migrate(): Promise { function getItemUpdateData(itemData: Partial) { if (itemData.type !== "spell") return; - const updateData: Record = { - "-=data.scrollPrice": null, - "data.minimumLevels": { healer: null, wizard: null, sorcerer: null }, - }; - const cooldownDurationUnit: string | undefined = itemData.data?.cooldownDuration.unit; - if (cooldownDurationUnit === "custom") { - updateData["data.cooldownDuration.unit"] = "rounds"; - } + const updateData: Record = { + data: { + "-=scrollPrice": null, + minimumLevels: { healer: null, wizard: null, sorcerer: null }, + cooldownDuration: { + unit: cooldownDurationUnit === "custom" ? "rounds" : cooldownDurationUnit, + }, + }, + }; return updateData; } diff --git a/src/module/migrations/migrationHelpers.ts b/src/module/migrations/migrationHelpers.ts index 16f3b537..dc9aec25 100644 --- a/src/module/migrations/migrationHelpers.ts +++ b/src/module/migrations/migrationHelpers.ts @@ -104,18 +104,18 @@ export function getSceneUpdateDataGetter(getActorUpdateData: ActorUpdateDataGett if (update !== undefined) { ["items" as const, "effects" as const].forEach((embeddedName) => { const embeddedUpdates = update[embeddedName]; - if (embeddedUpdates === undefined || update[embeddedName]?.length !== 0) return; + if (embeddedUpdates === undefined || !embeddedUpdates.length) return; const updates = new Map(embeddedUpdates.flatMap((u) => (u && u._id ? [[u._id, u]] : []))); const originals = t.actorData[embeddedName]; if (!originals) return; originals.forEach((original) => { if (!original._id) return; const update = updates.get(original._id); - if (update) mergeObject(original, update); + if (update) foundry.utils.mergeObject(original, update); }); delete update[embeddedName]; }); - mergeObject(t.actorData, update); + foundry.utils.mergeObject(t.actorData, update); } } return t;