refactor: improve typing (#2501)

This commit is contained in:
wnhlee 2024-08-14 05:49:06 +09:00 committed by GitHub
parent 0d3fcd82bb
commit 452fbbb345
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 14 deletions

View File

@ -54,6 +54,13 @@ export enum EvolutionItem {
SYRUPY_APPLE
}
/**
* Pokemon Evolution tuple type consisting of:
* @property 0 {@linkcode Species} The species of the Pokemon.
* @property 1 {@linkcode integer} The level at which the Pokemon evolves.
*/
export type EvolutionLevel = [species: Species, level: integer];
export type EvolutionConditionPredicate = (p: Pokemon) => boolean;
export type EvolutionConditionEnforceFunc = (p: Pokemon) => void;

View File

@ -3,7 +3,7 @@ import BattleScene, { AnySound } from "../battle-scene";
import { Variant, variantColorCache } from "./variant";
import { variantData } from "./variant";
import { GrowthRate } from "./exp";
import { SpeciesWildEvolutionDelay, pokemonEvolutions, pokemonPrevolutions } from "./pokemon-evolutions";
import { EvolutionLevel,SpeciesWildEvolutionDelay, pokemonEvolutions, pokemonPrevolutions } from "./pokemon-evolutions";
import { Type } from "./type";
import { LevelMoves, pokemonFormLevelMoves, pokemonFormLevelMoves as pokemonSpeciesFormLevelMoves, pokemonSpeciesLevelMoves } from "./pokemon-level-moves";
import { uncatchableSpecies } from "./biomes";
@ -761,8 +761,8 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
return this.speciesId;
}
getEvolutionLevels(): [Species, integer][] {
const evolutionLevels: [Species, integer][] = [];
getEvolutionLevels(): EvolutionLevel[] {
const evolutionLevels: EvolutionLevel[] = [];
//console.log(Species[this.speciesId], pokemonEvolutions[this.speciesId])
@ -782,8 +782,8 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
return evolutionLevels;
}
getPrevolutionLevels(): [Species, integer][] {
const prevolutionLevels: [Species, integer][] = [];
getPrevolutionLevels(): EvolutionLevel[] {
const prevolutionLevels: EvolutionLevel[] = [];
const allEvolvingPokemon = Object.keys(pokemonEvolutions);
for (const p of allEvolvingPokemon) {
@ -804,8 +804,8 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
}
// This could definitely be written better and more accurate to the getSpeciesForLevel logic, but it is only for generating movesets for evolved Pokemon
getSimulatedEvolutionChain(currentLevel: integer, forTrainer: boolean = false, isBoss: boolean = false, player: boolean = false): [Species, integer][] {
const ret: [Species, integer][] = [];
getSimulatedEvolutionChain(currentLevel: integer, forTrainer: boolean = false, isBoss: boolean = false, player: boolean = false): EvolutionLevel[] {
const ret: EvolutionLevel[] = [];
if (pokemonPrevolutions.hasOwnProperty(this.speciesId)) {
const prevolutionLevels = this.getPrevolutionLevels().reverse();
const levelDiff = player ? 0 : forTrainer || isBoss ? forTrainer && isBoss ? 2.5 : 5 : 10;

View File

@ -1386,7 +1386,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
const evolutionChain = this.species.getSimulatedEvolutionChain(this.level, this.hasTrainer(), this.isBoss(), this.isPlayer());
for (let e = 0; e < evolutionChain.length; e++) {
// TODO: Might need to pass specific form index in simulated evolution chain
const speciesLevelMoves = getPokemonSpeciesForm(evolutionChain[e][0] as Species, this.formIndex).getLevelMoves();
const speciesLevelMoves = getPokemonSpeciesForm(evolutionChain[e][0], this.formIndex).getLevelMoves();
if (includeRelearnerMoves) {
levelMoves.push(...speciesLevelMoves);
} else {
@ -1401,7 +1401,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
const fusionEvolutionChain = this.fusionSpecies.getSimulatedEvolutionChain(this.level, this.hasTrainer(), this.isBoss(), this.isPlayer());
for (let e = 0; e < fusionEvolutionChain.length; e++) {
// TODO: Might need to pass specific form index in simulated evolution chain
const speciesLevelMoves = getPokemonSpeciesForm(fusionEvolutionChain[e][0] as Species, this.fusionFormIndex).getLevelMoves();
const speciesLevelMoves = getPokemonSpeciesForm(fusionEvolutionChain[e][0], this.fusionFormIndex).getLevelMoves();
if (includeRelearnerMoves) {
levelMoves.push(...speciesLevelMoves.filter(lm => (includeEvolutionMoves && lm[0] === 0) || lm[0] !== 0));
} else {

View File

@ -832,7 +832,7 @@ export class EncounterPhase extends BattlePhase {
this.scene.unshiftPhase(new GameOverPhase(this.scene));
}
const loadEnemyAssets: Promise<any>[] = [];
const loadEnemyAssets: Promise<void>[] = [];
const battle = this.scene.currentBattle;

View File

@ -17,7 +17,7 @@ import PokemonSpecies, { allSpecies, getPokemonSpecies, getPokemonSpeciesForm, g
import { Type } from "../data/type";
import { GameModes } from "../game-mode";
import { SelectChallengePhase, TitlePhase } from "../phases";
import { AbilityAttr, DexAttr, DexAttrProps, DexEntry, StarterFormMoveData, StarterMoveset, StarterAttributes, StarterPreferences, StarterPrefs } from "../system/game-data";
import { AbilityAttr, DexAttr, DexAttrProps, DexEntry, StarterMoveset, StarterAttributes, StarterPreferences, StarterPrefs } from "../system/game-data";
import { Tutorial, handleTutorial } from "../tutorial";
import * as Utils from "../utils";
import { OptionSelectItem } from "./abstact-option-select-ui-handler";
@ -3026,8 +3026,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
const speciesMoveData = this.scene.gameData.starterData[species.speciesId].moveset;
const moveData: StarterMoveset | null = speciesMoveData
? Array.isArray(speciesMoveData)
? speciesMoveData as StarterMoveset
: (speciesMoveData as StarterFormMoveData)[formIndex!] // TODO: is this bang correct?
? speciesMoveData
: speciesMoveData[formIndex!] // TODO: is this bang correct?
: null;
const availableStarterMoves = this.speciesStarterMoves.concat(speciesEggMoves.hasOwnProperty(species.speciesId) ? speciesEggMoves[species.speciesId].filter((_, em: integer) => this.scene.gameData.starterData[species.speciesId].eggMoves & (1 << em)) : []);
this.starterMoveset = (moveData || (this.speciesStarterMoves.slice(0, 4) as StarterMoveset)).filter(m => availableStarterMoves.find(sm => sm === m)) as StarterMoveset;
@ -3464,7 +3464,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
}
}
checkIconId(icon: Phaser.GameObjects.Sprite, species: PokemonSpecies, female, formIndex, shiny, variant) {
checkIconId(icon: Phaser.GameObjects.Sprite, species: PokemonSpecies, female: boolean, formIndex: number, shiny: boolean, variant: number) {
if (icon.frame.name !== species.getIconId(female, formIndex, shiny, variant)) {
console.log(`${species.name}'s variant icon does not exist. Replacing with default.`);
icon.setTexture(species.getIconAtlasKey(formIndex, false, variant));