temporary comment migrations
This commit is contained in:
parent
76f42fe280
commit
446340c064
4 changed files with 410 additions and 410 deletions
|
@ -4,9 +4,9 @@
|
|||
|
||||
import logger from "./logger";
|
||||
import { migrate as migrate001 } from "./migrations/001";
|
||||
import { migrate as migrate002 } from "./migrations/002";
|
||||
import { migrate as migrate003 } from "./migrations/003";
|
||||
import { migrate as migrate004 } from "./migrations/004";
|
||||
// import { migrate as migrate002 } from "./migrations/002";
|
||||
// import { migrate as migrate003 } from "./migrations/003";
|
||||
// import { migrate as migrate004 } from "./migrations/004";
|
||||
|
||||
import notifications from "./ui/notifications";
|
||||
|
||||
|
@ -78,7 +78,7 @@ function getTargetMigrationVersion(): number {
|
|||
return migrations.length;
|
||||
}
|
||||
|
||||
const migrations: Array<() => Promise<void>> = [migrate001, migrate002, migrate003, migrate004];
|
||||
const migrations: Array<() => Promise<void>> = [migrate001 /* migrate002, migrate003, migrate004 */];
|
||||
|
||||
function isFirstWorldStart(migrationVersion: number): boolean {
|
||||
return migrationVersion < 0;
|
||||
|
|
|
@ -4,151 +4,151 @@
|
|||
|
||||
import logger from "../logger";
|
||||
|
||||
export async function migrate(): Promise<void> {
|
||||
await migrateItems();
|
||||
await migrateActors();
|
||||
await migrateScenes();
|
||||
await migrateCompendiums();
|
||||
}
|
||||
// export async function migrate(): Promise<void> {
|
||||
// await migrateItems();
|
||||
// await migrateActors();
|
||||
// await migrateScenes();
|
||||
// await migrateCompendiums();
|
||||
// }
|
||||
|
||||
async function migrateItems() {
|
||||
for (const item of game.items?.contents ?? []) {
|
||||
try {
|
||||
const updateData = getItemUpdateData(item.toObject());
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
await item.update(updateData), { enforceTypes: false };
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateItems() {
|
||||
// for (const item of game.items?.contents ?? []) {
|
||||
// try {
|
||||
// const updateData = getItemUpdateData(item.toObject());
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
// await item.update(updateData), { enforceTypes: false };
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getItemUpdateData(itemData: foundry.data.ItemData["_source"]) {
|
||||
if (!["equipment", "trinket"].includes(itemData.type ?? "")) return undefined;
|
||||
return { type: itemData.type === "equipment" ? ("loot" as const) : ("equipment" as const) };
|
||||
}
|
||||
// function getItemUpdateData(itemData: foundry.data.ItemData["_source"]) {
|
||||
// if (!["equipment", "trinket"].includes(itemData.type ?? "")) return undefined;
|
||||
// return { type: itemData.type === "equipment" ? ("loot" as const) : ("equipment" as const) };
|
||||
// }
|
||||
|
||||
async function migrateActors() {
|
||||
for (const actor of game.actors?.contents ?? []) {
|
||||
try {
|
||||
const updateData = getActorUpdateData(actor.toObject());
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
await actor.update(updateData);
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateActors() {
|
||||
// for (const actor of game.actors?.contents ?? []) {
|
||||
// try {
|
||||
// const updateData = getActorUpdateData(actor.toObject());
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
// await actor.update(updateData);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getActorUpdateData(actorData: foundry.data.ActorData["_source"]) {
|
||||
let hasItemUpdates = false;
|
||||
const items = actorData.items.map((itemData: foundry.data.ItemData["_source"]) => {
|
||||
const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
if (update) {
|
||||
hasItemUpdates = true;
|
||||
return { ...itemData, ...update };
|
||||
} else {
|
||||
return itemData;
|
||||
}
|
||||
});
|
||||
return hasItemUpdates ? { items } : undefined;
|
||||
}
|
||||
// function getActorUpdateData(actorData: foundry.data.ActorData["_source"]) {
|
||||
// let hasItemUpdates = false;
|
||||
// const items = actorData.items.map((itemData: foundry.data.ItemData["_source"]) => {
|
||||
// const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
// if (update) {
|
||||
// hasItemUpdates = true;
|
||||
// return { ...itemData, ...update };
|
||||
// } else {
|
||||
// return itemData;
|
||||
// }
|
||||
// });
|
||||
// return hasItemUpdates ? { items } : undefined;
|
||||
// }
|
||||
|
||||
async function migrateScenes() {
|
||||
for (const scene of game.scenes?.contents ?? []) {
|
||||
try {
|
||||
const updateData = getSceneUpdateData(scene.toObject());
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
await scene.update(updateData);
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Scene document ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateScenes() {
|
||||
// for (const scene of game.scenes?.contents ?? []) {
|
||||
// try {
|
||||
// const updateData = getSceneUpdateData(scene.toObject());
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
// await scene.update(updateData);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Scene document ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getSceneUpdateData(scene: Scene) {
|
||||
let hasTokenUpdates = false;
|
||||
// TODO: Continue from here
|
||||
const tokens = scene.tokens.map((tokenData: foundry.data.TokenData["_source"]) => {
|
||||
if (!tokenData.actorId || tokenData.actorLink) {
|
||||
tokenData.actorData = {};
|
||||
} else if (!game.actors?.has(tokenData.actorId)) {
|
||||
tokenData.actorId = null;
|
||||
tokenData.actorData = {};
|
||||
} else if (!tokenData.actorLink) {
|
||||
const actorData = duplicate(tokenData.actorData);
|
||||
actorData.type = token.actor?.type;
|
||||
}
|
||||
// function getSceneUpdateData(scene: Scene) {
|
||||
// let hasTokenUpdates = false;
|
||||
// // TODO: Continue from here
|
||||
// const tokens = scene.tokens.map((tokenData: foundry.data.TokenData["_source"]) => {
|
||||
// if (!tokenData.actorId || tokenData.actorLink) {
|
||||
// tokenData.actorData = {};
|
||||
// } else if (!game.actors?.has(tokenData.actorId)) {
|
||||
// tokenData.actorId = null;
|
||||
// tokenData.actorData = {};
|
||||
// } else if (!tokenData.actorLink) {
|
||||
// const actorData = duplicate(tokenData.actorData);
|
||||
// actorData.type = token.actor?.type;
|
||||
// }
|
||||
|
||||
if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
return tokenData;
|
||||
}
|
||||
const token = new Token(tokenData);
|
||||
if (!token.actor) {
|
||||
tokenData.actorId = null as unknown as string;
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
} else if (!tokenData.actorLink) {
|
||||
const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
hasTokenUpdates = true;
|
||||
}
|
||||
return tokenData;
|
||||
});
|
||||
if (!hasTokenUpdates) return undefined;
|
||||
return hasTokenUpdates ? { tokens } : undefined;
|
||||
}
|
||||
// if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// return tokenData;
|
||||
// }
|
||||
// const token = new Token(tokenData);
|
||||
// if (!token.actor) {
|
||||
// tokenData.actorId = null as unknown as string;
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// } else if (!tokenData.actorLink) {
|
||||
// const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
// tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
// hasTokenUpdates = true;
|
||||
// }
|
||||
// return tokenData;
|
||||
// });
|
||||
// if (!hasTokenUpdates) return undefined;
|
||||
// return hasTokenUpdates ? { tokens } : undefined;
|
||||
// }
|
||||
|
||||
async function migrateCompendiums() {
|
||||
for (const compendium of game.packs ?? []) {
|
||||
if (compendium.metadata.package !== "world") continue;
|
||||
if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
await migrateCompendium(compendium);
|
||||
}
|
||||
}
|
||||
// async function migrateCompendiums() {
|
||||
// for (const compendium of game.packs ?? []) {
|
||||
// if (compendium.metadata.package !== "world") continue;
|
||||
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
// await migrateCompendium(compendium);
|
||||
// }
|
||||
// }
|
||||
|
||||
async function migrateCompendium(compendium: Compendium) {
|
||||
const entityName = compendium.metadata.entity;
|
||||
if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
const wasLocked = compendium.locked;
|
||||
await compendium.configure({ locked: false });
|
||||
// async function migrateCompendium(compendium: Compendium) {
|
||||
// const entityName = compendium.metadata.entity;
|
||||
// if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
// const wasLocked = compendium.locked;
|
||||
// await compendium.configure({ locked: false });
|
||||
|
||||
const content = await compendium.getContent();
|
||||
// const content = await compendium.getContent();
|
||||
|
||||
for (const entity of content) {
|
||||
try {
|
||||
const getUpdateData = (entity: Entity) => {
|
||||
switch (entityName) {
|
||||
case "Item":
|
||||
return getItemUpdateData(entity._data);
|
||||
case "Actor":
|
||||
return getActorUpdateData(entity._data);
|
||||
case "Scene":
|
||||
return getSceneUpdateData(entity._data as Scene.Data);
|
||||
}
|
||||
};
|
||||
const updateData = getUpdateData(entity);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
// for (const entity of content) {
|
||||
// try {
|
||||
// const getUpdateData = (entity: Entity) => {
|
||||
// switch (entityName) {
|
||||
// case "Item":
|
||||
// return getItemUpdateData(entity._data);
|
||||
// case "Actor":
|
||||
// return getActorUpdateData(entity._data);
|
||||
// case "Scene":
|
||||
// return getSceneUpdateData(entity._data as Scene.Data);
|
||||
// }
|
||||
// };
|
||||
// const updateData = getUpdateData(entity);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
// await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
await compendium.migrate({});
|
||||
await compendium.configure({ locked: wasLocked });
|
||||
}
|
||||
// await compendium.migrate({});
|
||||
// await compendium.configure({ locked: wasLocked });
|
||||
// }
|
||||
|
|
|
@ -4,144 +4,144 @@
|
|||
|
||||
import logger from "../logger";
|
||||
|
||||
export async function migrate(): Promise<void> {
|
||||
await migrateItems();
|
||||
await migrateActors();
|
||||
await migrateScenes();
|
||||
await migrateCompendiums();
|
||||
}
|
||||
// export async function migrate(): Promise<void> {
|
||||
// await migrateItems();
|
||||
// await migrateActors();
|
||||
// await migrateScenes();
|
||||
// await migrateCompendiums();
|
||||
// }
|
||||
|
||||
async function migrateItems() {
|
||||
for (const item of game.items?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getItemUpdateData(item._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
await item.update(updateData), { enforceTypes: false };
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateItems() {
|
||||
// for (const item of game.items?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getItemUpdateData(item._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
// await item.update(updateData), { enforceTypes: false };
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getItemUpdateData(itemData: DeepPartial<Item.Data>) {
|
||||
if (!["loot"].includes(itemData.type ?? "")) return undefined;
|
||||
return {
|
||||
data: {
|
||||
"-=equipped": null,
|
||||
},
|
||||
};
|
||||
}
|
||||
// function getItemUpdateData(itemData: DeepPartial<Item.Data>) {
|
||||
// if (!["loot"].includes(itemData.type ?? "")) return undefined;
|
||||
// return {
|
||||
// data: {
|
||||
// "-=equipped": null,
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
|
||||
async function migrateActors() {
|
||||
for (const actor of game.actors?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getActorUpdateData(actor._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
await actor.update(updateData, { enforceTypes: false });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateActors() {
|
||||
// for (const actor of game.actors?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getActorUpdateData(actor._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
// await actor.update(updateData, { enforceTypes: false });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
||||
let hasItemUpdates = false;
|
||||
const items = actorData.items?.map((itemData) => {
|
||||
const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
if (update) {
|
||||
hasItemUpdates = true;
|
||||
return mergeObject(itemData, update, { enforceTypes: false, inplace: false });
|
||||
} else {
|
||||
return itemData;
|
||||
}
|
||||
});
|
||||
return hasItemUpdates ? { items } : undefined;
|
||||
}
|
||||
// function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
||||
// let hasItemUpdates = false;
|
||||
// const items = actorData.items?.map((itemData) => {
|
||||
// const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
// if (update) {
|
||||
// hasItemUpdates = true;
|
||||
// return mergeObject(itemData, update, { enforceTypes: false, inplace: false });
|
||||
// } else {
|
||||
// return itemData;
|
||||
// }
|
||||
// });
|
||||
// return hasItemUpdates ? { items } : undefined;
|
||||
// }
|
||||
|
||||
async function migrateScenes() {
|
||||
for (const scene of game.scenes?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getSceneUpdateData(scene._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
await scene.update(updateData, { enforceTypes: false });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Scene entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateScenes() {
|
||||
// for (const scene of game.scenes?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getSceneUpdateData(scene._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
// await scene.update(updateData, { enforceTypes: false });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Scene entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getSceneUpdateData(sceneData: Scene.Data) {
|
||||
let hasTokenUpdates = false;
|
||||
const tokens = sceneData.tokens.map((tokenData) => {
|
||||
if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
return tokenData;
|
||||
}
|
||||
const token = new Token(tokenData);
|
||||
if (!token.actor) {
|
||||
tokenData.actorId = null as unknown as string;
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
} else if (!tokenData.actorLink) {
|
||||
const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
hasTokenUpdates = true;
|
||||
}
|
||||
return tokenData;
|
||||
});
|
||||
if (!hasTokenUpdates) return undefined;
|
||||
return hasTokenUpdates ? { tokens } : undefined;
|
||||
}
|
||||
// function getSceneUpdateData(sceneData: Scene.Data) {
|
||||
// let hasTokenUpdates = false;
|
||||
// const tokens = sceneData.tokens.map((tokenData) => {
|
||||
// if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// return tokenData;
|
||||
// }
|
||||
// const token = new Token(tokenData);
|
||||
// if (!token.actor) {
|
||||
// tokenData.actorId = null as unknown as string;
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// } else if (!tokenData.actorLink) {
|
||||
// const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
// tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
// hasTokenUpdates = true;
|
||||
// }
|
||||
// return tokenData;
|
||||
// });
|
||||
// if (!hasTokenUpdates) return undefined;
|
||||
// return hasTokenUpdates ? { tokens } : undefined;
|
||||
// }
|
||||
|
||||
async function migrateCompendiums() {
|
||||
for (const compendium of game.packs ?? []) {
|
||||
if (compendium.metadata.package !== "world") continue;
|
||||
if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
await migrateCompendium(compendium);
|
||||
}
|
||||
}
|
||||
// async function migrateCompendiums() {
|
||||
// for (const compendium of game.packs ?? []) {
|
||||
// if (compendium.metadata.package !== "world") continue;
|
||||
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
// await migrateCompendium(compendium);
|
||||
// }
|
||||
// }
|
||||
|
||||
async function migrateCompendium(compendium: Compendium) {
|
||||
const entityName = compendium.metadata.entity;
|
||||
if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
const wasLocked = compendium.locked;
|
||||
await compendium.configure({ locked: false });
|
||||
// async function migrateCompendium(compendium: Compendium) {
|
||||
// const entityName = compendium.metadata.entity;
|
||||
// if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
// const wasLocked = compendium.locked;
|
||||
// await compendium.configure({ locked: false });
|
||||
|
||||
const content = await compendium.getContent();
|
||||
// const content = await compendium.getContent();
|
||||
|
||||
for (const entity of content) {
|
||||
try {
|
||||
const getUpdateData = (entity: Entity) => {
|
||||
switch (entityName) {
|
||||
case "Item":
|
||||
return getItemUpdateData(entity._data);
|
||||
case "Actor":
|
||||
return getActorUpdateData(entity._data);
|
||||
case "Scene":
|
||||
return getSceneUpdateData(entity._data as Scene.Data);
|
||||
}
|
||||
};
|
||||
const updateData = getUpdateData(entity);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
// for (const entity of content) {
|
||||
// try {
|
||||
// const getUpdateData = (entity: Entity) => {
|
||||
// switch (entityName) {
|
||||
// case "Item":
|
||||
// return getItemUpdateData(entity._data);
|
||||
// case "Actor":
|
||||
// return getActorUpdateData(entity._data);
|
||||
// case "Scene":
|
||||
// return getSceneUpdateData(entity._data as Scene.Data);
|
||||
// }
|
||||
// };
|
||||
// const updateData = getUpdateData(entity);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
// await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
await compendium.migrate({});
|
||||
await compendium.configure({ locked: wasLocked });
|
||||
}
|
||||
// await compendium.migrate({});
|
||||
// await compendium.configure({ locked: wasLocked });
|
||||
// }
|
||||
|
|
|
@ -5,154 +5,154 @@
|
|||
import { DS4SpellDataSourceData } from "../item/item-data-source";
|
||||
import logger from "../logger";
|
||||
|
||||
export async function migrate(): Promise<void> {
|
||||
await migrateItems();
|
||||
await migrateActors();
|
||||
await migrateScenes();
|
||||
await migrateCompendiums();
|
||||
}
|
||||
// export async function migrate(): Promise<void> {
|
||||
// await migrateItems();
|
||||
// await migrateActors();
|
||||
// await migrateScenes();
|
||||
// await migrateCompendiums();
|
||||
// }
|
||||
|
||||
async function migrateItems() {
|
||||
for (const item of game.items?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getItemUpdateData(item._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
await item.update(updateData), { enforceTypes: false };
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateItems() {
|
||||
// for (const item of game.items?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getItemUpdateData(item._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Item entity ${item.name} (${item.id})`);
|
||||
// await item.update(updateData), { enforceTypes: false };
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Item entity ${item.name} (${item.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getItemUpdateData(itemData: DeepPartial<Item.Data>) {
|
||||
if (!["spell"].includes(itemData.type ?? "")) return undefined;
|
||||
const updateData: Record<string, unknown> = {
|
||||
"-=data.scrollPrice": null,
|
||||
"data.minimumLevels": { healer: null, wizard: null, sorcerer: null },
|
||||
};
|
||||
if (((itemData.data as DS4SpellDataSourceData).cooldownDuration.unit as string) === "custom") {
|
||||
updateData["data.cooldownDuration.unit"] = "rounds";
|
||||
}
|
||||
return updateData;
|
||||
}
|
||||
// function getItemUpdateData(itemData: DeepPartial<Item.Data>) {
|
||||
// if (!["spell"].includes(itemData.type ?? "")) return undefined;
|
||||
// const updateData: Record<string, unknown> = {
|
||||
// "-=data.scrollPrice": null,
|
||||
// "data.minimumLevels": { healer: null, wizard: null, sorcerer: null },
|
||||
// };
|
||||
// if (((itemData.data as DS4SpellDataSourceData).cooldownDuration.unit as string) === "custom") {
|
||||
// updateData["data.cooldownDuration.unit"] = "rounds";
|
||||
// }
|
||||
// return updateData;
|
||||
// }
|
||||
|
||||
async function migrateActors() {
|
||||
for (const actor of game.actors?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getActorUpdateData(actor._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
await actor.update(updateData, { enforceTypes: false });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateActors() {
|
||||
// for (const actor of game.actors?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getActorUpdateData(actor._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Actor entity ${actor.name} (${actor.id})`);
|
||||
// await actor.update(updateData, { enforceTypes: false });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Actor entity ${actor.name} (${actor.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
||||
let hasItemUpdates = false;
|
||||
const items = actorData.items?.map((itemData) => {
|
||||
const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
if (update) {
|
||||
hasItemUpdates = true;
|
||||
return mergeObject(itemData, update, { enforceTypes: false, inplace: false });
|
||||
} else {
|
||||
return itemData;
|
||||
}
|
||||
});
|
||||
const updateData: Record<string, unknown> = {};
|
||||
if (actorData.type === "character") {
|
||||
updateData["data.slayerPoints"] = { value: 0 };
|
||||
}
|
||||
if (hasItemUpdates) {
|
||||
updateData["items"] = items;
|
||||
}
|
||||
return updateData;
|
||||
}
|
||||
// function getActorUpdateData(actorData: DeepPartial<Actor.Data>) {
|
||||
// let hasItemUpdates = false;
|
||||
// const items = actorData.items?.map((itemData) => {
|
||||
// const update = itemData ? getItemUpdateData(itemData) : undefined;
|
||||
// if (update) {
|
||||
// hasItemUpdates = true;
|
||||
// return mergeObject(itemData, update, { enforceTypes: false, inplace: false });
|
||||
// } else {
|
||||
// return itemData;
|
||||
// }
|
||||
// });
|
||||
// const updateData: Record<string, unknown> = {};
|
||||
// if (actorData.type === "character") {
|
||||
// updateData["data.slayerPoints"] = { value: 0 };
|
||||
// }
|
||||
// if (hasItemUpdates) {
|
||||
// updateData["items"] = items;
|
||||
// }
|
||||
// return updateData;
|
||||
// }
|
||||
|
||||
async function migrateScenes() {
|
||||
for (const scene of game.scenes?.entities ?? []) {
|
||||
try {
|
||||
const updateData = getSceneUpdateData(scene._data);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
await scene.update(updateData, { enforceTypes: false });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of Scene entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function migrateScenes() {
|
||||
// for (const scene of game.scenes?.entities ?? []) {
|
||||
// try {
|
||||
// const updateData = getSceneUpdateData(scene._data);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating Scene entity ${scene.name} (${scene.id})`);
|
||||
// await scene.update(updateData, { enforceTypes: false });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of Scene entity ${scene.name} (${scene.id}), continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
function getSceneUpdateData(sceneData: Scene.Data) {
|
||||
let hasTokenUpdates = false;
|
||||
const tokens = sceneData.tokens.map((tokenData) => {
|
||||
if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
return tokenData;
|
||||
}
|
||||
const token = new Token(tokenData);
|
||||
if (!token.actor) {
|
||||
tokenData.actorId = null as unknown as string;
|
||||
tokenData.actorData = {};
|
||||
hasTokenUpdates = true;
|
||||
} else if (!tokenData.actorLink) {
|
||||
const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
hasTokenUpdates = true;
|
||||
}
|
||||
return tokenData;
|
||||
});
|
||||
if (!hasTokenUpdates) return undefined;
|
||||
return hasTokenUpdates ? { tokens } : undefined;
|
||||
}
|
||||
// function getSceneUpdateData(sceneData: Scene.Data) {
|
||||
// let hasTokenUpdates = false;
|
||||
// const tokens = sceneData.tokens.map((tokenData) => {
|
||||
// if (!tokenData.actorId || tokenData.actorLink || tokenData.actorData.data) {
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// return tokenData;
|
||||
// }
|
||||
// const token = new Token(tokenData);
|
||||
// if (!token.actor) {
|
||||
// tokenData.actorId = null as unknown as string;
|
||||
// tokenData.actorData = {};
|
||||
// hasTokenUpdates = true;
|
||||
// } else if (!tokenData.actorLink) {
|
||||
// const actorUpdateData = getActorUpdateData(token.data.actorData);
|
||||
// tokenData.actorData = mergeObject(token.data.actorData, actorUpdateData);
|
||||
// hasTokenUpdates = true;
|
||||
// }
|
||||
// return tokenData;
|
||||
// });
|
||||
// if (!hasTokenUpdates) return undefined;
|
||||
// return hasTokenUpdates ? { tokens } : undefined;
|
||||
// }
|
||||
|
||||
async function migrateCompendiums() {
|
||||
for (const compendium of game.packs ?? []) {
|
||||
if (compendium.metadata.package !== "world") continue;
|
||||
if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
await migrateCompendium(compendium);
|
||||
}
|
||||
}
|
||||
// async function migrateCompendiums() {
|
||||
// for (const compendium of game.packs ?? []) {
|
||||
// if (compendium.metadata.package !== "world") continue;
|
||||
// if (!["Actor", "Item", "Scene"].includes(compendium.metadata.entity)) continue;
|
||||
// await migrateCompendium(compendium);
|
||||
// }
|
||||
// }
|
||||
|
||||
async function migrateCompendium(compendium: Compendium) {
|
||||
const entityName = compendium.metadata.entity;
|
||||
if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
const wasLocked = compendium.locked;
|
||||
await compendium.configure({ locked: false });
|
||||
await compendium.migrate({});
|
||||
// async function migrateCompendium(compendium: Compendium) {
|
||||
// const entityName = compendium.metadata.entity;
|
||||
// if (!["Actor", "Item", "Scene"].includes(entityName)) return;
|
||||
// const wasLocked = compendium.locked;
|
||||
// await compendium.configure({ locked: false });
|
||||
// await compendium.migrate({});
|
||||
|
||||
const content = await compendium.getContent();
|
||||
// const content = await compendium.getContent();
|
||||
|
||||
for (const entity of content) {
|
||||
try {
|
||||
const getUpdateData = (entity: Entity) => {
|
||||
switch (entityName) {
|
||||
case "Item":
|
||||
return getItemUpdateData(entity._data);
|
||||
case "Actor":
|
||||
return getActorUpdateData(entity._data);
|
||||
case "Scene":
|
||||
return getSceneUpdateData(entity._data as Scene.Data);
|
||||
}
|
||||
};
|
||||
const updateData = getUpdateData(entity);
|
||||
if (updateData) {
|
||||
logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
}
|
||||
} catch (err) {
|
||||
err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
// for (const entity of content) {
|
||||
// try {
|
||||
// const getUpdateData = (entity: Entity) => {
|
||||
// switch (entityName) {
|
||||
// case "Item":
|
||||
// return getItemUpdateData(entity._data);
|
||||
// case "Actor":
|
||||
// return getActorUpdateData(entity._data);
|
||||
// case "Scene":
|
||||
// return getSceneUpdateData(entity._data as Scene.Data);
|
||||
// }
|
||||
// };
|
||||
// const updateData = getUpdateData(entity);
|
||||
// if (updateData) {
|
||||
// logger.info(`Migrating entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}`);
|
||||
// await compendium.updateEntity({ ...updateData, _id: entity._id });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// err.message = `Error during migration of entity ${entity.name} (${entity.id}) in compendium ${compendium.collection}, continuing anyways.`;
|
||||
// logger.error(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
await compendium.configure({ locked: wasLocked });
|
||||
}
|
||||
// await compendium.configure({ locked: wasLocked });
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue