ds4/src/migration/002.js
Johannes Loher 7670d7f808
All checks were successful
ci/woodpecker/pr/checks Pipeline was successful
ci/woodpecker/push/checks Pipeline was successful
chore: reformat with 2 spaces
2023-07-10 22:33:01 +02:00

45 lines
1.4 KiB
JavaScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import {
getSceneMigrator,
migrateCollection,
migrateCompendiums,
getCompendiumMigrator,
getActorMigrator,
} from "./migrationHelpers.js";
/** @type {import("./migration.js").Migration["migrate"]} */
async function migrate() {
const itemsResult = await migrateCollection(game.items, migrateItem);
const actorsResult = await migrateCollection(game.actors, migrateActor);
const scenesResult = await migrateCollection(game.scenes, migrateScene);
const compendiumsResult = await migrateCompendiums(migrateCompendium);
return itemsResult === "error" ||
actorsResult === "error" ||
scenesResult === "error" ||
compendiumsResult === "error"
? "error"
: "success";
}
/** @type {import('./migrationHelpers.js').Migrator<Item>} */
async function migrateItem(item) {
if (item.type === "equipment" || item.type === "trinket") {
await item.update({ type: item.type === "equipment" ? "loot" : "equipment" });
}
}
const migrateActor = getActorMigrator(migrateItem);
const migrateScene = getSceneMigrator(migrateActor);
const migrateCompendium = getCompendiumMigrator(
{ migrateItem, migrateActor, migrateScene },
{ migrateToTemplateEarly: false },
);
/** @type {import("./migration.js").Migration} */
export const migration = {
migrate,
migrateCompendium,
};