chore: reformat with 2 spaces
This commit is contained in:
parent
d659e4bed9
commit
7670d7f808
1577 changed files with 70010 additions and 70042 deletions
|
@ -20,20 +20,20 @@ import { migration as migration009 } from "./009.js";
|
|||
* @returns {Promise<void>} A promise that resolves once all migrations have completed
|
||||
*/
|
||||
async function migrate() {
|
||||
if (!getGame().user?.isGM) {
|
||||
return;
|
||||
}
|
||||
if (!getGame().user?.isGM) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldMigrationVersion = getCurrentMigrationVersion();
|
||||
const oldMigrationVersion = getCurrentMigrationVersion();
|
||||
|
||||
const targetMigrationVersion = migrations.length;
|
||||
const targetMigrationVersion = migrations.length;
|
||||
|
||||
if (isFirstWorldStart(oldMigrationVersion)) {
|
||||
getGame().settings.set("ds4", "systemMigrationVersion", targetMigrationVersion);
|
||||
return;
|
||||
}
|
||||
if (isFirstWorldStart(oldMigrationVersion)) {
|
||||
getGame().settings.set("ds4", "systemMigrationVersion", targetMigrationVersion);
|
||||
return;
|
||||
}
|
||||
|
||||
return migrateFromTo(oldMigrationVersion, targetMigrationVersion);
|
||||
return migrateFromTo(oldMigrationVersion, targetMigrationVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,64 +43,64 @@ async function migrate() {
|
|||
* @returns {Promise<void>} A promise the resolves once the migration is complete
|
||||
*/
|
||||
async function migrateFromTo(oldMigrationVersion, targetMigrationVersion) {
|
||||
if (!getGame().user?.isGM) {
|
||||
return;
|
||||
}
|
||||
if (!getGame().user?.isGM) {
|
||||
return;
|
||||
}
|
||||
|
||||
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
||||
const migrationsToExecute = migrations.slice(oldMigrationVersion, targetMigrationVersion);
|
||||
|
||||
if (migrationsToExecute.length > 0) {
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoSystemUpdateStart", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
if (migrationsToExecute.length > 0) {
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoSystemUpdateStart", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
|
||||
/** @type {Result} */
|
||||
let result = "success";
|
||||
for (const [i, { migrate }] of migrationsToExecute.entries()) {
|
||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||
logger.info("executing migration script", currentMigrationVersion);
|
||||
try {
|
||||
const r = await migrate();
|
||||
getGame().settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||
if (r === "error") {
|
||||
result = "error";
|
||||
}
|
||||
} catch (err) {
|
||||
notifications.error(
|
||||
getGame().i18n.format("DS4.ErrorDuringMigration", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
migrationVersion: currentMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
|
||||
/** @type {Result} */
|
||||
let result = "success";
|
||||
for (const [i, { migrate }] of migrationsToExecute.entries()) {
|
||||
const currentMigrationVersion = oldMigrationVersion + i + 1;
|
||||
logger.info("executing migration script", currentMigrationVersion);
|
||||
try {
|
||||
const r = await migrate();
|
||||
getGame().settings.set("ds4", "systemMigrationVersion", currentMigrationVersion);
|
||||
if (r === "error") {
|
||||
result = "error";
|
||||
}
|
||||
} catch (err) {
|
||||
notifications.error(
|
||||
getGame().i18n.format("DS4.ErrorDuringMigration", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
migrationVersion: currentMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
logger.error("Failed ds4 system migration:", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (result === "success") {
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoSystemUpdateCompletedSuccessfully", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
} else {
|
||||
notifications.warn(
|
||||
getGame().i18n.format("DS4.WarningSystemUpdateCompletedWithErrors", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
}
|
||||
logger.error("Failed ds4 system migration:", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (result === "success") {
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoSystemUpdateCompletedSuccessfully", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
} else {
|
||||
notifications.warn(
|
||||
getGame().i18n.format("DS4.WarningSystemUpdateCompletedWithErrors", {
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,51 +111,51 @@ async function migrateFromTo(oldMigrationVersion, targetMigrationVersion) {
|
|||
* @returns {Promise<void>} A promise that resolves once the migration is complete
|
||||
*/
|
||||
async function migrateCompendiumFromTo(pack, oldMigrationVersion, targetMigrationVersion) {
|
||||
if (!getGame().user?.isGM) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 },
|
||||
);
|
||||
}
|
||||
notifications.info(
|
||||
getGame().i18n.format("DS4.InfoCompendiumMigrationCompleted", {
|
||||
pack: pack.title,
|
||||
currentVersion: oldMigrationVersion,
|
||||
targetVersion: targetMigrationVersion,
|
||||
}),
|
||||
{ permanent: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +163,7 @@ async function migrateCompendiumFromTo(pack, oldMigrationVersion, targetMigratio
|
|||
* @returns {number} The current migration version
|
||||
*/
|
||||
function getCurrentMigrationVersion() {
|
||||
return getGame().settings.get("ds4", "systemMigrationVersion");
|
||||
return getGame().settings.get("ds4", "systemMigrationVersion");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,7 +171,7 @@ function getCurrentMigrationVersion() {
|
|||
* @returns {number} The target migration version
|
||||
*/
|
||||
function getTargetMigrationVersion() {
|
||||
return migrations.length;
|
||||
return migrations.length;
|
||||
}
|
||||
|
||||
/** @typedef {"success" | "error"} Result */
|
||||
|
@ -186,15 +186,15 @@ function getTargetMigrationVersion() {
|
|||
* @type {Migration[]}
|
||||
*/
|
||||
const migrations = [
|
||||
migration001,
|
||||
migration002,
|
||||
migration003,
|
||||
migration004,
|
||||
migration005,
|
||||
migration006,
|
||||
migration007,
|
||||
migration008,
|
||||
migration009,
|
||||
migration001,
|
||||
migration002,
|
||||
migration003,
|
||||
migration004,
|
||||
migration005,
|
||||
migration006,
|
||||
migration007,
|
||||
migration008,
|
||||
migration009,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -203,13 +203,13 @@ const migrations = [
|
|||
* @returns {boolean} Whether the migration version indicates it is the first start of the world
|
||||
*/
|
||||
function isFirstWorldStart(migrationVersion) {
|
||||
return migrationVersion < 0;
|
||||
return migrationVersion < 0;
|
||||
}
|
||||
|
||||
export const migration = {
|
||||
migrate,
|
||||
migrateFromTo,
|
||||
getCurrentMigrationVersion,
|
||||
getTargetMigrationVersion,
|
||||
migrateCompendiumFromTo,
|
||||
migrate,
|
||||
migrateFromTo,
|
||||
getCurrentMigrationVersion,
|
||||
getTargetMigrationVersion,
|
||||
migrateCompendiumFromTo,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue