ds4/src/migration/001.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import { getSceneMigrator, migrateCollection, migrateCompendiums, getCompendiumMigrator } from "./migrationHelpers.js";
/** @type {import("./migration.js").Migration["migrate"]} */
async function migrate() {
const actorsResult = await migrateCollection(game.actors, migrateActor);
const scenesResult = await migrateCollection(game.scenes, migrateScene);
const compendiumsResult = await migrateCompendiums(migrateCompendium);
return actorsResult === "error" || scenesResult === "error" || compendiumsResult === "error" ? "error" : "success";
}
/** @type {import('./migrationHelpers.js').Migrator<Actor>} */
async function migrateActor(actor) {
await actor.update({
2022-11-21 03:00:46 +01:00
system: {
combatValues: [
"hitPoints",
"defense",
"initiative",
"movement",
"meleeAttack",
"rangedAttack",
"spellcasting",
"targetedSpellcasting",
].reduce((acc, curr) => {
acc[curr] = { "-=base": null };
return acc;
}, {}),
},
});
}
2021-07-08 02:32:25 +02:00
const migrateScene = getSceneMigrator(migrateActor);
const migrateCompendium = getCompendiumMigrator({ migrateActor, migrateScene });
/** @type {import("./migration.js").Migration} */
export const migration = {
migrate,
migrateCompendium,
};