2022-11-21 03:00:46 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
import {
|
2023-07-09 20:53:18 +02:00
|
|
|
getSceneMigrator,
|
|
|
|
migrateCollection,
|
2022-11-21 03:00:46 +01:00
|
|
|
migrateCompendiums,
|
2023-07-09 20:53:18 +02:00
|
|
|
getCompendiumMigrator,
|
|
|
|
getActorMigrator,
|
|
|
|
getItemMigrator,
|
|
|
|
} from "./migrationHelpers.js";
|
2022-11-21 03:00:46 +01:00
|
|
|
|
2023-07-09 20:53:18 +02:00
|
|
|
/** @type {import("./migration.js").Migration["migrate"]} */
|
2022-11-21 03:00:46 +01:00
|
|
|
async function migrate() {
|
2023-07-09 20:53:18 +02:00
|
|
|
await migrateCollection(game.items, migrateItem);
|
|
|
|
await migrateCollection(game.actors, migrateActor);
|
|
|
|
await migrateCollection(game.scenes, migrateScene);
|
2022-11-21 03:00:46 +01:00
|
|
|
await migrateCompendiums(migrateCompendium);
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:53:18 +02:00
|
|
|
/** @type {import('./migrationHelpers.js').Migrator<ActiveEffect>} */
|
|
|
|
async function migrateActiveEffect(activeEffect) {
|
|
|
|
const data = activeEffect.toObject();
|
2022-11-21 03:00:46 +01:00
|
|
|
let hasUpdates = false;
|
2023-07-09 20:53:18 +02:00
|
|
|
|
2022-11-21 03:00:46 +01:00
|
|
|
if ("changes" in data) {
|
|
|
|
for (const change of data.changes) {
|
|
|
|
const newValue = change.value.replaceAll(/@data\./g, "@system.");
|
|
|
|
if (newValue !== change.value) {
|
|
|
|
hasUpdates = true;
|
|
|
|
change.value = newValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {string | undefined} */
|
|
|
|
const condition = data.flags?.ds4?.itemEffectConfig?.condition;
|
|
|
|
if (condition !== undefined) {
|
|
|
|
const newCondition = condition.replaceAll(/(@actor|@item|@effect)\.data/g, "$1.system");
|
|
|
|
if (newCondition !== condition) {
|
|
|
|
hasUpdates = true;
|
|
|
|
data.flags.ds4.itemEffectConfig.condition = newCondition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasUpdates) {
|
2023-07-09 20:53:18 +02:00
|
|
|
await activeEffect.update(data);
|
2022-11-21 03:00:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:53:18 +02:00
|
|
|
const migrateItem = getItemMigrator(migrateActiveEffect);
|
|
|
|
const migrateActor = getActorMigrator(migrateItem, migrateActiveEffect);
|
|
|
|
const migrateScene = getSceneMigrator(migrateActor);
|
|
|
|
const migrateCompendium = getCompendiumMigrator({ migrateItem, migrateActor, migrateScene });
|
2022-11-21 03:00:46 +01:00
|
|
|
|
2023-07-09 20:53:18 +02:00
|
|
|
/** @type {import("./migration.js").Migration} */
|
2022-11-21 03:00:46 +01:00
|
|
|
export const migration = {
|
|
|
|
migrate,
|
|
|
|
migrateCompendium,
|
|
|
|
};
|