Add example pack generator
This commit is contained in:
parent
b7e6f6cf01
commit
5930d63672
1 changed files with 42 additions and 0 deletions
42
example/gen-packs-mlp/main.go
Normal file
42
example/gen-packs-mlp/main.go
Normal 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, "-")
|
||||
}
|
Loading…
Reference in a new issue