Renamed fields in StarterPreferences

This commit is contained in:
Wlowscha 2025-09-08 16:09:20 +02:00
parent 8db5b96afc
commit 1a4de942f7
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04
6 changed files with 50 additions and 49 deletions

View File

@ -169,9 +169,9 @@ export interface StarterMoveData {
export interface StarterPreferences { export interface StarterPreferences {
nature?: number; nature?: number;
ability?: number; abilityIndex?: number;
variant?: number; variant?: number;
form?: number; formIndex?: number;
female?: boolean; female?: boolean;
shiny?: boolean; shiny?: boolean;
favorite?: boolean; favorite?: boolean;

View File

@ -548,7 +548,7 @@ export class StarterSummary extends Phaser.GameObjects.Container {
} }
const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
props.formIndex = starterPreferences?.form ?? props.formIndex; props.formIndex = starterPreferences?.formIndex ?? props.formIndex;
const speciesForm = getPokemonSpeciesForm(species.speciesId, props.formIndex); const speciesForm = getPokemonSpeciesForm(species.speciesId, props.formIndex);
this.setTypeIcons(speciesForm.type1, speciesForm.type2); this.setTypeIcons(speciesForm.type1, speciesForm.type2);

View File

@ -727,7 +727,7 @@ export class PokedexPageUiHandler extends MessageUiHandler {
variant: 0, variant: 0,
form: 0, form: 0,
}; };
this.formIndex = this.savedStarterPreferences.form ?? 0; this.formIndex = this.savedStarterPreferences.formIndex ?? 0;
this.filteredIndices = args[2] ?? null; this.filteredIndices = args[2] ?? null;
this.starterSetup(); this.starterSetup();
@ -1632,8 +1632,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
: ""; : "";
const matchingForm = newSpecies?.forms.find(form => form.formKey === newFormKey); const matchingForm = newSpecies?.forms.find(form => form.formKey === newFormKey);
const newFormIndex = matchingForm ? matchingForm.formIndex : 0; const newFormIndex = matchingForm ? matchingForm.formIndex : 0;
this.starterPreferences.form = newFormIndex; this.starterPreferences.formIndex = newFormIndex;
this.savedStarterPreferences.form = newFormIndex; this.savedStarterPreferences.formIndex = newFormIndex;
this.moveInfoOverlay.clear(); this.moveInfoOverlay.clear();
this.clearText(); this.clearText();
ui.setMode(UiMode.POKEDEX_PAGE, newSpecies, this.savedStarterPreferences); ui.setMode(UiMode.POKEDEX_PAGE, newSpecies, this.savedStarterPreferences);
@ -1674,8 +1674,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
handler: () => { handler: () => {
this.previousSpecies.push(this.species); this.previousSpecies.push(this.species);
this.previousStarterPreferences.push({ ...this.savedStarterPreferences }); this.previousStarterPreferences.push({ ...this.savedStarterPreferences });
this.starterPreferences.form = newFormIndex; this.starterPreferences.formIndex = newFormIndex;
this.savedStarterPreferences.form = newFormIndex; this.savedStarterPreferences.formIndex = newFormIndex;
this.moveInfoOverlay.clear(); this.moveInfoOverlay.clear();
this.clearText(); this.clearText();
ui.setMode(UiMode.POKEDEX_PAGE, evoSpecies, this.savedStarterPreferences); ui.setMode(UiMode.POKEDEX_PAGE, evoSpecies, this.savedStarterPreferences);
@ -1718,8 +1718,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
this.previousStarterPreferences.push({ ...this.savedStarterPreferences }); this.previousStarterPreferences.push({ ...this.savedStarterPreferences });
const newSpecies = this.species; const newSpecies = this.species;
const newFormIndex = this.species.forms.find(f => f.formKey === bf.formKey)?.formIndex; const newFormIndex = this.species.forms.find(f => f.formKey === bf.formKey)?.formIndex;
this.starterPreferences.form = newFormIndex; this.starterPreferences.formIndex = newFormIndex;
this.savedStarterPreferences.form = newFormIndex; this.savedStarterPreferences.formIndex = newFormIndex;
this.moveInfoOverlay.clear(); this.moveInfoOverlay.clear();
this.clearText(); this.clearText();
ui.setMode( ui.setMode(
@ -1879,8 +1879,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
break; break;
} }
} while (newFormIndex !== props.formIndex || this.species.forms[newFormIndex].isUnobtainable); } while (newFormIndex !== props.formIndex || this.species.forms[newFormIndex].isUnobtainable);
starterPreferences.form = newFormIndex; // store the selected form starterPreferences.formIndex = newFormIndex; // store the selected form
this.savedStarterPreferences.form = starterPreferences.form; this.savedStarterPreferences.formIndex = starterPreferences.formIndex;
this.formIndex = newFormIndex; this.formIndex = newFormIndex;
// Some forms are tied to the gender and should change accordingly // Some forms are tied to the gender and should change accordingly
let newFemale = props.female; let newFemale = props.female;
@ -1906,8 +1906,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
if (this.isFormGender) { if (this.isFormGender) {
newFormIndex = this.formIndex === 0 ? 1 : 0; newFormIndex = this.formIndex === 0 ? 1 : 0;
} }
starterPreferences.form = newFormIndex; // store the selected form starterPreferences.formIndex = newFormIndex; // store the selected form
this.savedStarterPreferences.form = starterPreferences.form; this.savedStarterPreferences.formIndex = starterPreferences.formIndex;
this.formIndex = newFormIndex; this.formIndex = newFormIndex;
this.starterSetup(); this.starterSetup();
this.setSpeciesDetails(this.species, { this.setSpeciesDetails(this.species, {
@ -2107,8 +2107,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
form => form.formKey === this.species?.forms[this.formIndex]?.formKey, form => form.formKey === this.species?.forms[this.formIndex]?.formKey,
); );
const newFormIndex = matchingForm ? matchingForm.formIndex : 0; const newFormIndex = matchingForm ? matchingForm.formIndex : 0;
this.starterPreferences.form = newFormIndex; this.starterPreferences.formIndex = newFormIndex;
this.savedStarterPreferences.form = newFormIndex; this.savedStarterPreferences.formIndex = newFormIndex;
this.moveInfoOverlay.clear(); this.moveInfoOverlay.clear();
this.clearText(); this.clearText();
ui.setModeForceTransition( ui.setModeForceTransition(
@ -2146,8 +2146,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
form => form.formKey === this.species?.forms[this.formIndex]?.formKey, form => form.formKey === this.species?.forms[this.formIndex]?.formKey,
); );
const newFormIndex = matchingForm ? matchingForm.formIndex : 0; const newFormIndex = matchingForm ? matchingForm.formIndex : 0;
this.starterPreferences.form = newFormIndex; this.starterPreferences.formIndex = newFormIndex;
this.savedStarterPreferences.form = newFormIndex; this.savedStarterPreferences.formIndex = newFormIndex;
this.moveInfoOverlay.clear(); this.moveInfoOverlay.clear();
this.clearText(); this.clearText();
ui.setModeForceTransition( ui.setModeForceTransition(
@ -2336,12 +2336,12 @@ export class PokedexPageUiHandler extends MessageUiHandler {
props.variant = starterPreferences.variant as Variant; props.variant = starterPreferences.variant as Variant;
} }
} }
props.form = starterPreferences?.form ?? props.form; props.formIndex = starterPreferences?.formIndex ?? props.formIndex;
props.female = starterPreferences?.female ?? props.female; props.female = starterPreferences?.female ?? props.female;
this.setSpeciesDetails(species, { this.setSpeciesDetails(species, {
shiny: props.shiny, shiny: props.shiny,
formIndex: props.form, formIndex: props.formIndex,
female: props.female, female: props.female,
variant: props.variant ?? 0, variant: props.variant ?? 0,
}); });
@ -2443,7 +2443,7 @@ export class PokedexPageUiHandler extends MessageUiHandler {
variant = oldProps?.variant ?? 0; variant = oldProps?.variant ?? 0;
} }
if (formIndex === undefined) { if (formIndex === undefined) {
formIndex = oldProps?.form ?? 0; formIndex = oldProps?.formIndex ?? 0;
} }
} }
@ -2463,8 +2463,8 @@ export class PokedexPageUiHandler extends MessageUiHandler {
if (shiny === undefined || shiny !== props.shiny) { if (shiny === undefined || shiny !== props.shiny) {
shiny = props.shiny; shiny = props.shiny;
} }
if (formIndex === undefined || formIndex !== props.form) { if (formIndex === undefined || formIndex !== props.formIndex) {
formIndex = props.form; formIndex = props.formIndex;
} }
if (female === undefined || female !== props.female) { if (female === undefined || female !== props.female) {
female = props.female; female = props.female;
@ -2763,9 +2763,9 @@ export class PokedexPageUiHandler extends MessageUiHandler {
props += DexAttr.NON_SHINY; props += DexAttr.NON_SHINY;
props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant
} }
if (this.starterPreferences?.form) { if (this.starterPreferences?.formIndex) {
// this checks for the form of the pokemon // this checks for the form of the pokemon
props += BigInt(Math.pow(2, this.starterPreferences?.form)) * DexAttr.DEFAULT_FORM; props += BigInt(Math.pow(2, this.starterPreferences?.formIndex)) * DexAttr.DEFAULT_FORM;
} else { } else {
// Get the first unlocked form // Get the first unlocked form
props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr));

View File

@ -732,7 +732,7 @@ export class PokedexUiHandler extends MessageUiHandler {
} }
} }
if (starterPreferences.ability !== undefined) { if (starterPreferences.abilityIndex !== undefined) {
const speciesHasSingleAbility = species.ability2 === species.ability1; const speciesHasSingleAbility = species.ability2 === species.ability1;
const abilityAttr = starterData.abilityAttr; const abilityAttr = starterData.abilityAttr;
const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1; const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1;
@ -745,20 +745,20 @@ export class PokedexUiHandler extends MessageUiHandler {
speciesHasSingleAbility ? hasAbility2 && !hasAbility1 : hasAbility2, speciesHasSingleAbility ? hasAbility2 && !hasAbility1 : hasAbility2,
hasHiddenAbility, hasHiddenAbility,
]; ];
if (!unlockedAbilities[starterPreferences.ability]) { if (!unlockedAbilities[starterPreferences.abilityIndex]) {
// requested ability wasn't unlocked, purging setting // requested ability wasn't unlocked, purging setting
starterPreferences.ability = undefined; starterPreferences.abilityIndex = undefined;
} }
} }
const selectedForm = starterPreferences.form; const selectedForm = starterPreferences.formIndex;
if ( if (
selectedForm !== undefined && selectedForm !== undefined &&
(!species.forms[selectedForm]?.isStarterSelectable || (!species.forms[selectedForm]?.isStarterSelectable ||
!(caughtAttr & globalScene.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
starterPreferences.form = undefined; starterPreferences.formIndex = undefined;
} }
if (starterPreferences.nature !== undefined) { if (starterPreferences.nature !== undefined) {
@ -2357,9 +2357,9 @@ export class PokedexUiHandler extends MessageUiHandler {
props += DexAttr.NON_SHINY; props += DexAttr.NON_SHINY;
props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant
} }
if (this.starterPreferences[speciesId]?.form) { if (this.starterPreferences[speciesId]?.formIndex) {
// this checks for the form of the pokemon // this checks for the form of the pokemon
props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM; props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.formIndex)) * DexAttr.DEFAULT_FORM;
} else { } else {
// Get the first unlocked form // Get the first unlocked form
props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr));

View File

@ -858,7 +858,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
} }
} }
if (starterPreferences.ability !== undefined) { if (starterPreferences.abilityIndex !== undefined) {
const speciesHasSingleAbility = species.ability2 === species.ability1; const speciesHasSingleAbility = species.ability2 === species.ability1;
const abilityAttr = starterData.abilityAttr; const abilityAttr = starterData.abilityAttr;
const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1; const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1;
@ -871,20 +871,20 @@ export class StarterSelectUiHandler extends MessageUiHandler {
speciesHasSingleAbility ? hasAbility2 && !hasAbility1 : hasAbility2, speciesHasSingleAbility ? hasAbility2 && !hasAbility1 : hasAbility2,
hasHiddenAbility, hasHiddenAbility,
]; ];
if (!unlockedAbilities[starterPreferences.ability]) { if (!unlockedAbilities[starterPreferences.abilityIndex]) {
// requested ability wasn't unlocked, purging setting // requested ability wasn't unlocked, purging setting
starterPreferences.ability = undefined; starterPreferences.abilityIndex = undefined;
} }
} }
const selectedForm = starterPreferences.form; const selectedForm = starterPreferences.formIndex;
if ( if (
selectedForm !== undefined && selectedForm !== undefined &&
(!species.forms[selectedForm]?.isStarterSelectable || (!species.forms[selectedForm]?.isStarterSelectable ||
!(caughtAttr & globalScene.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
starterPreferences.form = undefined; starterPreferences.formIndex = undefined;
} }
if (starterPreferences.nature !== undefined) { if (starterPreferences.nature !== undefined) {
@ -1457,8 +1457,8 @@ export class StarterSelectUiHandler extends MessageUiHandler {
break; break;
} }
} while (newFormIndex !== props.formIndex); } while (newFormIndex !== props.formIndex);
starterPreferences.form = newFormIndex; // store the selected form starterPreferences.formIndex = newFormIndex; // store the selected form
originalStarterPreferences.form = newFormIndex; originalStarterPreferences.formIndex = newFormIndex;
starterPreferences.tera = this.lastSpecies.forms[newFormIndex].type1; starterPreferences.tera = this.lastSpecies.forms[newFormIndex].type1;
originalStarterPreferences.tera = starterPreferences.tera; originalStarterPreferences.tera = starterPreferences.tera;
this.setSpeciesDetails(this.lastSpecies, { this.setSpeciesDetails(this.lastSpecies, {
@ -1502,8 +1502,8 @@ export class StarterSelectUiHandler extends MessageUiHandler {
} }
} }
} while (newAbilityIndex !== this.abilityCursor); } while (newAbilityIndex !== this.abilityCursor);
starterPreferences.ability = newAbilityIndex; // store the selected ability starterPreferences.abilityIndex = newAbilityIndex; // store the selected ability
originalStarterPreferences.ability = newAbilityIndex; originalStarterPreferences.abilityIndex = newAbilityIndex;
this.setSpeciesDetails(this.lastSpecies, { this.setSpeciesDetails(this.lastSpecies, {
abilityIndex: newAbilityIndex, abilityIndex: newAbilityIndex,
@ -1527,7 +1527,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
break; break;
case Button.CYCLE_TERA: case Button.CYCLE_TERA:
if (this.canCycleTera) { if (this.canCycleTera) {
const speciesForm = getPokemonSpeciesForm(this.lastSpecies.speciesId, starterPreferences.form ?? 0); const speciesForm = getPokemonSpeciesForm(this.lastSpecies.speciesId, starterPreferences.formIndex ?? 0);
if (speciesForm.type1 === this.teraCursor && !isNullOrUndefined(speciesForm.type2)) { if (speciesForm.type1 === this.teraCursor && !isNullOrUndefined(speciesForm.type2)) {
starterPreferences.tera = speciesForm.type2; starterPreferences.tera = speciesForm.type2;
originalStarterPreferences.tera = starterPreferences.tera; originalStarterPreferences.tera = starterPreferences.tera;
@ -2097,7 +2097,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
const attributes = { const attributes = {
shiny: starterPreferences.shiny, shiny: starterPreferences.shiny,
variant: starterPreferences.variant, variant: starterPreferences.variant,
form: starterPreferences.form, form: starterPreferences.formIndex,
female: starterPreferences.female, female: starterPreferences.female,
}; };
ui.setOverlayMode(UiMode.POKEDEX_PAGE, this.lastSpecies, attributes, null, null, () => { ui.setOverlayMode(UiMode.POKEDEX_PAGE, this.lastSpecies, attributes, null, null, () => {
@ -3007,8 +3007,8 @@ export class StarterSelectUiHandler extends MessageUiHandler {
if (starterPreferences?.nature) { if (starterPreferences?.nature) {
this.natureCursor = starterPreferences.nature; this.natureCursor = starterPreferences.nature;
} }
if (starterPreferences?.ability && !Number.isNaN(starterPreferences.ability)) { if (starterPreferences?.abilityIndex && !Number.isNaN(starterPreferences.abilityIndex)) {
this.abilityCursor = starterPreferences.ability; this.abilityCursor = starterPreferences.abilityIndex;
} }
if (starterPreferences?.tera) { if (starterPreferences?.tera) {
this.teraCursor = starterPreferences.tera; this.teraCursor = starterPreferences.tera;
@ -3027,7 +3027,8 @@ export class StarterSelectUiHandler extends MessageUiHandler {
const props = this.getSpeciesPropsFromPreferences(species); const props = this.getSpeciesPropsFromPreferences(species);
const ability = starterPreferences?.ability ?? globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species); const ability =
starterPreferences?.abilityIndex ?? globalScene.gameData.getStarterSpeciesDefaultAbilityIndex(species);
const nature = starterPreferences?.nature || globalScene.gameData.getSpeciesDefaultNature(species, dexEntry); const nature = starterPreferences?.nature || globalScene.gameData.getSpeciesDefaultNature(species, dexEntry);
// TODO: are these checks necessary? getSpeciesPropsFromPreferences should have already done this. // TODO: are these checks necessary? getSpeciesPropsFromPreferences should have already done this.
@ -3036,7 +3037,7 @@ export class StarterSelectUiHandler extends MessageUiHandler {
props.variant = starterPreferences.variant as Variant; props.variant = starterPreferences.variant as Variant;
} }
} }
props.formIndex = starterPreferences?.form ?? props.formIndex; props.formIndex = starterPreferences?.formIndex ?? props.formIndex;
props.female = starterPreferences?.female ?? props.female; props.female = starterPreferences?.female ?? props.female;
this.setSpeciesDetails( this.setSpeciesDetails(

View File

@ -514,7 +514,7 @@ describe("UI - Pokedex", () => {
it("should show caught battle form as caught", async () => { it("should show caught battle form as caught", async () => {
await game.importData("./test/test-utils/saves/data_pokedex_tests_v2.prsv"); await game.importData("./test/test-utils/saves/data_pokedex_tests_v2.prsv");
const pageHandler = await runToPokedexPage(getPokemonSpecies(SpeciesId.VENUSAUR), { form: 1 }); const pageHandler = await runToPokedexPage(getPokemonSpecies(SpeciesId.VENUSAUR), { formIndex: 1 });
// @ts-expect-error - `species` is private // @ts-expect-error - `species` is private
expect(pageHandler.species.speciesId).toEqual(SpeciesId.VENUSAUR); expect(pageHandler.species.speciesId).toEqual(SpeciesId.VENUSAUR);
@ -529,7 +529,7 @@ describe("UI - Pokedex", () => {
//TODO: check tint of the sprite //TODO: check tint of the sprite
it("should show uncaught battle form as seen", async () => { it("should show uncaught battle form as seen", async () => {
await game.importData("./test/test-utils/saves/data_pokedex_tests_v2.prsv"); await game.importData("./test/test-utils/saves/data_pokedex_tests_v2.prsv");
const pageHandler = await runToPokedexPage(getPokemonSpecies(SpeciesId.VENUSAUR), { form: 2 }); const pageHandler = await runToPokedexPage(getPokemonSpecies(SpeciesId.VENUSAUR), { formIndex: 2 });
// @ts-expect-error - `species` is private // @ts-expect-error - `species` is private
expect(pageHandler.species.speciesId).toEqual(SpeciesId.VENUSAUR); expect(pageHandler.species.speciesId).toEqual(SpeciesId.VENUSAUR);