feat: only allow specific selectable values for the cooldown duration of spells
World data (including compendium packs) is migrated automatically. In order to also migrate packs provided by modules, you can use the following macro: ```js const pack = game.packs.get("<name-of-the-module>.<name-of-the-pack>"); game.ds4.migration.migrateCompendiumFromTo(pack, 4, 5); ```
This commit is contained in:
parent
73e2d44c55
commit
da1f6999eb
20 changed files with 558 additions and 876 deletions
|
@ -4,10 +4,11 @@
|
|||
|
||||
import { getGame } from "./helpers";
|
||||
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 { migration as migration001 } from "./migrations/001";
|
||||
import { migration as migration002 } from "./migrations/002";
|
||||
import { migration as migration003 } from "./migrations/003";
|
||||
import { migration as migration004 } from "./migrations/004";
|
||||
import { migration as migration005 } from "./migrations/005";
|
||||
import notifications from "./ui/notifications";
|
||||
|
||||
async function migrate(): Promise<void> {
|
||||
|
@ -43,11 +44,11 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
|||
{ permanent: true },
|
||||
);
|
||||
|
||||
for (const [i, migration] of migrationsToExecute.entries()) {
|
||||
for (const [i, { migrate }] of migrationsToExecute.entries()) {
|
||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||
logger.info("executing migration script ", currentMigrationVersion);
|
||||
try {
|
||||
await migration();
|
||||
await migrate();
|
||||
getGame().settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||
} catch (err) {
|
||||
notifications.error(
|
||||
|
@ -73,18 +74,76 @@ async function migrateFromTo(oldMigrationVersion: number, targetMigrationVersion
|
|||
}
|
||||
}
|
||||
|
||||
async function migrateCompendiumFromTo(
|
||||
pack: CompendiumCollection<CompendiumCollection.Metadata>,
|
||||
oldMigrationVersion: number,
|
||||
targetMigrationVersion: number,
|
||||
): Promise<void> {
|
||||
if (!getGame().user?.isGM) {
|
||||
return;
|
||||
}
|
||||
|
||||
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
||||
|
||||
if (migrationsToExecute.length > 0) {
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoCompendiumMigrationStart", {
|
||||
pack: pack.title,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
|
||||
for (const [i, { migrateCompendium }] of migrationsToExecute.entries()) {
|
||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||
logger.info("executing compendium migration ", currentMigrationVersion);
|
||||
try {
|
||||
await migrateCompendium(pack);
|
||||
} catch (err) {
|
||||
notifications.error(
|
||||
getGame().i18n.format("DS4.ErrorDuringCompendiumMigration", {
|
||||
pack: pack.title,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
migrationVersion: currentMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
logger.error("Failed ds4 compendium migration:", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoCompendiumMigrationCompleted", {
|
||||
pack: pack.title,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetMigrationVersion(): number {
|
||||
return migrations.length;
|
||||
}
|
||||
|
||||
const migrations: Array<() => Promise<void>> = [migrate001, migrate002, migrate003, migrate004];
|
||||
interface Migration {
|
||||
migrate: () => Promise<void>;
|
||||
migrateCompendium: (pack: CompendiumCollection<CompendiumCollection.Metadata>) => Promise<void>;
|
||||
}
|
||||
|
||||
const migrations: Migration[] = [migration001, migration002, migration003, migration004, migration005];
|
||||
|
||||
function isFirstWorldStart(migrationVersion: number): boolean {
|
||||
return migrationVersion < 0;
|
||||
}
|
||||
|
||||
export const migration = {
|
||||
migrate: migrate,
|
||||
migrateFromTo: migrateFromTo,
|
||||
getTargetMigrationVersion: getTargetMigrationVersion,
|
||||
migrate,
|
||||
migrateFromTo,
|
||||
getTargetMigrationVersion,
|
||||
migrateCompendiumFromTo,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue