-
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 #29 from tmck-code/glow-up
Glow up
- Loading branch information
Showing
14 changed files
with
273 additions
and
154 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
set -euxo pipefail | ||
|
||
OUTPUT_DIR="build/bin" | ||
mkdir -p "$OUTPUT_DIR" | ||
|
||
function build() { | ||
echo "building $1 / $2" | ||
GOOS=$1 GOARCH=$2 go build -o bin/pokesay-${1}-${2}${3:-} pokesay.go | ||
GOOS=$1 GOARCH=$2 go build -o "${OUTPUT_DIR}/pokesay-${1}-${2}${3:-}" pokesay.go | ||
} | ||
|
||
mkdir bin/ | ||
|
||
build darwin amd64 & | ||
build darwin arm64 & | ||
build linux amd64 & | ||
build windows amd64 .exe & | ||
build android arm64 & | ||
wait | ||
wait |
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,15 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
tar xzf build/cows.tar.gz | ||
go run ./src/bin/pokedex/pokedex.go \ | ||
-from ./cows/ \ | ||
-to ./build/assets/ \ | ||
-toCategoryFpath pokedex.gob \ | ||
-toDataSubDir cows/ \ | ||
-toMetadataSubDir metadata/ \ | ||
-toTotalFname total.txt | ||
|
||
rm -rf cows | ||
ls -alh build/assets |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/tmck-code/pokesay-go/src/bin" | ||
"github.com/tmck-code/pokesay-go/src/pokedex" | ||
) | ||
|
||
func check(e error) { | ||
if e != nil { | ||
log.Fatal(e) | ||
} | ||
} | ||
|
||
var ( | ||
DEBUG bool = false | ||
) | ||
|
||
type CowBuildArgs struct { | ||
FromDir string | ||
ToDir string | ||
SkipDirs []string | ||
Padding int | ||
Debug bool | ||
} | ||
|
||
func parseArgs() CowBuildArgs { | ||
fromDir := flag.String("from", ".", "from dir") | ||
toDir := flag.String("to", ".", "to dir") | ||
skipDirs := flag.String("skip", "'[\"resources\"]'", "JSON array of dir patterns to skip converting") | ||
padding := flag.Int("padding", 2, "the number of spaces to pad from the left") | ||
debug := flag.Bool("debug", DEBUG, "show debug logs") | ||
|
||
flag.Parse() | ||
|
||
DEBUG = *debug | ||
|
||
args := CowBuildArgs{FromDir: *fromDir, ToDir: *toDir, Padding: *padding} | ||
json.Unmarshal([]byte(*skipDirs), &args.SkipDirs) | ||
|
||
if DEBUG { | ||
fmt.Println("%+v", args) | ||
} | ||
return args | ||
} | ||
|
||
func main() { | ||
args := parseArgs() | ||
|
||
fpaths := pokedex.FindFiles(args.FromDir, ".png", args.SkipDirs) | ||
|
||
// Ensure that the destination dir exists | ||
os.MkdirAll(args.ToDir, 0755) | ||
|
||
fmt.Println("Converting PNGs -> cowfiles") | ||
pbar := bin.NewProgressBar(len(fpaths)) | ||
for _, f := range fpaths { | ||
pokedex.ConvertPngToCow(args.FromDir, f, args.ToDir, args.Padding) | ||
pbar.Add(1) | ||
} | ||
fmt.Println("Finished converting", len(fpaths), "pokesprite PNGs", "-> cowfiles") | ||
} |
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,90 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path" | ||
"strconv" | ||
|
||
"github.com/tmck-code/pokesay-go/src/bin" | ||
"github.com/tmck-code/pokesay-go/src/pokedex" | ||
) | ||
|
||
func check(e error) { | ||
if e != nil { | ||
log.Fatal(e) | ||
} | ||
} | ||
|
||
type PokedexArgs struct { | ||
FromDir string | ||
ToDir string | ||
Debug bool | ||
ToCategoryFname string | ||
ToDataSubDir string | ||
ToMetadataSubDir string | ||
ToTotalFname string | ||
} | ||
|
||
func parseArgs() PokedexArgs { | ||
fromDir := flag.String("from", "/tmp/cows", "from dir") | ||
toDir := flag.String("to", "build/assets/", "to dir") | ||
|
||
toDataSubDir := flag.String("toDataSubDir", "cows/", "dir to write all binary (image) data to") | ||
toMetadataSubDir := flag.String("toMetadataSubDir", "metadata/", "dir to write all binary (metadata) data to") | ||
toCategoryFname := flag.String("toCategoryFpath", "pokedex.gob", "to fpath") | ||
toTotalFname := flag.String("toTotalFname", "total.txt", "file to write the number of available entries to") | ||
debug := flag.Bool("debug", false, "show debug logs") | ||
|
||
flag.Parse() | ||
|
||
args := PokedexArgs{ | ||
FromDir: pokedex.NormaliseRelativeDir(*fromDir), | ||
ToDir: pokedex.NormaliseRelativeDir(*toDir), | ||
ToCategoryFname: *toCategoryFname, | ||
ToDataSubDir: pokedex.NormaliseRelativeDir(*toDataSubDir), | ||
ToMetadataSubDir: pokedex.NormaliseRelativeDir(*toMetadataSubDir), | ||
ToTotalFname: *toTotalFname, | ||
Debug: *debug, | ||
} | ||
if args.Debug { | ||
fmt.Printf("%+v\n", args) | ||
} | ||
return args | ||
} | ||
|
||
func main() { | ||
args := parseArgs() | ||
|
||
totalFpath := path.Join(args.ToDir, args.ToTotalFname) | ||
categoryFpath := path.Join(args.ToDir, args.ToCategoryFname) | ||
|
||
fpaths := pokedex.FindFiles(args.FromDir, ".cow", make([]string, 0)) | ||
|
||
err := os.MkdirAll(path.Join(args.ToDir, args.ToDataSubDir), 0755) | ||
check(err) | ||
err = os.MkdirAll(path.Join(args.ToDir, args.ToMetadataSubDir), 0755) | ||
check(err) | ||
|
||
// categories is a PokemonTrie struct that will be written to a file using encoding/gob | ||
// metadata is a list of pokemon data and an index to use when writing them to a file | ||
// - this index matches a corresponding one in the categories struct | ||
// - these files are embedded into the build binary using go:embed and then loaded at runtime | ||
categories, metadata := pokedex.CreateMetadata(args.FromDir, fpaths, args.Debug) | ||
|
||
pokedex.WriteStructToFile(categories, categoryFpath) | ||
|
||
fmt.Println("\nConverting cowfiles -> category & metadata GOB") | ||
pbar := bin.NewProgressBar(len(fpaths)) | ||
for _, m := range metadata { | ||
pokedex.WriteBytesToFile(m.Data, pokedex.EntryFpath(path.Join(args.ToDir, args.ToDataSubDir), m.Index), true) | ||
pokedex.WriteStructToFile(m.Metadata, pokedex.MetadataFpath(path.Join(args.ToDir, args.ToMetadataSubDir), m.Index)) | ||
pbar.Add(1) | ||
} | ||
pokedex.WriteBytesToFile([]byte(strconv.Itoa(len(metadata))), totalFpath, false) | ||
|
||
fmt.Println("Finished converting", len(fpaths), "pokesprite -> cowfiles") | ||
fmt.Println("Wrote categories to", path.Join(args.ToDir, args.ToCategoryFname)) | ||
} |
Oops, something went wrong.