forked from gamebytes/deckbrew-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtgjson.go
97 lines (82 loc) · 2.31 KB
/
mtgjson.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"crypto/md5"
"encoding/json"
"fmt"
"io"
"io/ioutil"
)
type MTGCollection map[string]MTGSet
type MTGSet struct {
Name string `json:"name"`
Code string `json:"code"`
Released string `json:"releaseDate"`
Border string `json:"border"`
Type string `json:"type"`
Cards []MTGCard `json:"cards"`
}
type MTGCard struct {
Artist string `json:"artist"`
Border string `json:"border"`
Colors []string `json:"colors"`
ConvertedCost float64 `json:"cmc"`
Flavor string `json:"flavor"`
HandModifier int `json:"hand"`
Layout string `json:"layout"`
LifeModifier int `json:"life"`
Loyalty int `json:"loyalty"`
ManaCost string `json:"manaCost"`
MultiverseId int `json:"multiverseid"`
Name string `json:"name"`
Names []string `json:"names"`
Number string `json:"number"`
Power string `json:"power"`
Rarity string `json:"rarity"`
Rulings []MTGRuling `json:"rulings"`
Subtypes []string `json:"subtypes"`
Supertypes []string `json:"supertypes"`
Text string `json:"text"`
Toughness string `json:"toughness"`
Type string `json:"type"`
Types []string `json:"types"`
Watermark string `json:"watermark"`
}
func (c MTGCard) Id() string {
h := md5.New()
io.WriteString(h, c.Name+c.ManaCost)
return fmt.Sprintf("%x", h.Sum(nil))
}
type MTGRuling struct {
Date string `json:"date"`
Text string `json:"text"`
}
type MTGFormat struct {
Name string `json:"name"`
Sets []string `json:"sets"`
Banned []Card `json:"banned"`
Restricted []Card `json:"restricted"`
}
func LoadFormat(path string) (MTGFormat, error) {
blob, err := ioutil.ReadFile(path)
if err != nil {
return MTGFormat{}, err
}
var format MTGFormat
err = json.Unmarshal(blob, &format)
if err != nil {
return MTGFormat{}, err
}
return format, nil
}
func LoadCollection(path string) (MTGCollection, error) {
blob, err := ioutil.ReadFile(path)
if err != nil {
return MTGCollection{}, err
}
var collection MTGCollection
err = json.Unmarshal(blob, &collection)
if err != nil {
return MTGCollection{}, err
}
return collection, nil
}