mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-23 15:59:26 +02:00
Restructure Migration Initialization
This commit is contained in:
parent
13233b77e4
commit
03c36c1d84
@ -44,7 +44,7 @@ import { WeatherType } from "#app/enums/weather-type";
|
||||
import { TerrainType } from "#app/data/terrain";
|
||||
import { ReloadSessionPhase } from "#app/phases/reload-session-phase";
|
||||
import { RUN_HISTORY_LIMIT } from "#app/ui/run-history-ui-handler";
|
||||
import { SessionVersionConverter, SettingsVersionConverter, SystemVersionConverter } from "./version_migration/version_converter";
|
||||
import { applySessionVersionMigration, applySystemVersionMigration, applySettingsVersionMigration } from "./version_migration/version_converter";
|
||||
import { MysteryEncounterSaveData } from "../data/mystery-encounters/mystery-encounter-save-data";
|
||||
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
||||
import { PokerogueApiClearSessionData } from "#app/@types/pokerogue-api";
|
||||
@ -476,7 +476,7 @@ export class GameData {
|
||||
localStorage.setItem(lsItemKey, "");
|
||||
}
|
||||
|
||||
new SystemVersionConverter(systemData, systemData.gameVersion);
|
||||
applySystemVersionMigration(systemData);
|
||||
|
||||
this.trainerId = systemData.trainerId;
|
||||
this.secretId = systemData.secretId;
|
||||
@ -851,7 +851,7 @@ export class GameData {
|
||||
|
||||
const settings = JSON.parse(localStorage.getItem("settings")!); // TODO: is this bang correct?
|
||||
|
||||
new SettingsVersionConverter(settings);
|
||||
applySettingsVersionMigration(settings);
|
||||
|
||||
for (const setting of Object.keys(settings)) {
|
||||
setSetting(this.scene, setting, settings[setting]);
|
||||
@ -1289,7 +1289,7 @@ export class GameData {
|
||||
return v;
|
||||
}) as SessionSaveData;
|
||||
|
||||
new SessionVersionConverter(sessionData, sessionData.gameVersion);
|
||||
applySessionVersionMigration(sessionData);
|
||||
|
||||
return sessionData;
|
||||
}
|
||||
|
@ -6,14 +6,35 @@ import * as v1_0_4 from "./versions/v1_0_4";
|
||||
|
||||
const LATEST_VERSION = version.split(".").map(value => parseInt(value));
|
||||
|
||||
export abstract class VersionConverter {
|
||||
constructor(data: any, gameVersion: string) {
|
||||
const curVersion = gameVersion.split(".").map(value => parseInt(value));
|
||||
if (!curVersion.every((value, index) => value === LATEST_VERSION[index])) {
|
||||
this.applyMigration(data, curVersion);
|
||||
}
|
||||
}
|
||||
export function applySystemVersionMigration(data: SystemSaveData) {
|
||||
const curVersion = data.gameVersion.split(".").map(value => parseInt(value));
|
||||
|
||||
if (!curVersion.every((value, index) => value === LATEST_VERSION[index])) {
|
||||
const converter = new SystemVersionConverter();
|
||||
converter.applyMigration(data, curVersion);
|
||||
}
|
||||
}
|
||||
|
||||
export function applySessionVersionMigration(data: SessionSaveData) {
|
||||
const curVersion = data.gameVersion.split(".").map(value => parseInt(value));
|
||||
|
||||
if (!curVersion.every((value, index) => value === LATEST_VERSION[index])) {
|
||||
const converter = new SessionVersionConverter();
|
||||
converter.applyMigration(data, curVersion);
|
||||
}
|
||||
}
|
||||
|
||||
export function applySettingsVersionMigration(data: Object) {
|
||||
const gameVersion: string = data.hasOwnProperty("gameVersion") ? data["gameVersion"] : "1.0.0";
|
||||
const curVersion = gameVersion.split(".").map(value => parseInt(value));
|
||||
|
||||
if (!curVersion.every((value, index) => value === LATEST_VERSION[index])) {
|
||||
const converter = new SettingsVersionConverter();
|
||||
converter.applyMigration(data, curVersion);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class VersionConverter {
|
||||
/**
|
||||
* Iterates through an array of designated migration functions that are each
|
||||
* called one by one to transform the data.
|
||||
@ -38,75 +59,53 @@ export abstract class VersionConverter {
|
||||
abstract applyMigration(data: any, curVersion: number[]): void;
|
||||
}
|
||||
|
||||
export class SessionVersionConverter extends VersionConverter {
|
||||
constructor(data: SessionSaveData, gameVersion: string) {
|
||||
super(data, gameVersion);
|
||||
}
|
||||
|
||||
class SessionVersionConverter extends VersionConverter {
|
||||
override applyMigration(data: SessionSaveData, curVersion: number[]): void {
|
||||
const [ curMajor, curMinor, curPatch ] = curVersion;
|
||||
|
||||
switch (curMajor) {
|
||||
case 1:
|
||||
switch (curMinor) {
|
||||
case 0:
|
||||
if (curMajor === 1) {
|
||||
if (curMinor === 0) {
|
||||
if (curPatch <= 4) {
|
||||
console.log("Applying v1.0.4 session data migration!");
|
||||
this.callMigrators(data, v1_0_4.sessionMigrators);
|
||||
}
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
console.log(`Session data successfully migrated to v${version}!`);
|
||||
}
|
||||
}
|
||||
|
||||
export class SystemVersionConverter extends VersionConverter {
|
||||
constructor(data: SystemSaveData, gameVersion: string) {
|
||||
super(data, gameVersion);
|
||||
}
|
||||
|
||||
class SystemVersionConverter extends VersionConverter {
|
||||
override applyMigration(data: SystemSaveData, curVersion: number[]): void {
|
||||
const [ curMajor, curMinor, curPatch ] = curVersion;
|
||||
|
||||
switch (curMajor) {
|
||||
case 1:
|
||||
switch (curMinor) {
|
||||
case 0:
|
||||
if (curMajor === 1) {
|
||||
if (curMinor === 0) {
|
||||
if (curPatch <= 4) {
|
||||
console.log("Applying v1.0.4 system data migraton!");
|
||||
this.callMigrators(data, v1_0_4.systemMigrators);
|
||||
}
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
console.log(`System data successfully migrated to v${version}!`);
|
||||
}
|
||||
}
|
||||
|
||||
export class SettingsVersionConverter extends VersionConverter {
|
||||
constructor(data: SystemSaveData) {
|
||||
const gameVersion = data.hasOwnProperty("gameVersion") ? data["gameVersion"] : "1.0.0";
|
||||
super(data, gameVersion);
|
||||
}
|
||||
|
||||
class SettingsVersionConverter extends VersionConverter {
|
||||
override applyMigration(data: Object, curVersion: number[]): void {
|
||||
const [ curMajor, curMinor, curPatch ] = curVersion;
|
||||
|
||||
switch (curMajor) {
|
||||
case 1:
|
||||
switch (curMinor) {
|
||||
case 0:
|
||||
if (curMajor === 1) {
|
||||
if (curMinor === 0) {
|
||||
if (curPatch <= 4) {
|
||||
console.log("Applying v1.0.4 settings data migraton!");
|
||||
this.callMigrators(data, v1_0_4.sessionMigrators);
|
||||
this.callMigrators(data, v1_0_4.settingsMigrators);
|
||||
}
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
console.log(`System data successfully migrated to v${version}!`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user