draft/example/gen-packs-mlp/main.go

42 lines
1,013 B
Go

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, "-")
}