Add example pack generator

This commit is contained in:
Hamcha 2019-05-31 15:35:49 +02:00
parent b7e6f6cf01
commit 5930d63672
Signed by: hamcha
GPG key ID: A40413D21021EAEE

View file

@ -0,0 +1,42 @@
package main // import "git.fromouter.space/mcg/draft/example/gen-packs/mlp"
import (
"flag"
"fmt"
"os"
"strings"
"git.fromouter.space/mcg/draft"
"git.fromouter.space/mcg/draft/mlp"
)
func main() {
setname := flag.String("set", "PR", "Set to make a pack for (PR/CN/CG..)")
count := flag.Int("packs", 1, "How many packs to generate")
flag.Parse()
set, err := mlp.LoadSetHTTP(mlp.SetID(strings.ToUpper(*setname)))
checkErr(err, "Could not load set")
for i := 0; i < *count; i++ {
if *count > 1 {
fmt.Printf("Pack %d: ", i+1)
}
pack := draft.MakePack(set)
fmt.Printf("%s\n URL: %s\n", pack, ponyheadURL(pack))
}
}
func checkErr(err error, fmtstr string, fmtargs ...interface{}) {
if err != nil {
fmt.Fprintf(os.Stderr, "[FATAL ERROR] "+fmtstr+":\n "+err.Error(), fmtargs...)
os.Exit(1)
}
}
func ponyheadURL(pack draft.Pack) string {
str := "http://ponyhead.com/deckbuilder?v1code="
for _, card := range pack {
str += card.ID + "x1-"
}
return strings.TrimRight(str, "-")
}