2023-06-25 23:55:08 +02:00
|
|
|
// SPDX-FileCopyrightText: 2023 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
import {
|
2023-07-10 22:23:13 +02:00
|
|
|
getSceneMigrator,
|
|
|
|
migrateCollection,
|
|
|
|
migrateCompendiums,
|
|
|
|
getCompendiumMigrator,
|
|
|
|
getActorMigrator,
|
2023-06-25 23:55:08 +02:00
|
|
|
} from "./migrationHelpers.js";
|
|
|
|
|
|
|
|
/** @type {import("./migration.js").Migration["migrate"]} */
|
|
|
|
async function migrate() {
|
2023-07-10 22:23:13 +02:00
|
|
|
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";
|
2023-06-25 23:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const itemIdRegex = /Item\.([a-zA-Z0-9]+)/;
|
|
|
|
|
|
|
|
/** @type {import('./migrationHelpers.js').Migrator<ActiveEffect>} */
|
|
|
|
async function migrateActiveEffect(activeEffect) {
|
2023-07-10 22:23:13 +02:00
|
|
|
if (activeEffect.parent instanceof Actor) {
|
|
|
|
const itemId = activeEffect.origin?.match(itemIdRegex)?.[1];
|
|
|
|
if (activeEffect.parent.items.has(itemId)) {
|
|
|
|
await activeEffect.delete();
|
2023-06-25 23:55:08 +02:00
|
|
|
}
|
2023-07-10 22:23:13 +02:00
|
|
|
}
|
2023-06-25 23:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const migrateActor = getActorMigrator(undefined, migrateActiveEffect);
|
|
|
|
const migrateScene = getSceneMigrator(migrateActor);
|
|
|
|
const migrateCompendium = getCompendiumMigrator({ migrateActor, migrateScene });
|
|
|
|
|
|
|
|
/** @type {import("./migration.js").Migration} */
|
|
|
|
export const migration = {
|
2023-07-10 22:23:13 +02:00
|
|
|
migrate,
|
|
|
|
migrateCompendium,
|
2023-06-25 23:55:08 +02:00
|
|
|
};
|