Adding pokédex to admin panel

This commit is contained in:
Wlowscha 2025-09-20 20:42:51 +02:00
parent b6a3cc82be
commit cfb0857b44
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
2 changed files with 55 additions and 48 deletions

View File

@ -417,6 +417,9 @@ export class AdminUiHandler extends FormModalUiHandler {
() => { () => {
globalScene.ui.setOverlayMode(UiMode.GAME_STATS, this.tempGameData); globalScene.ui.setOverlayMode(UiMode.GAME_STATS, this.tempGameData);
}, },
() => {
globalScene.ui.setOverlayMode(UiMode.POKEDEX, this.tempGameData);
},
], ],
}, },
mode, mode,

View File

@ -31,6 +31,7 @@ import { UiMode } from "#enums/ui-mode";
import { UiTheme } from "#enums/ui-theme"; import { UiTheme } from "#enums/ui-theme";
import type { Variant } from "#sprites/variant"; import type { Variant } from "#sprites/variant";
import { getVariantIcon, getVariantTint } from "#sprites/variant"; import { getVariantIcon, getVariantTint } from "#sprites/variant";
import type { GameData } from "#system/game-data";
import { SettingKeyboard } from "#system/settings-keyboard"; import { SettingKeyboard } from "#system/settings-keyboard";
import type { DexEntry } from "#types/dex-data"; import type { DexEntry } from "#types/dex-data";
import type { DexAttrProps, StarterAttributes } from "#types/save-data"; import type { DexAttrProps, StarterAttributes } from "#types/save-data";
@ -236,6 +237,7 @@ export class PokedexUiHandler extends MessageUiHandler {
private showFormTrayLabel: Phaser.GameObjects.Text; private showFormTrayLabel: Phaser.GameObjects.Text;
private canShowFormTray: boolean; private canShowFormTray: boolean;
private filteredIndices: SpeciesId[]; private filteredIndices: SpeciesId[];
private gameData: GameData;
constructor() { constructor() {
super(UiMode.POKEDEX); super(UiMode.POKEDEX);
@ -641,9 +643,14 @@ export class PokedexUiHandler extends MessageUiHandler {
this.pokerusSpecies = getPokerusStarters(); this.pokerusSpecies = getPokerusStarters();
this.gameData = globalScene.gameData;
// When calling with "refresh", we do not reset the cursor and filters // When calling with "refresh", we do not reset the cursor and filters
if (args.length > 0 && args[0] === "refresh") { if (args.length > 0) {
return false; if (args[0] === "refresh") {
return false;
}
this.gameData = args[0];
} }
super.show(args); super.show(args);
@ -685,8 +692,8 @@ export class PokedexUiHandler extends MessageUiHandler {
*/ */
initStarterPrefs(species: PokemonSpecies): StarterAttributes { initStarterPrefs(species: PokemonSpecies): StarterAttributes {
const starterAttributes = this.starterPreferences[species.speciesId]; const starterAttributes = this.starterPreferences[species.speciesId];
const dexEntry = globalScene.gameData.dexData[species.speciesId]; const dexEntry = this.gameData.dexData[species.speciesId];
const starterData = globalScene.gameData.starterData[species.speciesId]; const starterData = this.gameData.starterData[species.speciesId];
// no preferences or Pokemon wasn't caught, return empty attribute // no preferences or Pokemon wasn't caught, return empty attribute
if (!starterAttributes || !dexEntry.caughtAttr) { if (!starterAttributes || !dexEntry.caughtAttr) {
@ -753,15 +760,14 @@ export class PokedexUiHandler extends MessageUiHandler {
const selectedForm = starterAttributes.form; const selectedForm = starterAttributes.form;
if ( if (
selectedForm !== undefined selectedForm !== undefined
&& (!species.forms[selectedForm]?.isStarterSelectable && (!species.forms[selectedForm]?.isStarterSelectable || !(caughtAttr & this.gameData.getFormAttr(selectedForm)))
|| !(caughtAttr & globalScene.gameData.getFormAttr(selectedForm)))
) { ) {
// requested form wasn't unlocked/isn't a starter form, purging setting // requested form wasn't unlocked/isn't a starter form, purging setting
starterAttributes.form = undefined; starterAttributes.form = undefined;
} }
if (starterAttributes.nature !== undefined) { if (starterAttributes.nature !== undefined) {
const unlockedNatures = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr); const unlockedNatures = this.gameData.getNaturesForAttr(dexEntry.natureAttr);
if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) { if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) {
// requested nature wasn't unlocked, purging setting // requested nature wasn't unlocked, purging setting
starterAttributes.nature = undefined; starterAttributes.nature = undefined;
@ -812,7 +818,7 @@ export class PokedexUiHandler extends MessageUiHandler {
return true; return true;
} }
if (!seenFilter) { if (!seenFilter) {
const starterDexEntry = globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)]; const starterDexEntry = this.gameData.dexData[this.getStarterSpeciesId(species.speciesId)];
return !!starterDexEntry?.caughtAttr; return !!starterDexEntry?.caughtAttr;
} }
return false; return false;
@ -851,7 +857,7 @@ export class PokedexUiHandler extends MessageUiHandler {
*/ */
isPassiveAvailable(speciesId: number): boolean { isPassiveAvailable(speciesId: number): boolean {
// Get this species ID's starter data // Get this species ID's starter data
const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; const starterData = this.gameData.starterData[this.getStarterSpeciesId(speciesId)];
return ( return (
starterData.candyCount >= getPassiveCandyCount(speciesStarterCosts[this.getStarterSpeciesId(speciesId)]) starterData.candyCount >= getPassiveCandyCount(speciesStarterCosts[this.getStarterSpeciesId(speciesId)])
@ -866,7 +872,7 @@ export class PokedexUiHandler extends MessageUiHandler {
*/ */
isValueReductionAvailable(speciesId: number): boolean { isValueReductionAvailable(speciesId: number): boolean {
// Get this species ID's starter data // Get this species ID's starter data
const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; const starterData = this.gameData.starterData[this.getStarterSpeciesId(speciesId)];
return ( return (
starterData.candyCount starterData.candyCount
@ -883,7 +889,7 @@ export class PokedexUiHandler extends MessageUiHandler {
*/ */
isSameSpeciesEggAvailable(speciesId: number): boolean { isSameSpeciesEggAvailable(speciesId: number): boolean {
// Get this species ID's starter data // Get this species ID's starter data
const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; const starterData = this.gameData.starterData[this.getStarterSpeciesId(speciesId)];
return ( return (
starterData.candyCount >= getSameSpeciesEggCandyCounts(speciesStarterCosts[this.getStarterSpeciesId(speciesId)]) starterData.candyCount >= getSameSpeciesEggCandyCounts(speciesStarterCosts[this.getStarterSpeciesId(speciesId)])
@ -1372,21 +1378,21 @@ export class PokedexUiHandler extends MessageUiHandler {
const starterId = this.getStarterSpeciesId(species.speciesId); const starterId = this.getStarterSpeciesId(species.speciesId);
const currentDexAttr = this.getCurrentDexProps(species.speciesId); const currentDexAttr = this.getCurrentDexProps(species.speciesId);
const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(species, currentDexAttr)); const props = this.getSanitizedProps(this.gameData.getSpeciesDexAttrProps(species, currentDexAttr));
const data: ContainerData = { const data: ContainerData = {
species, species,
cost: globalScene.gameData.getSpeciesStarterValue(starterId), cost: this.gameData.getSpeciesStarterValue(starterId),
props, props,
}; };
// First, ensure you have the caught attributes for the species else default to bigint 0 // First, ensure you have the caught attributes for the species else default to bigint 0
// TODO: This might be removed depending on how accessible we want the pokedex function to be // TODO: This might be removed depending on how accessible we want the pokedex function to be
const caughtAttr = const caughtAttr =
(globalScene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0)) (this.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0))
& (globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)]?.caughtAttr || BigInt(0)) & (this.gameData.dexData[this.getStarterSpeciesId(species.speciesId)]?.caughtAttr || BigInt(0))
& species.getFullUnlocksData(); & species.getFullUnlocksData();
const starterData = globalScene.gameData.starterData[starterId]; const starterData = this.gameData.starterData[starterId];
const isStarterProgressable = speciesEggMoves.hasOwnProperty(starterId); const isStarterProgressable = speciesEggMoves.hasOwnProperty(starterId);
// Name filter // Name filter
@ -1635,7 +1641,7 @@ export class PokedexUiHandler extends MessageUiHandler {
}); });
// Seen Filter // Seen Filter
const dexEntry = globalScene.gameData.dexData[species.speciesId]; const dexEntry = this.gameData.dexData[species.speciesId];
const isItSeen = this.isSeen(species, dexEntry, true) || !!dexEntry.caughtAttr; const isItSeen = this.isSeen(species, dexEntry, true) || !!dexEntry.caughtAttr;
const fitsSeen = this.filterBar.getVals(DropDownColumn.MISC).some(misc => { const fitsSeen = this.filterBar.getVals(DropDownColumn.MISC).some(misc => {
if (misc.val === "SEEN_SPECIES" && misc.state === DropDownState.ON) { if (misc.val === "SEEN_SPECIES" && misc.state === DropDownState.ON) {
@ -1725,33 +1731,31 @@ export class PokedexUiHandler extends MessageUiHandler {
case SortCriteria.COST: case SortCriteria.COST:
return (a.cost - b.cost) * -sort.dir; return (a.cost - b.cost) * -sort.dir;
case SortCriteria.CANDY: { case SortCriteria.CANDY: {
const candyCountA = const candyCountA = this.gameData.starterData[this.getStarterSpeciesId(a.species.speciesId)].candyCount;
globalScene.gameData.starterData[this.getStarterSpeciesId(a.species.speciesId)].candyCount; const candyCountB = this.gameData.starterData[this.getStarterSpeciesId(b.species.speciesId)].candyCount;
const candyCountB =
globalScene.gameData.starterData[this.getStarterSpeciesId(b.species.speciesId)].candyCount;
return (candyCountA - candyCountB) * -sort.dir; return (candyCountA - candyCountB) * -sort.dir;
} }
case SortCriteria.IV: { case SortCriteria.IV: {
const avgIVsA = const avgIVsA =
globalScene.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0) this.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0)
/ globalScene.gameData.dexData[a.species.speciesId].ivs.length; / this.gameData.dexData[a.species.speciesId].ivs.length;
const avgIVsB = const avgIVsB =
globalScene.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0) this.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0)
/ globalScene.gameData.dexData[b.species.speciesId].ivs.length; / this.gameData.dexData[b.species.speciesId].ivs.length;
return (avgIVsA - avgIVsB) * -sort.dir; return (avgIVsA - avgIVsB) * -sort.dir;
} }
case SortCriteria.NAME: case SortCriteria.NAME:
return a.species.name.localeCompare(b.species.name) * -sort.dir; return a.species.name.localeCompare(b.species.name) * -sort.dir;
case SortCriteria.CAUGHT: case SortCriteria.CAUGHT:
return ( return (
(globalScene.gameData.dexData[a.species.speciesId].caughtCount (this.gameData.dexData[a.species.speciesId].caughtCount
- globalScene.gameData.dexData[b.species.speciesId].caughtCount) - this.gameData.dexData[b.species.speciesId].caughtCount)
* -sort.dir * -sort.dir
); );
case SortCriteria.HATCHED: case SortCriteria.HATCHED:
return ( return (
(globalScene.gameData.dexData[this.getStarterSpeciesId(a.species.speciesId)].hatchedCount (this.gameData.dexData[this.getStarterSpeciesId(a.species.speciesId)].hatchedCount
- globalScene.gameData.dexData[this.getStarterSpeciesId(b.species.speciesId)].hatchedCount) - this.gameData.dexData[this.getStarterSpeciesId(b.species.speciesId)].hatchedCount)
* -sort.dir * -sort.dir
); );
default: default:
@ -1795,10 +1799,10 @@ export class PokedexUiHandler extends MessageUiHandler {
container.checkIconId(props.female, props.formIndex, props.shiny, props.variant); container.checkIconId(props.female, props.formIndex, props.shiny, props.variant);
const speciesId = data.species.speciesId; const speciesId = data.species.speciesId;
const dexEntry = globalScene.gameData.dexData[speciesId]; const dexEntry = this.gameData.dexData[speciesId];
const caughtAttr = const caughtAttr =
dexEntry.caughtAttr dexEntry.caughtAttr
& globalScene.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr & this.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr
& data.species.getFullUnlocksData(); & data.species.getFullUnlocksData();
if (caughtAttr & data.species.getFullUnlocksData() || globalScene.dexForDevs) { if (caughtAttr & data.species.getFullUnlocksData() || globalScene.dexForDevs) {
@ -1857,13 +1861,13 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
container.starterPassiveBgs.setVisible( container.starterPassiveBgs.setVisible(
!!globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].passiveAttr, !!this.gameData.starterData[this.getStarterSpeciesId(speciesId)].passiveAttr,
); );
container.hiddenAbilityIcon.setVisible( container.hiddenAbilityIcon.setVisible(
!!caughtAttr && !!(globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].abilityAttr & 4), !!caughtAttr && !!(this.gameData.starterData[this.getStarterSpeciesId(speciesId)].abilityAttr & 4),
); );
container.classicWinIcon.setVisible( container.classicWinIcon.setVisible(
globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].classicWinCount > 0, this.gameData.starterData[this.getStarterSpeciesId(speciesId)].classicWinCount > 0,
); );
container.favoriteIcon.setVisible(this.starterPreferences[speciesId]?.favorite ?? false); container.favoriteIcon.setVisible(this.starterPreferences[speciesId]?.favorite ?? false);
@ -1989,15 +1993,15 @@ export class PokedexUiHandler extends MessageUiHandler {
this.formTrayContainer.setX((goLeft ? boxPos.x - 18 * (this.trayColumns - spaceRight) : boxPos.x) - 3); this.formTrayContainer.setX((goLeft ? boxPos.x - 18 * (this.trayColumns - spaceRight) : boxPos.x) - 3);
this.formTrayContainer.setY(goUp ? boxPos.y - this.trayBg.height : boxPos.y + 17); this.formTrayContainer.setY(goUp ? boxPos.y - this.trayBg.height : boxPos.y + 17);
const dexEntry = globalScene.gameData.dexData[species.speciesId]; const dexEntry = this.gameData.dexData[species.speciesId];
const dexAttr = this.getCurrentDexProps(species.speciesId); const dexAttr = this.getCurrentDexProps(species.speciesId);
const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr)); const props = this.getSanitizedProps(this.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr));
this.trayContainers = []; this.trayContainers = [];
const isFormSeen = this.isSeen(species, dexEntry); const isFormSeen = this.isSeen(species, dexEntry);
this.trayForms.map((f, index) => { this.trayForms.map((f, index) => {
const isFormCaught = dexEntry const isFormCaught = dexEntry
? (dexEntry.caughtAttr & species.getFullUnlocksData() & globalScene.gameData.getFormAttr(f.formIndex ?? 0)) > 0n ? (dexEntry.caughtAttr & species.getFullUnlocksData() & this.gameData.getFormAttr(f.formIndex ?? 0)) > 0n
: false; : false;
const formContainer = new PokedexMonContainer(species, { const formContainer = new PokedexMonContainer(species, {
formIndex: f.formIndex, formIndex: f.formIndex,
@ -2066,7 +2070,7 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
getFriendship(speciesId: number) { getFriendship(speciesId: number) {
let currentFriendship = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship; let currentFriendship = this.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship;
if (!currentFriendship || currentFriendship === undefined) { if (!currentFriendship || currentFriendship === undefined) {
currentFriendship = 0; currentFriendship = 0;
} }
@ -2094,7 +2098,7 @@ export class PokedexUiHandler extends MessageUiHandler {
if (container) { if (container) {
const lastSpeciesIcon = container.icon; const lastSpeciesIcon = container.icon;
const dexAttr = this.getCurrentDexProps(container.species.speciesId); const dexAttr = this.getCurrentDexProps(container.species.speciesId);
const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(container.species, dexAttr)); const props = this.getSanitizedProps(this.gameData.getSpeciesDexAttrProps(container.species, dexAttr));
this.checkIconId(lastSpeciesIcon, container.species, props.female, props.formIndex, props.shiny, props.variant); this.checkIconId(lastSpeciesIcon, container.species, props.female, props.formIndex, props.shiny, props.variant);
this.iconAnimHandler.addOrUpdate(lastSpeciesIcon, PokemonIconAnimMode.NONE); this.iconAnimHandler.addOrUpdate(lastSpeciesIcon, PokemonIconAnimMode.NONE);
// Resume the animation for the previously selected species // Resume the animation for the previously selected species
@ -2103,7 +2107,7 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
setSpecies(species: PokemonSpecies | null) { setSpecies(species: PokemonSpecies | null) {
this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; this.speciesStarterDexEntry = species ? this.gameData.dexData[species.speciesId] : null;
if (!species && globalScene.ui.getTooltip().visible) { if (!species && globalScene.ui.getTooltip().visible) {
globalScene.ui.hideTooltip(); globalScene.ui.hideTooltip();
@ -2182,15 +2186,15 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
if (species) { if (species) {
const dexEntry = globalScene.gameData.dexData[species.speciesId]; const dexEntry = this.gameData.dexData[species.speciesId];
const caughtAttr = const caughtAttr =
dexEntry.caughtAttr dexEntry.caughtAttr
& globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)].caughtAttr & this.gameData.dexData[this.getStarterSpeciesId(species.speciesId)].caughtAttr
& species.getFullUnlocksData(); & species.getFullUnlocksData();
if (caughtAttr) { if (caughtAttr) {
const props = this.getSanitizedProps( const props = this.getSanitizedProps(
globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), this.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)),
); );
if (shiny === undefined) { if (shiny === undefined) {
@ -2207,7 +2211,7 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
} }
const isFormCaught = dexEntry ? (caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false; const isFormCaught = dexEntry ? (caughtAttr & this.gameData.getFormAttr(formIndex ?? 0)) > 0n : false;
const isFormSeen = this.isSeen(species, dexEntry); const isFormSeen = this.isSeen(species, dexEntry);
const assetLoadCancelled = new BooleanHolder(false); const assetLoadCancelled = new BooleanHolder(false);
@ -2291,7 +2295,7 @@ export class PokedexUiHandler extends MessageUiHandler {
updateStarterValueLabel(starter: PokedexMonContainer): void { updateStarterValueLabel(starter: PokedexMonContainer): void {
const speciesId = starter.species.speciesId; const speciesId = starter.species.speciesId;
const baseStarterValue = speciesStarterCosts[speciesId]; const baseStarterValue = speciesStarterCosts[speciesId];
const starterValue = globalScene.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(speciesId)); const starterValue = this.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(speciesId));
starter.cost = starterValue; starter.cost = starterValue;
let valueStr = starterValue.toString(); let valueStr = starterValue.toString();
if (valueStr.startsWith("0.")) { if (valueStr.startsWith("0.")) {
@ -2356,8 +2360,8 @@ export class PokedexUiHandler extends MessageUiHandler {
let props = 0n; let props = 0n;
const species = allSpecies.find(sp => sp.speciesId === speciesId); const species = allSpecies.find(sp => sp.speciesId === speciesId);
const caughtAttr = const caughtAttr =
globalScene.gameData.dexData[speciesId].caughtAttr this.gameData.dexData[speciesId].caughtAttr
& globalScene.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr & this.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr
& (species?.getFullUnlocksData() ?? 0n); & (species?.getFullUnlocksData() ?? 0n);
/* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props /* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props
@ -2401,7 +2405,7 @@ export class PokedexUiHandler extends MessageUiHandler {
props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM; props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM;
} else { } else {
// Get the first unlocked form // Get the first unlocked form
props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); props += this.gameData.getFormAttr(this.gameData.getFormIndex(caughtAttr));
} }
return props; return props;