From 54614bfc4d9871caf76e60e13ab0f2ee15883657 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sat, 17 Feb 2018 19:54:45 +0400 Subject: [PATCH] Pokedex sorting by letter, for moving zero grade to end of the list --- lib/datacache/pokememes.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/datacache/pokememes.go b/lib/datacache/pokememes.go index 71d4902..06fb4dc 100644 --- a/lib/datacache/pokememes.go +++ b/lib/datacache/pokememes.go @@ -228,8 +228,14 @@ func (dc *DataCache) GetAllPokememes() map[int]*dbmapping.PokememeFull { var keys []string keysToIDs := make(map[string]int) for i := range dc.fullPokememes { - keys = append(keys, strconv.Itoa(dc.fullPokememes[i].Pokememe.Grade)+"_"+strconv.Itoa(dc.fullPokememes[i].Pokememe.Attack+100000000000000)+"_"+dc.fullPokememes[i].Pokememe.Name) - keysToIDs[strconv.Itoa(dc.fullPokememes[i].Pokememe.Grade)+"_"+strconv.Itoa(dc.fullPokememes[i].Pokememe.Attack+100000000000000)+"_"+dc.fullPokememes[i].Pokememe.Name] = i + gradeKey := "" + if dc.fullPokememes[i].Pokememe.Grade == 0 { + gradeKey += "Z" + } else { + gradeKey += string(rune('A' - 1 + dc.fullPokememes[i].Pokememe.Grade)) + } + keys = append(keys, gradeKey+"_"+strconv.Itoa(dc.fullPokememes[i].Pokememe.Attack+100000000000000)+"_"+dc.fullPokememes[i].Pokememe.Name) + keysToIDs[gradeKey+"_"+strconv.Itoa(dc.fullPokememes[i].Pokememe.Attack+100000000000000)+"_"+dc.fullPokememes[i].Pokememe.Name] = i } sort.Strings(keys)