Fix migration

This commit is contained in:
Johannes Loher 2021-07-08 07:10:34 +02:00
parent b694f20e1c
commit e4143446aa
3 changed files with 15 additions and 12 deletions

View file

@ -22,7 +22,9 @@ export async function migrate(): Promise<void> {
function getItemUpdateData(itemData: Partial<foundry.data.ItemData["_source"]>) {
if (!["loot"].includes(itemData.type ?? "")) return undefined;
return {
"-=data.equipped": null,
data: {
"-=equipped": null,
},
};
}

View file

@ -21,16 +21,17 @@ export async function migrate(): Promise<void> {
function getItemUpdateData(itemData: Partial<foundry.data.ItemData["_source"]>) {
if (itemData.type !== "spell") return;
const updateData: Record<string, unknown> = {
"-=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<string, unknown> = {
data: {
"-=scrollPrice": null,
minimumLevels: { healer: null, wizard: null, sorcerer: null },
cooldownDuration: {
unit: cooldownDurationUnit === "custom" ? "rounds" : cooldownDurationUnit,
},
},
};
return updateData;
}

View file

@ -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;