[UI/UX] Caught battle forms are displayed correctly in Pokédex (#5697)

* isCaught function in Dex now returns the correct result

* Removed log messages

* Added tests to check caught status of battle forms

* Update src/ui/pokedex-page-ui-handler.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Wlowscha 2025-05-01 04:17:21 +02:00 committed by GitHub
parent fd5612e253
commit cdcc338afd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 68 additions and 6 deletions

View File

@ -921,16 +921,22 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
return biomes;
}
/**
* Return the caughtAttr of a given species, sanitized.
*
* @param otherSpecies The species to check; defaults to current species
* @returns caught DexAttr for the species
*/
isCaught(otherSpecies?: PokemonSpecies): bigint {
const species = otherSpecies ? otherSpecies : this.species;
if (globalScene.dexForDevs) {
return 255n;
species.getFullUnlocksData();
}
const species = otherSpecies ? otherSpecies : this.species;
const dexEntry = globalScene.gameData.dexData[species.speciesId];
const starterDexEntry = globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)];
return (dexEntry?.caughtAttr ?? 0n) & (starterDexEntry?.caughtAttr ?? 0n) & species.getFullUnlocksData();
return (dexEntry?.caughtAttr ?? 0n) & species.getFullUnlocksData();
}
/**
@ -939,7 +945,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
*
* @param otherSpecies The species to check; defaults to current species
* @param otherFormIndex The form index of the form to check; defaults to current form
* @returns StarterAttributes for the species
* @returns `true` if the form is caught
*/
isFormCaught(otherSpecies?: PokemonSpecies, otherFormIndex?: number | undefined): boolean {
if (globalScene.dexForDevs) {
@ -954,6 +960,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
}
const isFormCaught = (caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n;
return isFormCaught;
}
@ -1151,7 +1158,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.blockInput = false;
} else {
ui.revertMode().then(() => {
console.log("exitCallback", this.exitCallback);
if (this.exitCallback instanceof Function) {
const exitCallback = this.exitCallback;
this.exitCallback = null;

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,8 @@ import { DropDownColumn } from "#app/ui/filter-bar";
import type PokemonSpecies from "#app/data/pokemon-species";
import { PokemonType } from "#enums/pokemon-type";
import { UiMode } from "#enums/ui-mode";
import PokedexPageUiHandler from "#app/ui/pokedex-page-ui-handler";
import type { StarterAttributes } from "#app/system/game-data";
/*
Information for the `data_pokedex_tests.psrv`:
@ -80,6 +82,26 @@ describe("UI - Pokedex", () => {
return handler as PokedexUiHandler;
}
/**
* Run the game to open the pokedex UI.
* @returns The handler for the pokedex UI.
*/
async function runToPokedexPage(
species: PokemonSpecies,
starterAttributes: StarterAttributes = {},
): Promise<PokedexPageUiHandler> {
// Open the pokedex UI.
await game.runToTitle();
await game.phaseInterceptor.setOverlayMode(UiMode.POKEDEX_PAGE, species, starterAttributes);
// Get the handler for the current UI.
const handler = game.scene.ui.getHandler();
expect(handler).toBeInstanceOf(PokedexPageUiHandler);
return handler as PokedexPageUiHandler;
}
/**
* Compute a set of pokemon that have a specific ability in allAbilities
* @param ability - The ability to filter for
@ -489,4 +511,37 @@ describe("UI - Pokedex", () => {
expect(selectedPokemon).toEqual(pokedexHandler.lastSpecies.speciesId);
},
);
/****************************
* Tests for Pokédex Pages *
****************************/
it("should show caught battle form as caught", async () => {
await game.importData("./test/testUtils/saves/data_pokedex_tests_v2.prsv");
const pageHandler = await runToPokedexPage(getPokemonSpecies(Species.VENUSAUR), { form: 1 });
// @ts-expect-error - `species` is private
expect(pageHandler.species.speciesId).toEqual(Species.VENUSAUR);
// @ts-expect-error - `formIndex` is private
expect(pageHandler.formIndex).toEqual(1);
expect(pageHandler.isFormCaught()).toEqual(true);
expect(pageHandler.isSeen()).toEqual(true);
});
//TODO: check tint of the sprite
it("should show uncaught battle form as seen", async () => {
await game.importData("./test/testUtils/saves/data_pokedex_tests_v2.prsv");
const pageHandler = await runToPokedexPage(getPokemonSpecies(Species.VENUSAUR), { form: 2 });
// @ts-expect-error - `species` is private
expect(pageHandler.species.speciesId).toEqual(Species.VENUSAUR);
// @ts-expect-error - `formIndex` is private
expect(pageHandler.formIndex).toEqual(2);
expect(pageHandler.isFormCaught()).toEqual(false);
expect(pageHandler.isSeen()).toEqual(true);
});
});