-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from tmck-code/embedded-name-metadata
Embedded name metadata
- Loading branch information
Showing
13 changed files
with
371 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/tmck-code/pokesay/src/pokedex" | ||
"github.com/tmck-code/pokesay/src/timer" | ||
) | ||
|
||
var ( | ||
//go:embed assets/metadata/*metadata | ||
GOBCowNames embed.FS | ||
//go:embed assets/cows/*cow | ||
GOBCowFiles embed.FS | ||
//go:embed assets/pokedex.gob | ||
GOBCategory []byte | ||
|
||
MetadataRoot string = "assets/metadata" | ||
CowfileRoot string = "assets/cows" | ||
) | ||
|
||
type Args struct { | ||
Index int | ||
} | ||
|
||
func parseFlags() Args { | ||
index := flag.Int("index", 80, "the metadata file index") | ||
flag.Parse() | ||
|
||
return Args{ | ||
Index: *index, | ||
} | ||
} | ||
func MetadataFpath(idx int) string { | ||
return pokedex.MetadataFpath(MetadataRoot, idx) | ||
} | ||
|
||
func EntryFpath(idx int) string { | ||
return pokedex.EntryFpath(CowfileRoot, idx) | ||
} | ||
|
||
func main() { | ||
args := parseFlags() | ||
t := timer.NewTimer("read_assets", true) | ||
pokedex.NewTrieFromBytes(GOBCategory) | ||
t.Mark("trie") | ||
|
||
metadata := pokedex.ReadMetadataFromEmbedded(GOBCowNames, MetadataFpath(args.Index)) | ||
t.Mark("metadata") | ||
|
||
fmt.Println(pokedex.StructToJSON(metadata, 2)) | ||
t.Mark("toJSON") | ||
|
||
for i, entry := range metadata.Entries { | ||
data := string(pokedex.ReadPokemonCow(GOBCowFiles, EntryFpath(entry.EntryIndex))) | ||
t.Mark(fmt.Sprintf("read-cow-%d", i)) | ||
|
||
fmt.Printf("%s\n%s\n", entry.Categories, data) | ||
t.Mark(fmt.Sprintf("print-cow-%d", i)) | ||
} | ||
t.Stop() | ||
t.PrintJson() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.