From 9e94599971e8e8f0cff9ea5b2c53a6aa3e274d3e Mon Sep 17 00:00:00 2001 From: Vomitblood Date: Wed, 17 Apr 2024 00:01:49 +0800 Subject: [PATCH] sort forms --- src/fetch.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fetch.rs b/src/fetch.rs index 2574f67..c4ae267 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -234,12 +234,12 @@ fn read_pokemon_file( } fn transform_pokemon_data( - pokemons: &std::collections::HashMap, + pokemon_collection: &std::collections::HashMap, ) -> Vec { - let mut processed_pokemons: Vec = pokemons + let mut processed_pokemons: Vec = pokemon_collection .iter() .map(|(_key, p)| { - let forms = p + let mut forms = p .gen_8 .forms .keys() @@ -249,6 +249,14 @@ fn transform_pokemon_data( }) .collect::>(); + // 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 { // remove leading zeros from the pokedex number pokedex: p.idx.trim_start_matches('0').to_string(),