Allow reload helper to directly access getSessionSaveData()

This commit is contained in:
Michael Li 2024-09-01 17:23:47 -04:00
parent 427de53ae6
commit b2a934e260
2 changed files with 2 additions and 38 deletions

View File

@ -946,7 +946,7 @@ export class GameData {
return ret; return ret;
} }
private getSessionSaveData(scene: BattleScene): SessionSaveData { public getSessionSaveData(scene: BattleScene): SessionSaveData {
return { return {
seed: scene.seed, seed: scene.seed,
playTime: scene.sessionPlayTime, playTime: scene.sessionPlayTime,

View File

@ -1,10 +1,3 @@
import { BattleType } from "#app/battle";
import PokemonData from "#app/system/pokemon-data";
import ArenaData from "#app/system/arena-data";
import PersistentModifierData from "#app/system/modifier-data";
import ChallengeData from "#app/system/challenge-data";
import TrainerData from "#app/system/trainer-data";
import { SessionSaveData } from "#app/system/game-data";
import { GameManagerHelper } from "./gameManagerHelper"; import { GameManagerHelper } from "./gameManagerHelper";
import { TitlePhase } from "#app/phases/title-phase"; import { TitlePhase } from "#app/phases/title-phase";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
@ -17,35 +10,6 @@ import { TurnInitPhase } from "#app/phases/turn-init-phase";
* Helper to allow reloading sessions in unit tests. * Helper to allow reloading sessions in unit tests.
*/ */
export class ReloadHelper extends GameManagerHelper { export class ReloadHelper extends GameManagerHelper {
/**
* Return a save data object to be used for reloading the current session.
* @returns A save data object for the current session.
*/
getSessionSaveData() : SessionSaveData {
// Copied from game-data.ts
const scene = this.game.scene;
const ret = {
seed: scene.seed,
playTime: scene.sessionPlayTime,
gameMode: scene.gameMode.modeId,
party: scene.getParty().map(p => new PokemonData(p)),
enemyParty: scene.getEnemyParty().map(p => new PokemonData(p)),
modifiers: scene.findModifiers(() => true).map(m => new PersistentModifierData(m, true)),
enemyModifiers: scene.findModifiers(() => true, false).map(m => new PersistentModifierData(m, false)),
arena: new ArenaData(scene.arena),
pokeballCounts: scene.pokeballCounts,
money: scene.money,
score: scene.score,
waveIndex: scene.currentBattle.waveIndex,
battleType: scene.currentBattle.battleType,
trainer: scene.currentBattle.battleType === BattleType.TRAINER ? new TrainerData(scene.currentBattle.trainer) : null,
gameVersion: scene.game.config.gameVersion,
timestamp: new Date().getTime(),
challenges: scene.gameMode.challenges.map(c => new ChallengeData(c))
} as SessionSaveData;
return ret;
}
/** /**
* Simulate reloading the session from the title screen, until reaching the * Simulate reloading the session from the title screen, until reaching the
* beginning of the first turn (equivalent to running `startBattle()`) for * beginning of the first turn (equivalent to running `startBattle()`) for
@ -53,7 +17,7 @@ export class ReloadHelper extends GameManagerHelper {
*/ */
async reloadSession() : Promise<void> { async reloadSession() : Promise<void> {
const scene = this.game.scene; const scene = this.game.scene;
const sessionData = this.getSessionSaveData(); const sessionData = scene.gameData.getSessionSaveData(scene);
const titlePhase = new TitlePhase(scene); const titlePhase = new TitlePhase(scene);
scene.clearPhaseQueue(); scene.clearPhaseQueue();