Add outdated session support and fix older migrations

pull/225/head
Flashfyre 2024-04-21 10:59:50 -04:00
parent 8614a52557
commit c8a9069e8b
4 changed files with 89 additions and 4 deletions

View File

@ -379,6 +379,33 @@ export class UnavailablePhase extends Phase {
}
}
export class ReloadSessionPhase extends Phase {
constructor(scene: BattleScene) {
super(scene);
}
start(): void {
this.scene.ui.setMode(Mode.SESSION_RELOAD);
let delayElapsed = false;
let loaded = false;
this.scene.time.delayedCall(Utils.fixedInt(1500), () => {
if (loaded)
this.end();
else
delayElapsed = true;
});
this.scene.gameData.loadSystem().then(() => {
if (delayElapsed)
this.end();
else
loaded = true;
});
}
}
export class OutdatedPhase extends Phase {
constructor(scene: BattleScene) {
super(scene);

View File

@ -27,7 +27,7 @@ import { Moves } from "../data/enums/moves";
import { speciesEggMoves } from "../data/egg-moves";
import { allMoves } from "../data/move";
import { TrainerVariant } from "../field/trainer";
import { OutdatedPhase, UnavailablePhase } from "#app/phases";
import { OutdatedPhase, ReloadSessionPhase, UnavailablePhase } from "#app/phases";
import { Variant, variantData } from "#app/data/variant";
const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary
@ -280,6 +280,9 @@ export class GameData {
if (error.startsWith('client version out of date')) {
this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new OutdatedPhase(this.scene));
} else if (error.startsWith('session out of date')) {
this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
}
console.error(error);
return resolve(false);
@ -340,7 +343,7 @@ export class GameData {
this.starterData[s].eggMoves = starterEggMoveData[s];
}
this.migrateStarterAbilities(systemData);
this.migrateStarterAbilities(systemData, this.starterData);
} else {
if ([ '1.0.0', '1.0.1' ].includes(systemData.gameVersion))
this.migrateStarterAbilities(systemData);
@ -551,6 +554,10 @@ export class GameData {
.then(response => response.text())
.then(error => {
if (error) {
if (error.startsWith('session out of date')) {
this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
}
console.error(error);
return resolve(false);
}
@ -1207,9 +1214,9 @@ export class GameData {
}
}
migrateStarterAbilities(systemData: SystemSaveData): void {
migrateStarterAbilities(systemData: SystemSaveData, initialStarterData?: StarterData): void {
const starterIds = Object.keys(this.starterData).map(s => parseInt(s) as Species);
const starterData = systemData.starterData;
const starterData = initialStarterData || systemData.starterData;
const dexData = systemData.dexData;
for (let s of starterIds) {
const dexAttr = dexData[s].caughtAttr;

View File

@ -0,0 +1,47 @@
import BattleScene from "../battle-scene";
import { ModalConfig, ModalUiHandler } from "./modal-ui-handler";
import { addTextObject, TextStyle } from "./text";
import { Mode } from "./ui";
export default class SessionReloadModalUiHandler extends ModalUiHandler {
constructor(scene: BattleScene, mode?: Mode) {
super(scene, mode);
}
getModalTitle(): string {
return '';
}
getWidth(): number {
return 160;
}
getHeight(): number {
return 32;
}
getMargin(): [number, number, number, number] {
return [ 0, 0, 48, 0 ];
}
getButtonLabels(): string[] {
return [ ];
}
setup(): void {
super.setup();
const label = addTextObject(this.scene, this.getWidth() / 2, this.getHeight() / 2, 'Your session is out of date.\nYour data will be reloaded…', TextStyle.WINDOW, { fontSize: '48px', align: 'center' });
label.setOrigin(0.5, 0.5);
this.modalContainer.add(label);
}
show(args: any[]): boolean {
const config: ModalConfig = {
buttonActions: []
};
return super.show([ config ]);
}
}

View File

@ -34,6 +34,7 @@ import TitleUiHandler from './title-ui-handler';
import SavingIconHandler from './saving-icon-handler';
import UnavailableModalUiHandler from './unavailable-modal-ui-handler';
import OutdatedModalUiHandler from './outdated-modal-ui-handler';
import SessionReloadModalUiHandler from './session-reload-modal-ui-handler';
export enum Mode {
MESSAGE,
@ -62,6 +63,7 @@ export enum Mode {
LOGIN_FORM,
REGISTRATION_FORM,
LOADING,
SESSION_RELOAD,
UNAVAILABLE,
OUTDATED
};
@ -90,6 +92,7 @@ const noTransitionModes = [
Mode.LOGIN_FORM,
Mode.REGISTRATION_FORM,
Mode.LOADING,
Mode.SESSION_RELOAD,
Mode.UNAVAILABLE,
Mode.OUTDATED
];
@ -141,6 +144,7 @@ export default class UI extends Phaser.GameObjects.Container {
new LoginFormUiHandler(scene),
new RegistrationFormUiHandler(scene),
new LoadingModalUiHandler(scene),
new SessionReloadModalUiHandler(scene),
new UnavailableModalUiHandler(scene),
new OutdatedModalUiHandler(scene)
];