mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-07 07:59:26 +02:00
[Dev] Move various functions out of pokemon-species.ts
(#6155)
`initSpecies` moved to its own file, other functions moved to `pokemon-utils.ts`
This commit is contained in:
parent
491df80b66
commit
e8ab79ebed
1784
src/data/balance/pokemon-species.ts
Normal file
1784
src/data/balance/pokemon-species.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,6 @@ import { pokemonEvolutions } from "#balance/pokemon-evolutions";
|
||||
import { speciesStarterCosts } from "#balance/starters";
|
||||
import { pokemonFormChanges } from "#data/pokemon-forms";
|
||||
import type { PokemonSpecies } from "#data/pokemon-species";
|
||||
import { getPokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { BattleType } from "#enums/battle-type";
|
||||
import { ChallengeType } from "#enums/challenge-type";
|
||||
import { Challenges } from "#enums/challenges";
|
||||
@ -26,7 +25,7 @@ import { PokemonMove } from "#moves/pokemon-move";
|
||||
import type { DexAttrProps, GameData } from "#system/game-data";
|
||||
import { BooleanHolder, isBetween, type NumberHolder, randSeedItem } from "#utils/common";
|
||||
import { deepCopy } from "#utils/data";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
import { toCamelCase, toSnakeCase } from "#utils/strings";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { pokerogueApi } from "#api/pokerogue-api";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { speciesStarterCosts } from "#balance/starters";
|
||||
import type { PokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { getPokemonSpeciesForm, PokemonSpecies } from "#data/pokemon-species";
|
||||
import { PokemonSpecies } from "#data/pokemon-species";
|
||||
import { BiomeId } from "#enums/biome-id";
|
||||
import { PartyMemberStrength } from "#enums/party-member-strength";
|
||||
import type { SpeciesId } from "#enums/species-id";
|
||||
@ -10,7 +10,7 @@ import { PlayerPokemon } from "#field/pokemon";
|
||||
import type { Starter } from "#ui/starter-select-ui-handler";
|
||||
import { randSeedGauss, randSeedInt, randSeedItem } from "#utils/common";
|
||||
import { getEnumValues } from "#utils/enums";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
|
||||
export interface DailyRunConfig {
|
||||
seed: number;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@ import { loadBattlerTag, SerializableBattlerTag } from "#data/battler-tags";
|
||||
import { allSpecies } from "#data/data-lists";
|
||||
import type { Gender } from "#data/gender";
|
||||
import { PokemonMove } from "#data/moves/pokemon-move";
|
||||
import { getPokemonSpeciesForm, type PokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import type { PokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import type { TypeDamageMultiplier } from "#data/type";
|
||||
import type { AbilityId } from "#enums/ability-id";
|
||||
import type { BerryType } from "#enums/berry-type";
|
||||
@ -16,6 +16,7 @@ import type { IllusionData } from "#types/illusion-data";
|
||||
import type { TurnMove } from "#types/turn-move";
|
||||
import type { CoerceNullPropertiesToUndefined } from "#types/type-helpers";
|
||||
import { isNullOrUndefined } from "#utils/common";
|
||||
import { getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
|
||||
/**
|
||||
* The type that {@linkcode PokemonSpeciesForm} is converted to when an object containing it serializes it.
|
||||
|
@ -60,7 +60,7 @@ import {
|
||||
} from "#data/pokemon-data";
|
||||
import type { SpeciesFormChange } from "#data/pokemon-forms";
|
||||
import type { PokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { getFusedSpeciesName, getPokemonSpeciesForm, PokemonSpecies } from "#data/pokemon-species";
|
||||
import { PokemonSpecies } from "#data/pokemon-species";
|
||||
import { getRandomStatus, getStatusEffectOverlapText, Status } from "#data/status-effect";
|
||||
import { getTerrainBlockMessage, TerrainType } from "#data/terrain";
|
||||
import type { TypeDamageMultiplier } from "#data/type";
|
||||
@ -168,7 +168,7 @@ import {
|
||||
toDmgValue,
|
||||
} from "#utils/common";
|
||||
import { getEnumValues } from "#utils/enums";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getFusedSpeciesName, getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
import { argbFromRgba, QuantizerCelebi, rgbaFromArgb } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
import Phaser from "phaser";
|
||||
|
@ -2,10 +2,10 @@ import { initAbilities } from "#abilities/ability";
|
||||
import { initBiomes } from "#balance/biomes";
|
||||
import { initEggMoves } from "#balance/egg-moves";
|
||||
import { initPokemonPrevolutions, initPokemonStarters } from "#balance/pokemon-evolutions";
|
||||
import { initSpecies } from "#balance/pokemon-species";
|
||||
import { initChallenges } from "#data/challenge";
|
||||
import { initTrainerTypeDialogue } from "#data/dialogue";
|
||||
import { initPokemonForms } from "#data/pokemon-forms";
|
||||
import { initSpecies } from "#data/pokemon-species";
|
||||
import { initModifierPools } from "#modifiers/init-modifier-pools";
|
||||
import { initModifierTypes } from "#modifiers/modifier-type";
|
||||
import { initMoves } from "#moves/move";
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import type { Gender } from "#data/gender";
|
||||
import { CustomPokemonData, PokemonBattleData, PokemonSummonData } from "#data/pokemon-data";
|
||||
import { getPokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { Status } from "#data/status-effect";
|
||||
import { BattleType } from "#enums/battle-type";
|
||||
import type { BiomeId } from "#enums/biome-id";
|
||||
@ -14,7 +13,7 @@ import { TrainerSlot } from "#enums/trainer-slot";
|
||||
import { EnemyPokemon, Pokemon } from "#field/pokemon";
|
||||
import { PokemonMove } from "#moves/pokemon-move";
|
||||
import type { Variant } from "#sprites/variant";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
|
||||
export class PokemonData {
|
||||
public id: number;
|
||||
|
@ -1,11 +1,10 @@
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { getPokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { DexAttr } from "#enums/dex-attr";
|
||||
import type { SessionSaveData, SystemSaveData } from "#system/game-data";
|
||||
import type { SessionSaveMigrator } from "#types/session-save-migrator";
|
||||
import type { SystemSaveMigrator } from "#types/system-save-migrator";
|
||||
import { isNullOrUndefined } from "#utils/common";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
|
||||
/**
|
||||
* If a starter is caught, but the only forms registered as caught are not starterSelectable,
|
||||
|
@ -25,7 +25,7 @@ import { getNatureName } from "#data/nature";
|
||||
import type { SpeciesFormChange } from "#data/pokemon-forms";
|
||||
import { pokemonFormChanges } from "#data/pokemon-forms";
|
||||
import type { PokemonSpecies } from "#data/pokemon-species";
|
||||
import { getPokemonSpeciesForm, normalForm } from "#data/pokemon-species";
|
||||
import { normalForm } from "#data/pokemon-species";
|
||||
import { AbilityAttr } from "#enums/ability-attr";
|
||||
import type { AbilityId } from "#enums/ability-id";
|
||||
import { BiomeId } from "#enums/biome-id";
|
||||
@ -56,7 +56,7 @@ import { addBBCodeTextObject, addTextObject, getTextColor, getTextStyleOptions }
|
||||
import { addWindow } from "#ui/ui-theme";
|
||||
import { BooleanHolder, getLocalizedSpriteKey, isNullOrUndefined, padInt, rgbHexToRgba } from "#utils/common";
|
||||
import { getEnumValues } from "#utils/enums";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
import { toTitleCase } from "#utils/strings";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
import { speciesTmMoves } from "#balance/tms";
|
||||
import { allAbilities, allMoves, allSpecies } from "#data/data-lists";
|
||||
import type { PokemonForm, PokemonSpecies } from "#data/pokemon-species";
|
||||
import { getPokemonSpeciesForm, getPokerusStarters, normalForm } from "#data/pokemon-species";
|
||||
import { normalForm } from "#data/pokemon-species";
|
||||
import { AbilityAttr } from "#enums/ability-attr";
|
||||
import { AbilityId } from "#enums/ability-id";
|
||||
import { BiomeId } from "#enums/biome-id";
|
||||
@ -46,6 +46,7 @@ import { addWindow } from "#ui/ui-theme";
|
||||
import { BooleanHolder, fixedInt, getLocalizedSpriteKey, padInt, randIntRange, rgbHexToRgba } from "#utils/common";
|
||||
import type { StarterPreferences } from "#utils/data";
|
||||
import { loadStarterPreferences } from "#utils/data";
|
||||
import { getPokemonSpeciesForm, getPokerusStarters } from "#utils/pokemon-utils";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
|
||||
|
@ -5,7 +5,6 @@ import { allMoves } from "#data/data-lists";
|
||||
import { getEggTierForSpecies } from "#data/egg";
|
||||
import type { EggHatchData } from "#data/egg-hatch-data";
|
||||
import { Gender } from "#data/gender";
|
||||
import { getPokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { PokemonType } from "#enums/pokemon-type";
|
||||
import { SpeciesId } from "#enums/species-id";
|
||||
import { TextStyle } from "#enums/text-style";
|
||||
@ -13,6 +12,7 @@ import type { PlayerPokemon } from "#field/pokemon";
|
||||
import { PokemonInfoContainer } from "#ui/pokemon-info-container";
|
||||
import { addTextObject } from "#ui/text";
|
||||
import { padInt, rgbHexToRgba } from "#utils/common";
|
||||
import { getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,6 @@ import { Gender, getGenderColor, getGenderSymbol } from "#data/gender";
|
||||
import { getNatureName } from "#data/nature";
|
||||
import { pokemonFormChanges } from "#data/pokemon-forms";
|
||||
import type { PokemonSpecies } from "#data/pokemon-species";
|
||||
import { getPokemonSpeciesForm, getPokerusStarters } from "#data/pokemon-species";
|
||||
import { AbilityAttr } from "#enums/ability-attr";
|
||||
import { AbilityId } from "#enums/ability-id";
|
||||
import { Button } from "#enums/buttons";
|
||||
@ -72,6 +71,7 @@ import {
|
||||
} from "#utils/common";
|
||||
import type { StarterPreferences } from "#utils/data";
|
||||
import { loadStarterPreferences, saveStarterPreferences } from "#utils/data";
|
||||
import { getPokemonSpeciesForm, getPokerusStarters } from "#utils/pokemon-utils";
|
||||
import { toTitleCase } from "#utils/strings";
|
||||
import { argbFromRgba } from "@material/material-color-utilities";
|
||||
import i18next from "i18next";
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { POKERUS_STARTER_COUNT, speciesStarterCosts } from "#balance/starters";
|
||||
import { allSpecies } from "#data/data-lists";
|
||||
import type { PokemonSpecies } from "#data/pokemon-species";
|
||||
import type { PokemonSpecies, PokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import type { SpeciesId } from "#enums/species-id";
|
||||
import { randSeedItem } from "./common";
|
||||
|
||||
/**
|
||||
* Gets the {@linkcode PokemonSpecies} object associated with the {@linkcode SpeciesId} enum given
|
||||
@ -19,3 +22,104 @@ export function getPokemonSpecies(species: SpeciesId | SpeciesId[]): PokemonSpec
|
||||
}
|
||||
return allSpecies[species - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the daily list of starters with Pokerus.
|
||||
* @returns A list of starters with Pokerus
|
||||
*/
|
||||
export function getPokerusStarters(): PokemonSpecies[] {
|
||||
const pokerusStarters: PokemonSpecies[] = [];
|
||||
const date = new Date();
|
||||
date.setUTCHours(0, 0, 0, 0);
|
||||
globalScene.executeWithSeedOffset(
|
||||
() => {
|
||||
while (pokerusStarters.length < POKERUS_STARTER_COUNT) {
|
||||
const randomSpeciesId = Number.parseInt(randSeedItem(Object.keys(speciesStarterCosts)), 10);
|
||||
const species = getPokemonSpecies(randomSpeciesId);
|
||||
if (!pokerusStarters.includes(species)) {
|
||||
pokerusStarters.push(species);
|
||||
}
|
||||
}
|
||||
},
|
||||
0,
|
||||
date.getTime().toString(),
|
||||
);
|
||||
return pokerusStarters;
|
||||
}
|
||||
|
||||
export function getFusedSpeciesName(speciesAName: string, speciesBName: string): string {
|
||||
const fragAPattern = /([a-z]{2}.*?[aeiou(?:y$)\-']+)(.*?)$/i;
|
||||
const fragBPattern = /([a-z]{2}.*?[aeiou(?:y$)\-'])(.*?)$/i;
|
||||
|
||||
const [speciesAPrefixMatch, speciesBPrefixMatch] = [speciesAName, speciesBName].map(n => /^(?:[^ ]+) /.exec(n));
|
||||
const [speciesAPrefix, speciesBPrefix] = [speciesAPrefixMatch, speciesBPrefixMatch].map(m => (m ? m[0] : ""));
|
||||
|
||||
if (speciesAPrefix) {
|
||||
speciesAName = speciesAName.slice(speciesAPrefix.length);
|
||||
}
|
||||
if (speciesBPrefix) {
|
||||
speciesBName = speciesBName.slice(speciesBPrefix.length);
|
||||
}
|
||||
|
||||
const [speciesASuffixMatch, speciesBSuffixMatch] = [speciesAName, speciesBName].map(n => / (?:[^ ]+)$/.exec(n));
|
||||
const [speciesASuffix, speciesBSuffix] = [speciesASuffixMatch, speciesBSuffixMatch].map(m => (m ? m[0] : ""));
|
||||
|
||||
if (speciesASuffix) {
|
||||
speciesAName = speciesAName.slice(0, -speciesASuffix.length);
|
||||
}
|
||||
if (speciesBSuffix) {
|
||||
speciesBName = speciesBName.slice(0, -speciesBSuffix.length);
|
||||
}
|
||||
|
||||
const splitNameA = speciesAName.split(/ /g);
|
||||
const splitNameB = speciesBName.split(/ /g);
|
||||
|
||||
const fragAMatch = fragAPattern.exec(speciesAName);
|
||||
const fragBMatch = fragBPattern.exec(speciesBName);
|
||||
|
||||
let fragA: string;
|
||||
let fragB: string;
|
||||
|
||||
fragA = splitNameA.length === 1 ? (fragAMatch ? fragAMatch[1] : speciesAName) : splitNameA[splitNameA.length - 1];
|
||||
|
||||
if (splitNameB.length === 1) {
|
||||
if (fragBMatch) {
|
||||
const lastCharA = fragA.slice(fragA.length - 1);
|
||||
const prevCharB = fragBMatch[1].slice(fragBMatch.length - 1);
|
||||
fragB = (/[-']/.test(prevCharB) ? prevCharB : "") + fragBMatch[2] || prevCharB;
|
||||
if (lastCharA === fragB[0]) {
|
||||
if (/[aiu]/.test(lastCharA)) {
|
||||
fragB = fragB.slice(1);
|
||||
} else {
|
||||
const newCharMatch = new RegExp(`[^${lastCharA}]`).exec(fragB);
|
||||
if (newCharMatch?.index !== undefined && newCharMatch.index > 0) {
|
||||
fragB = fragB.slice(newCharMatch.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fragB = speciesBName;
|
||||
}
|
||||
} else {
|
||||
fragB = splitNameB[splitNameB.length - 1];
|
||||
}
|
||||
|
||||
if (splitNameA.length > 1) {
|
||||
fragA = `${splitNameA.slice(0, splitNameA.length - 1).join(" ")} ${fragA}`;
|
||||
}
|
||||
|
||||
fragB = `${fragB.slice(0, 1).toLowerCase()}${fragB.slice(1)}`;
|
||||
|
||||
return `${speciesAPrefix || speciesBPrefix}${fragA}${fragB}${speciesBSuffix || speciesASuffix}`;
|
||||
}
|
||||
|
||||
export function getPokemonSpeciesForm(species: SpeciesId, formIndex: number): PokemonSpeciesForm {
|
||||
const retSpecies: PokemonSpecies =
|
||||
species >= 2000
|
||||
? allSpecies.find(s => s.speciesId === species)! // TODO: is the bang correct?
|
||||
: allSpecies[species - 1];
|
||||
if (formIndex < retSpecies.forms?.length) {
|
||||
return retSpecies.forms[formIndex];
|
||||
}
|
||||
return retSpecies;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import type { BattleScene } from "#app/battle-scene";
|
||||
import { getGameMode } from "#app/game-mode";
|
||||
import { getDailyRunStarters } from "#data/daily-run";
|
||||
import { Gender } from "#data/gender";
|
||||
import { getPokemonSpeciesForm } from "#data/pokemon-species";
|
||||
import { BattleType } from "#enums/battle-type";
|
||||
import { GameModes } from "#enums/game-modes";
|
||||
import type { MoveId } from "#enums/move-id";
|
||||
@ -11,7 +10,7 @@ import type { SpeciesId } from "#enums/species-id";
|
||||
import { PlayerPokemon } from "#field/pokemon";
|
||||
import type { StarterMoveset } from "#system/game-data";
|
||||
import type { Starter } from "#ui/starter-select-ui-handler";
|
||||
import { getPokemonSpecies } from "#utils/pokemon-utils";
|
||||
import { getPokemonSpecies, getPokemonSpeciesForm } from "#utils/pokemon-utils";
|
||||
|
||||
/** Function to convert Blob to string */
|
||||
export function blobToString(blob) {
|
||||
|
Loading…
Reference in New Issue
Block a user