ds4/src/module/migrations/001.ts

36 lines
1,000 B
TypeScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
2021-07-07 19:22:35 +02:00
import { getGame } from "../helpers";
import logger from "../logger";
export async function migrate(): Promise<void> {
2021-07-07 19:22:35 +02:00
for (const a of getGame().actors?.contents ?? []) {
const updateData = getActorUpdateData();
logger.info(`Migrating actor ${a.name}`);
2021-06-30 05:00:23 +02:00
await a.update(updateData);
}
}
function getActorUpdateData(): Record<string, unknown> {
const updateData = {
data: {
combatValues: [
"hitPoints",
"defense",
"initiative",
"movement",
"meleeAttack",
"rangedAttack",
"spellcasting",
"targetedSpellcasting",
2021-02-07 13:51:20 +01:00
].reduce((acc: Partial<Record<string, { "-=base": null }>>, curr) => {
acc[curr] = { "-=base": null };
return acc;
}, {}),
},
};
return updateData;
}