mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-25 05:28:27 +00:00
* refactor executed code while importing and initializing all of these in loading-scene * reset to main * fix server url * added rule no-trailing-spaces * made progress * test somme data from a session save is working * trying to launch a battle * added fetch wrapper to load data locally * trying to mockAllSettled * pushPhase & shiftPhase * check integrity of exported session * set toke + loggedInUser in tests * progress on starting new battle * tring to test phase but it's async * mocking fetch * working mock fetch * need to handle pile of data * attempt to use real phaser classes * reorder overrides * refactored to use some real classes from phaser * removed useless things * started to work on some container mock * finished the mockContainer time to add some logic * some more mock containers * removed addMethods since there is the mock classes now * commented issues * attempt to create mockTextureManager * fix tests * mockSprite & mockText * yes but not really * yes but not really * fix tutorial callback * reached mode title * added achievement tests * fix test achievements with current state of mock * correct sequence loading for BattleScene with mockLoader ! * deep dive into next step * working wait until starter selection screen * added newGame method into wrapper * expect to save_slot * trying to manage pokemon sprite for getAll without success yet * added test for egg output * fixed egg test for June * fix tests + locate next issue to fix * we are in battle baby * added new game in one-line * export is working but export only what's in the fetch * fix start game as guest * refactored how we start a battle + cleanup * overrided mewtwo but issue with currentBattle * refactor: rename InitAchievements to initAchievements * added missing mock method * override level and pokemon forms working as intended * bringToTop Obj * remove launch battle in achivement test * fix getIndex when same pokemon * can run all tests * first attack, faint, and shop modifiers, MockClock * on method for container * added doAttack one-liner * one-line export data * removed throw error * feat: Make `scenes` property of `GameWrapper` class public The `scenes` property of the `GameWrapper` class was changed from private to public. This change allows external access to the `scenes` map, which is used to store Phaser scenes. This modification was made to enable easier manipulation and interaction with the scenes in the game. * correction * removed CanvasRenderer * added a param to remove console.log and added a param to preven scene create call * fix encounter wave 30 when it's a trainer * test double-battle * test fight without KO * test double fight no ko * fix crashing texture + added Text wrapper to log fight * fix tests on boss - trainer - rival * chore: Refactor BattleScene initialization and add new phases Refactor the BattleScene initialization code to remove unnecessary delay and improve performance. Also, add new phases for the title and unavailable states to enhance the game experience. * rework of Game tests * skipFn is working * added onNextPrompt and restore Og Start * better newGame * added skipFN in remove * not yet working test but updated interceptors * do attack work but not on PostSummonPhase phase when there is mention of silcoon and wurmple * error located, it's just a double fight, i was not there yet * single OHKO & double no OHKO * added expirationFn into next prompt * all tests are passing * working test on non damaging move from opponent * cleaned a bit * removed phaser initialisation on every tests * renamed test file * added load system data * added some ability support * added onKill & onSummon abilities test * removed useless test + cleanup * removed useless test + cleanup * fixed tests after merge main * added itemHeld endTurn trigger test (toxic orb) * added runFrom..To * added mustRun to assert currentPhase * added no-miss move to test things * cleaner restore mock * fix test * fix moxie test + game speed * improve test speed * added onOurself and onOpponent mvoe test * added onDamage test for tackle * removed timeout in intervals to run tests faster * cleanup * added never crit override + separate file per test + remove randomness in randBattleSeedInt * move folders * better org * renamed itemHeld folder to items * fix deploy.yml * cleanup * simplified the gameManager start battle and allow single pokemon in party * remove the need of mode development * added input handler to test inputs + remove time from phaser into inputController * added keyboard support * added fakeMobile support * added details * removed a console.log + added logUp * move test to folder * fixed canvas issue * added starter select tests * added some more test on starter-select * added battle-order tests * added battle-order tests * fixing Phaser RNG * ordering stats for better reading * fix tests for main * adapt battle-order test to be more readable * fix merge * fix some errors and silent all errors from gameWrapper since it's not possible to avoid them * fix mocks to manage childs & stuffs * added some docs * fix achievement test * removed an unused file * separate misc tests to clean battle.test file * added a basic french lokalization test * added i18n where it needs to be used only * revers extracted method * removed unused method * removed handler fetch since we do not test anything server related * fix test with handlers removed * added intrepid sword test * fix enum exp party --------- Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
224 lines
8.1 KiB
TypeScript
224 lines
8.1 KiB
TypeScript
import GameWrapper from "#app/test/utils/gameWrapper";
|
|
import {Mode} from "#app/ui/ui";
|
|
import {generateStarter, waitUntil} from "#app/test/utils/gameManagerUtils";
|
|
import {
|
|
CheckSwitchPhase,
|
|
CommandPhase,
|
|
EncounterPhase,
|
|
LoginPhase,
|
|
PostSummonPhase,
|
|
SelectGenderPhase,
|
|
SelectStarterPhase,
|
|
SummonPhase,
|
|
TitlePhase,
|
|
ToggleDoublePositionPhase,
|
|
} from "#app/phases";
|
|
import BattleScene from "#app/battle-scene.js";
|
|
import PhaseInterceptor from "#app/test/utils/phaseInterceptor";
|
|
import TextInterceptor from "#app/test/utils/TextInterceptor";
|
|
import {expect} from "vitest";
|
|
import {GameModes} from "#app/game-mode";
|
|
import fs from "fs";
|
|
import { AES, enc } from "crypto-js";
|
|
import {updateUserInfo} from "#app/account";
|
|
import {Species} from "#app/data/enums/species";
|
|
import {PlayerGender} from "#app/data/enums/player-gender";
|
|
import {GameDataType} from "#app/data/enums/game-data-type";
|
|
import InputsHandler from "#app/test/utils/inputsHandler";
|
|
import {ExpNotification} from "#app/enums/exp-notification";
|
|
|
|
/**
|
|
* Class to manage the game state and transitions between phases.
|
|
*/
|
|
export default class GameManager {
|
|
public gameWrapper: GameWrapper;
|
|
public scene: BattleScene;
|
|
public phaseInterceptor: PhaseInterceptor;
|
|
public textInterceptor: TextInterceptor;
|
|
public inputsHandler: InputsHandler;
|
|
|
|
/**
|
|
* Creates an instance of GameManager.
|
|
* @param phaserGame - The Phaser game instance.
|
|
* @param bypassLogin - Whether to bypass the login phase.
|
|
*/
|
|
constructor(phaserGame: Phaser.Game, bypassLogin: boolean = true) {
|
|
BattleScene.prototype.randBattleSeedInt = (arg) => arg-1;
|
|
this.gameWrapper = new GameWrapper(phaserGame, bypassLogin);
|
|
this.scene = new BattleScene();
|
|
this.phaseInterceptor = new PhaseInterceptor(this.scene);
|
|
this.textInterceptor = new TextInterceptor(this.scene);
|
|
this.gameWrapper.setScene(this.scene);
|
|
}
|
|
|
|
/**
|
|
* Sets the game mode.
|
|
* @param mode - The mode to set.
|
|
*/
|
|
setMode(mode: Mode) {
|
|
this.scene.ui?.setMode(mode);
|
|
}
|
|
|
|
/**
|
|
* Waits until the specified mode is set.
|
|
* @param mode - The mode to wait for.
|
|
* @returns A promise that resolves when the mode is set.
|
|
*/
|
|
waitMode(mode: Mode): Promise<void> {
|
|
return new Promise(async (resolve) => {
|
|
await waitUntil(() => this.scene.ui?.getMode() === mode);
|
|
return resolve();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Ends the current phase.
|
|
*/
|
|
endPhase() {
|
|
this.scene.getCurrentPhase().end();
|
|
}
|
|
|
|
/**
|
|
* Adds an action to be executed on the next prompt.
|
|
* @param phaseTarget - The target phase.
|
|
* @param mode - The mode to wait for.
|
|
* @param callback - The callback to execute.
|
|
* @param expireFn - Optional function to determine if the prompt has expired.
|
|
*/
|
|
onNextPrompt(phaseTarget: string, mode: Mode, callback: () => void, expireFn?: () => void) {
|
|
this.phaseInterceptor.addToNextPrompt(phaseTarget, mode, callback, expireFn);
|
|
}
|
|
|
|
/**
|
|
* Runs the game to the title phase.
|
|
* @returns A promise that resolves when the title phase is reached.
|
|
*/
|
|
runToTitle(): Promise<void> {
|
|
return new Promise(async(resolve) => {
|
|
await this.phaseInterceptor.run(LoginPhase);
|
|
this.onNextPrompt("SelectGenderPhase", Mode.OPTION_SELECT, () => {
|
|
this.scene.gameData.gender = PlayerGender.MALE;
|
|
this.endPhase();
|
|
}, () => this.isCurrentPhase(TitlePhase));
|
|
await this.phaseInterceptor.run(SelectGenderPhase, () => this.isCurrentPhase(TitlePhase));
|
|
await this.phaseInterceptor.run(TitlePhase);
|
|
this.scene.gameSpeed = 5;
|
|
this.scene.moveAnimations = false;
|
|
this.scene.showLevelUpStats = false;
|
|
this.scene.expGainsSpeed = 3;
|
|
this.scene.expParty = ExpNotification.SKIP;
|
|
this.scene.hpBarSpeed = 3;
|
|
resolve();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Runs the game to the summon phase.
|
|
* @param species - Optional array of species to summon.
|
|
* @returns A promise that resolves when the summon phase is reached.
|
|
*/
|
|
runToSummon(species?: Species[]): Promise<void> {
|
|
return new Promise(async(resolve) => {
|
|
await this.runToTitle();
|
|
this.onNextPrompt("TitlePhase", Mode.TITLE, () => {
|
|
const starters = generateStarter(this.scene, species);
|
|
const selectStarterPhase = new SelectStarterPhase(this.scene, GameModes.CLASSIC);
|
|
this.scene.pushPhase(new EncounterPhase(this.scene, false));
|
|
selectStarterPhase.initBattle(starters);
|
|
});
|
|
await this.phaseInterceptor.run(EncounterPhase);
|
|
resolve();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Starts a battle.
|
|
* @param species - Optional array of species to start the battle with.
|
|
* @returns A promise that resolves when the battle is started.
|
|
*/
|
|
startBattle(species?: Species[]): Promise<void> {
|
|
return new Promise(async(resolve) => {
|
|
await this.runToSummon(species);
|
|
await this.phaseInterceptor.runFrom(PostSummonPhase).to(ToggleDoublePositionPhase);
|
|
await this.phaseInterceptor.run(SummonPhase, () => this.isCurrentPhase(CheckSwitchPhase) || this.isCurrentPhase(PostSummonPhase));
|
|
this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => {
|
|
this.setMode(Mode.MESSAGE);
|
|
this.endPhase();
|
|
}, () => this.isCurrentPhase(PostSummonPhase));
|
|
this.onNextPrompt("CheckSwitchPhase", Mode.CONFIRM, () => {
|
|
this.setMode(Mode.MESSAGE);
|
|
this.endPhase();
|
|
}, () => this.isCurrentPhase(PostSummonPhase));
|
|
await this.phaseInterceptor.run(CheckSwitchPhase, () => this.isCurrentPhase(PostSummonPhase));
|
|
await this.phaseInterceptor.run(CheckSwitchPhase, () => this.isCurrentPhase(PostSummonPhase));
|
|
await this.phaseInterceptor.runFrom(PostSummonPhase).to(CommandPhase);
|
|
await waitUntil(() => this.scene.ui?.getMode() === Mode.COMMAND);
|
|
console.log("==================[New Turn]==================");
|
|
expect(this.scene.ui?.getMode()).toBe(Mode.COMMAND);
|
|
expect(this.scene.getCurrentPhase().constructor.name).toBe(CommandPhase.name);
|
|
return resolve();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Checks if the player has won the battle.
|
|
* @returns True if the player has won, otherwise false.
|
|
*/
|
|
isVictory() {
|
|
return this.scene.currentBattle.enemyParty.every(pokemon => pokemon.isFainted());
|
|
}
|
|
|
|
/**
|
|
* Checks if the current phase matches the target phase.
|
|
* @param phaseTarget - The target phase.
|
|
* @returns True if the current phase matches the target phase, otherwise false.
|
|
*/
|
|
isCurrentPhase(phaseTarget) {
|
|
const targetName = typeof phaseTarget === "string" ? phaseTarget : phaseTarget.name;
|
|
return this.scene.getCurrentPhase().constructor.name === targetName;
|
|
}
|
|
|
|
/**
|
|
* Checks if the current mode matches the target mode.
|
|
* @param mode - The target mode.
|
|
* @returns True if the current mode matches the target mode, otherwise false.
|
|
*/
|
|
isCurrentMode(mode: Mode) {
|
|
return this.scene.ui?.getMode() === mode;
|
|
}
|
|
|
|
/**
|
|
* Exports the save data to import it in a test game.
|
|
* @returns A promise that resolves with the exported save data.
|
|
*/
|
|
exportSaveToTest(): Promise<string> {
|
|
return new Promise(async (resolve) => {
|
|
await this.scene.gameData.saveAll(this.scene, true, true, true, true);
|
|
this.scene.reset(true);
|
|
await waitUntil(() => this.scene.ui?.getMode() === Mode.TITLE);
|
|
await this.scene.gameData.tryExportData(GameDataType.SESSION, 0);
|
|
await waitUntil(() => localStorage.hasOwnProperty("toExport"));
|
|
return resolve(localStorage.getItem("toExport"));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Imports game data from a file.
|
|
* @param path - The path to the data file.
|
|
* @returns A promise that resolves with a tuple containing a boolean indicating success and an integer status code.
|
|
*/
|
|
async importData(path): Promise<[boolean, integer]> {
|
|
const saveKey = "x0i2O7WRiANTqPmZ";
|
|
const dataRaw = fs.readFileSync(path, {encoding: "utf8", flag: "r"});
|
|
let dataStr = AES.decrypt(dataRaw, saveKey).toString(enc.Utf8);
|
|
dataStr = this.scene.gameData.convertSystemDataStr(dataStr);
|
|
const systemData = this.scene.gameData.parseSystemData(dataStr);
|
|
const valid = !!systemData.dexData && !!systemData.timestamp;
|
|
if (valid) {
|
|
await updateUserInfo();
|
|
await this.scene.gameData.initSystem(dataStr);
|
|
}
|
|
return updateUserInfo();
|
|
}
|
|
}
|