sort forms

This commit is contained in:
Vomitblood 2024-04-17 00:01:49 +08:00
parent 6411936478
commit 9e94599971

View file

@ -234,12 +234,12 @@ fn read_pokemon_file(
} }
fn transform_pokemon_data( fn transform_pokemon_data(
pokemons: &std::collections::HashMap<String, Pokemon>, pokemon_collection: &std::collections::HashMap<String, Pokemon>,
) -> Vec<ProcessedPokemon> { ) -> Vec<ProcessedPokemon> {
let mut processed_pokemons: Vec<ProcessedPokemon> = pokemons let mut processed_pokemons: Vec<ProcessedPokemon> = pokemon_collection
.iter() .iter()
.map(|(_key, p)| { .map(|(_key, p)| {
let forms = p let mut forms = p
.gen_8 .gen_8
.forms .forms
.keys() .keys()
@ -249,6 +249,14 @@ fn transform_pokemon_data(
}) })
.collect::<Vec<String>>(); .collect::<Vec<String>>();
// ensure `regular` is first then sort remaining forms alphabetically
// ocd af
forms.sort();
if let Some(pos) = forms.iter().position(|x| x == "regular") {
forms.remove(pos);
forms.insert(0, "regular".to_string());
}
ProcessedPokemon { ProcessedPokemon {
// remove leading zeros from the pokedex number // remove leading zeros from the pokedex number
pokedex: p.idx.trim_start_matches('0').to_string(), pokedex: p.idx.trim_start_matches('0').to_string(),