diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 18f85a7ca58..77acff3cc15 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -710,6 +710,42 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali } } + /** + * Find the form name for species with just one form (regional variants, Floette, Ursaluna) + * @param species the species to check + * @returns the pokemon-form locale key for the single form name ("Alolan Form", "Eternal Flower" etc) + */ + getFormNameToDisplay(formIndex: number = 0, key?: string, append: boolean = false): string { + const formKey = key ?? (this.forms?.[formIndex!]?.formKey); + const formText = Utils.capitalizeString(formKey, "-", false, false) || ""; + const speciesName = Utils.capitalizeString(Species[this.speciesId], "_", true, false); + let ret: string = ""; + + const region = this.getRegion(); + if (this.speciesId === Species.ARCEUS) { + ret = i18next.t(`pokemonInfo:Type.${formText?.toUpperCase()}`); + } else if ([ SpeciesFormKey.MEGA_X, SpeciesFormKey.MEGA_Y, SpeciesFormKey.GIGANTAMAX_RAPID, SpeciesFormKey.GIGANTAMAX_SINGLE ].includes(formKey)) { + return i18next.t(`battlePokemonForm:${formKey}`, { pokemonName: "" }); + } else if (region === Region.NORMAL || (this.speciesId === Species.GALAR_DARMANITAN && formIndex > 0) || this.speciesId === Species.PALDEA_TAUROS) { + const i18key = `pokemonForm:${speciesName}${formText}`; + if (i18next.exists(i18key)) { + ret = i18next.t(i18key); + } else { + const rootSpeciesName = Utils.capitalizeString(Species[this.getRootSpeciesId()], "_", true, false); + const i18RootKey = `pokemonForm:${rootSpeciesName}${formText}`; + ret = i18next.exists(i18RootKey) ? i18next.t(i18RootKey) : formText; + } + } else if (this.speciesId === Species.ETERNAL_FLOETTE) { + ret = i18next.t("pokemonForm:floetteEternalFlower"); + } else if (this.speciesId === Species.BLOODMOON_URSALUNA) { + ret = i18next.t("pokemonForm:ursalunaBloodmoon"); + } else { + const regionalName = i18next.t(`pokemonForm:regionalForm${Region[region]}`); + ret = regionalName; + } + return ret + (append ? this.name : ""); + } + localize(): void { this.name = i18next.t(`pokemon:${Species[this.speciesId].toLowerCase()}`); } diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index a0458d762a8..8d6fab534af 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -15,7 +15,6 @@ import type { SpeciesFormChange } from "#app/data/pokemon-forms"; import { pokemonFormChanges } from "#app/data/pokemon-forms"; import type { LevelMoves } from "#app/data/balance/pokemon-level-moves"; import { pokemonFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves"; -import type { PokemonForm } from "#app/data/pokemon-species"; import type PokemonSpecies from "#app/data/pokemon-species"; import { allSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; import { getStarterValueFriendshipCap, speciesStarterCosts } from "#app/data/balance/starters"; @@ -45,7 +44,7 @@ import { Button } from "#enums/buttons"; import { EggSourceType } from "#enums/egg-source-types"; import { StarterContainer } from "#app/ui/starter-container"; import { getPassiveCandyCount, getValueReductionCandyCounts, getSameSpeciesEggCandyCounts } from "#app/data/balance/starters"; -import { BooleanHolder, capitalizeString, getLocalizedSpriteKey, isNullOrUndefined, NumberHolder, padInt, rgbHexToRgba, toReadableString } from "#app/utils"; +import { BooleanHolder, getLocalizedSpriteKey, isNullOrUndefined, NumberHolder, padInt, rgbHexToRgba, toReadableString } from "#app/utils"; import type { Nature } from "#enums/nature"; import BgmBar from "./bgm-bar"; import * as Utils from "../utils"; @@ -893,31 +892,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } } - /** - * Assign a form string to a given species and form - * @param formKey the form to format - * @param species the species to format - * @param speciesId whether the name of the species should be shown at the end - * @returns the formatted string - */ - getFormString(formKey: string, species: PokemonSpecies, append: boolean = false): string { - let label: string; - const formText = capitalizeString(formKey, "-", false, false) ?? ""; - const speciesName = capitalizeString(this.getStarterSpecies(species).name, "_", true, false) ?? ""; - if (species.speciesId === Species.ARCEUS) { - label = i18next.t(`pokemonInfo:Type.${formText?.toUpperCase()}`); - return label; - } - label = formText ? i18next.t(`pokemonForm:${speciesName}${formText}`) : ""; - if (label === `${speciesName}${formText}`) { - label = i18next.t(`battlePokemonForm:${formKey}`, { pokemonName:species.name }); - } else { - // If the label is only the form, we can append the name of the pokemon - label += append ? ` ${species.name}` : ""; - } - return label; - } - processInput(button: Button): boolean { if (this.blockInput) { return false; @@ -1354,12 +1328,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { }); this.prevolutions.map(pre => { const preSpecies = allSpecies.find(species => species.speciesId === pokemonPrevolutions[this.species.speciesId]); + const preFormIndex: number = preSpecies?.forms.find(f => f.formKey === pre.preFormKey)?.formIndex ?? 0; const conditionText: string = pre.description; options.push({ label: pre.preFormKey ? - this.getFormString(pre.preFormKey, preSpecies ?? this.species, true) : + (preSpecies ?? this.species).getFormNameToDisplay(preFormIndex, pre.preFormKey, true) : (preSpecies ?? this.species).getExpandedSpeciesName(), handler: () => { const newSpecies = allSpecies.find(species => species.speciesId === pokemonPrevolutions[pre.speciesId]); @@ -1400,7 +1375,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { options.push({ label: evo.evoFormKey ? - this.getFormString(evo.evoFormKey, evoSpecies ?? this.species, true) : + (evoSpecies ?? this.species).getFormNameToDisplay(newFormIndex, evo.evoFormKey, true) : (evoSpecies ?? this.species).getExpandedSpeciesName(), style: isCaughtEvo && isFormCaughtEvo ? TextStyle.WINDOW : TextStyle.SHADOW_TEXT, handler: () => { @@ -1424,6 +1399,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { handler: () => false }); this.battleForms.map(bf => { + const matchingForm = this.species?.forms.find(form => form.formKey === bf.formKey); + const newFormIndex = matchingForm ? matchingForm.formIndex : 0; let conditionText:string = ""; if (bf.trigger) { @@ -1431,12 +1408,10 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } else { conditionText = ""; } - let label: string = this.getFormString(bf.formKey, this.species); + let label: string = this.species.getFormNameToDisplay(newFormIndex, bf.formKey); if (label === "") { label = this.species.name; } - const matchingForm = this.species?.forms.find(form => form.formKey === bf.formKey); - const newFormIndex = matchingForm ? matchingForm.formIndex : 0; const isFormCaught = this.isFormCaught(this.species, newFormIndex); if (conditionText) { @@ -2254,7 +2229,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { if (caughtAttr || forSeen) { const speciesForm = getPokemonSpeciesForm(species.speciesId, formIndex!); // TODO: is the bang correct? this.setTypeIcons(speciesForm.type1, speciesForm.type2); - this.pokemonFormText.setText(this.getFormString((speciesForm as PokemonForm).formKey, species)); + this.pokemonFormText.setText(species.getFormNameToDisplay(formIndex)); } else { this.setTypeIcons(null, null); diff --git a/src/ui/pokemon-hatch-info-container.ts b/src/ui/pokemon-hatch-info-container.ts index e4b431b4d55..a9b8e260b34 100644 --- a/src/ui/pokemon-hatch-info-container.ts +++ b/src/ui/pokemon-hatch-info-container.ts @@ -160,7 +160,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonCandyCountText.setVisible(true); this.pokemonNumberText.setText(Utils.padInt(species.speciesId, 4)); - this.pokemonNameText.setText(species.getExpandedSpeciesName()); + this.pokemonNameText.setText(species.name); const hasEggMoves = species && speciesEggMoves.hasOwnProperty(species.speciesId); diff --git a/src/ui/pokemon-info-container.ts b/src/ui/pokemon-info-container.ts index 554cea39731..eda5ac3f580 100644 --- a/src/ui/pokemon-info-container.ts +++ b/src/ui/pokemon-info-container.ts @@ -13,7 +13,6 @@ import ConfirmUiHandler from "./confirm-ui-handler"; import { StatsContainer } from "./stats-container"; import { TextStyle, addBBCodeTextObject, addTextObject, getTextColor } from "./text"; import { addWindow } from "./ui-theme"; -import { Species } from "#enums/species"; interface LanguageSetting { infoContainerTextSize: string; @@ -218,23 +217,7 @@ export default class PokemonInfoContainer extends Phaser.GameObjects.Container { this.pokemonGenderText.setVisible(false); } - const formKey = (pokemon.species?.forms?.[pokemon.formIndex!]?.formKey); - const formText = Utils.capitalizeString(formKey, "-", false, false) || ""; - const speciesName = Utils.capitalizeString(Species[pokemon.species.speciesId], "_", true, false); - - let formName = ""; - if (pokemon.species.speciesId === Species.ARCEUS) { - formName = i18next.t(`pokemonInfo:Type.${formText?.toUpperCase()}`); - } else { - const i18key = `pokemonForm:${speciesName}${formText}`; - if (i18next.exists(i18key)) { - formName = i18next.t(i18key); - } else { - const rootSpeciesName = Utils.capitalizeString(Species[pokemon.species.getRootSpeciesId()], "_", true, false); - const i18RootKey = `pokemonForm:${rootSpeciesName}${formText}`; - formName = i18next.exists(i18RootKey) ? i18next.t(i18RootKey) : formText; - } - } + const formName = pokemon.species.getFormNameToDisplay(pokemon.formIndex); if (formName) { this.pokemonFormLabelText.setVisible(true); diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 20ca2cc88da..4217d7e5205 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -53,7 +53,7 @@ import { EncounterPhase } from "#app/phases/encounter-phase"; import { TitlePhase } from "#app/phases/title-phase"; import { Abilities } from "#enums/abilities"; import { getPassiveCandyCount, getValueReductionCandyCounts, getSameSpeciesEggCandyCounts } from "#app/data/balance/starters"; -import { BooleanHolder, capitalizeString, fixedInt, getLocalizedSpriteKey, isNullOrUndefined, NumberHolder, padInt, randIntRange, rgbHexToRgba, toReadableString } from "#app/utils"; +import { BooleanHolder, fixedInt, getLocalizedSpriteKey, isNullOrUndefined, NumberHolder, padInt, randIntRange, rgbHexToRgba, toReadableString } from "#app/utils"; import type { Nature } from "#enums/nature"; import { PLAYER_PARTY_MAX_SIZE } from "#app/constants"; @@ -3408,15 +3408,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { }) as StarterMoveset; const speciesForm = getPokemonSpeciesForm(species.speciesId, formIndex!); // TODO: is the bang correct? - const formText = capitalizeString(species?.forms[formIndex!]?.formKey, "-", false, false); // TODO: is the bang correct? - - const speciesName = capitalizeString(Species[species.speciesId], "_", true, false); - - if (species.speciesId === Species.ARCEUS) { - this.pokemonFormText.setText(i18next.t(`pokemonInfo:Type.${formText?.toUpperCase()}`)); - } else { - this.pokemonFormText.setText(formText ? i18next.t(`pokemonForm:${speciesName}${formText}`) : ""); - } + const formText = species.getFormNameToDisplay(formIndex); + this.pokemonFormText.setText(formText); this.setTypeIcons(speciesForm.type1, speciesForm.type2); } else {