diff --git a/package.json b/package.json index 0cf1418..9203c82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pogo-data-generator", - "version": "1.16.8", + "version": "1.16.9", "description": "Pokemon GO project data generator", "author": "TurtIeSocks", "license": "Apache-2.0", diff --git a/src/classes/PokeApi.ts b/src/classes/PokeApi.ts index 6689f0c..3b73833 100644 --- a/src/classes/PokeApi.ts +++ b/src/classes/PokeApi.ts @@ -7,7 +7,11 @@ import { TempEvolutions, } from '../typings/dataTypes' import { TypeProto, PokemonIdProto, MoveProto } from '../typings/protos' -import { PokeApiStats, PokeApiTypes } from '../typings/pokeapi' +import { + BasePokeApiStruct, + PokeApiStats, + PokeApiTypes, +} from '../typings/pokeapi' import { SpeciesApi } from '../typings/general' export default class PokeApi extends Masterfile { @@ -541,4 +545,29 @@ export default class PokeApi extends Masterfile { }), ) } + + async getGenerations() { + const generations: { results: BasePokeApiStruct[] } = await this.fetch( + 'https://pokeapi.co/api/v2/generation', + ) + const results = await Promise.all( + generations.results.map(async (gen, index) => { + const { + main_region, + pokemon_species, + }: { + main_region: BasePokeApiStruct + pokemon_species: BasePokeApiStruct[] + } = await this.fetch(gen.url) + const name = this.capitalize(main_region.name) + const pokemonIds = pokemon_species.map( + (pokemon) => +pokemon.url.split('/').at(-2), + ) + const min = Math.min(...pokemonIds) + const max = Math.max(...pokemonIds) + return { id: index + 1, name, range: [min, max] } + }), + ) + return Object.fromEntries(results.map(({ id, ...rest}) => [id, rest])) + } } diff --git a/src/index.ts b/src/index.ts index 2f23ab8..2dfe0ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,6 +69,8 @@ export async function generate({ ) const AllPokeApi = new PokeApi() await AllPokeApi.setMaxPokemonId() + const generations = await AllPokeApi.getGenerations() + AllPokemon.generations = generations const AllMisc = new Misc() const apk = new ApkReader() diff --git a/src/typings/pokeapi.ts b/src/typings/pokeapi.ts index 4c4eb17..e689174 100644 --- a/src/typings/pokeapi.ts +++ b/src/typings/pokeapi.ts @@ -2,24 +2,15 @@ import { AllPokemon, AllTypes } from './dataTypes' export interface PokeApiStats { abilities: { - ability: { - name: string - url: string - } + ability: BasePokeApiStruct is_hidden: boolean slot: number }[] base_experience: number - forms: { - name: string - url: string - }[] + forms: BasePokeApiStruct[] game_indices: { game_index: number - version: { - name: string - url: string - } + version: BasePokeApiStruct }[] height: number held_items: [] @@ -27,44 +18,26 @@ export interface PokeApiStats { is_default: boolean location_area_encounters: string moves: { - move: { - name: string - url: string - } + move: BasePokeApiStruct version_group_details: { level_learned_at: number - move_learn_method: { - name: string - url: string - } - version_group: { - name: string - url: string - } + move_learn_method: BasePokeApiStruct + version_group: BasePokeApiStruct }[] }[] name: string order: number past_types: [] - species: { - name: string - url: string - } + species: BasePokeApiStruct sprites: Sprites stats: { base_stat: number effort: number - stat: { - name: string - url: string - } + stat: BasePokeApiStruct }[] types: { slot: number - type: { - name: string - url: string - } + type: BasePokeApiStruct }[] weight: number } @@ -101,19 +74,19 @@ type Sprite = { front_shiny_female?: string } -type PokeApiType = { +export type BasePokeApiStruct = { name: string url: string } export interface PokeApiTypes { damage_relations: { - double_damage_from: PokeApiType[] - double_damage_to: PokeApiType[] - half_damage_from: PokeApiType[] - half_damage_to: PokeApiType[] - no_damage_from: PokeApiType[] - no_damage_to: PokeApiType[] + double_damage_from: BasePokeApiStruct[] + double_damage_to: BasePokeApiStruct[] + half_damage_from: BasePokeApiStruct[] + half_damage_to: BasePokeApiStruct[] + no_damage_from: BasePokeApiStruct[] + no_damage_to: BasePokeApiStruct[] } }