ds4/src/migration/004.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
2021-07-08 02:32:25 +02:00
import {
2023-07-10 22:23:13 +02:00
getSceneMigrator,
migrateCollection,
migrateCompendiums,
getCompendiumMigrator,
getActorMigrator,
} from "./migrationHelpers.js";
2021-07-08 02:32:25 +02:00
/** @type {import("./migration.js").Migration["migrate"]} */
async function migrate() {
2023-07-10 22:23:13 +02:00
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";
2021-07-08 02:32:25 +02:00
}
/** @type {import('./migrationHelpers.js').Migrator<Item>} */
async function migrateItem(item) {
2023-07-10 22:23:13 +02:00
if (item.type === "spell") {
const cooldownDurationUnit = item.system?.cooldownDuration.unit;
await item.update({
system: {
"-=scrollPrice": null,
minimumLevels: { healer: null, wizard: null, sorcerer: null },
cooldownDuration: {
unit: cooldownDurationUnit === "custom" ? "rounds" : cooldownDurationUnit,
},
},
});
}
2023-07-10 22:23:13 +02:00
return updateData;
2021-07-08 02:32:25 +02:00
}
const migrateActor = getActorMigrator(migrateItem);
const migrateScene = getSceneMigrator(migrateActor);
const migrateCompendium = getCompendiumMigrator({ migrateItem, migrateActor, migrateScene });
/** @type {import("./migration.js").Migration} */
export const migration = {
2023-07-10 22:23:13 +02:00
migrate,
migrateCompendium,
};