diff --git a/src/bin/pokedex/pokedex.go b/src/bin/pokedex/pokedex.go index c43d8bea..3cae0659 100644 --- a/src/bin/pokedex/pokedex.go +++ b/src/bin/pokedex/pokedex.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + "sort" "strings" "github.com/tmck-code/pokesay/src/bin" @@ -98,6 +99,9 @@ func main() { fmt.Println("- Found", len(cowfileFpaths), "cowfiles") // Read pokemon names pokemonNames := pokedex.ReadNames(args.FromMetadataFname) + nameTokens := pokedex.GatherMapKeys(pokemonNames) + sort.Strings(nameTokens) + fmt.Println("- Read", len(pokemonNames), "pokemon names from", args.FromMetadataFname) fmt.Println("- Writing entries to file") @@ -117,8 +121,9 @@ func main() { uniqueNames := make(map[string][]int) i := 0 pbar = bin.NewProgressBar(len(pokemonNames)) - for key, name := range pokemonNames { - metadata := pokedex.CreateNameMetadata(i, key, name, args.FromDir, cowfileFpaths) + for i, key := range nameTokens { + name := pokemonNames[key] + metadata := pokedex.CreateNameMetadata(fmt.Sprintf("%04d", i), key, name, args.FromDir, cowfileFpaths) pokedex.WriteStructToFile(metadata, pokedex.MetadataFpath(paths.MetadataDirPath, i)) pokemonMetadata = append(pokemonMetadata, *metadata) uniqueNames[name.Slug] = append(uniqueNames[name.Slug], i) diff --git a/src/pokedex/metadata.go b/src/pokedex/metadata.go index 8b64ebff..7a545ffa 100644 --- a/src/pokedex/metadata.go +++ b/src/pokedex/metadata.go @@ -13,13 +13,14 @@ type PokemonEntryMapping struct { } type PokemonMetadata struct { + Idx string Name string JapaneseName string JapanesePhonetic string Entries []PokemonEntryMapping } -func NewMetadata(name string, japaneseName string, japanesePhonetic string, entryMap map[int][][]string) *PokemonMetadata { +func NewMetadata(idx string, name string, japaneseName string, japanesePhonetic string, entryMap map[int][][]string) *PokemonMetadata { entries := make([]PokemonEntryMapping, 0) @@ -30,6 +31,7 @@ func NewMetadata(name string, japaneseName string, japanesePhonetic string, entr } return &PokemonMetadata{ + Idx: idx, Name: name, JapaneseName: japaneseName, JapanesePhonetic: japanesePhonetic, diff --git a/src/pokedex/pokedex.go b/src/pokedex/pokedex.go index ea7a5060..6c0c05e0 100644 --- a/src/pokedex/pokedex.go +++ b/src/pokedex/pokedex.go @@ -130,7 +130,7 @@ func Decompress(data []byte) []byte { return resB.Bytes() } -func CreateNameMetadata(idx int, key string, name PokemonName, rootDir string, fpaths []string) *PokemonMetadata { +func CreateNameMetadata(idx string, key string, name PokemonName, rootDir string, fpaths []string) *PokemonMetadata { entryCategories := make(map[int][][]string, 0) for i, fpath := range fpaths { @@ -143,6 +143,7 @@ func CreateNameMetadata(idx int, key string, name PokemonName, rootDir string, f } } return NewMetadata( + idx, name.English, name.Japanese, name.JapanesePhonetic,