61 lines
2 KiB
JavaScript
61 lines
2 KiB
JavaScript
// SPDX-FileCopyrightText: 2022 Johannes Loher
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import {
|
|
getActorUpdateDataGetter,
|
|
getCompendiumMigrator,
|
|
getItemUpdateDataGetter,
|
|
getSceneUpdateDataGetter,
|
|
migrateActors,
|
|
migrateCompendiums,
|
|
migrateItems,
|
|
migrateScenes,
|
|
} from "./migrationHelpers";
|
|
|
|
/** @type {import("./migration").Migration["migrate"]} */
|
|
async function migrate() {
|
|
await migrateItems(getItemUpdateData);
|
|
await migrateActors(getActorUpdateData);
|
|
await migrateScenes(getSceneUpdateData);
|
|
await migrateCompendiums(migrateCompendium);
|
|
}
|
|
|
|
/** @type {import("./migrationHelpers").EffectUpdateDataGetter} */
|
|
function getEffectUpdateData(effectData) {
|
|
const data = foundry.utils.deepClone(effectData);
|
|
let hasUpdates = false;
|
|
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) {
|
|
return data;
|
|
}
|
|
}
|
|
|
|
const getItemUpdateData = getItemUpdateDataGetter(getEffectUpdateData);
|
|
const getActorUpdateData = getActorUpdateDataGetter(getItemUpdateData, getEffectUpdateData);
|
|
const getSceneUpdateData = getSceneUpdateDataGetter(getActorUpdateData);
|
|
const migrateCompendium = getCompendiumMigrator({ getItemUpdateData, getActorUpdateData, getSceneUpdateData });
|
|
|
|
/** @type {import("./migration").Migration} */
|
|
export const migration = {
|
|
migrate,
|
|
migrateCompendium,
|
|
};
|