-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs.go
93 lines (77 loc) · 1.64 KB
/
structs.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
package goterra
import (
"fmt"
"sort"
"strconv"
)
type Deck struct {
Format uint8
Version uint8
CardGroups []CardGroup
}
func NewDeck() *Deck {
d := Deck{
Version: uint8(1),
Format: uint8(1),
}
return &d
}
func (d *Deck) AddCard(cardCode string, cardCount uint8) {
if cardCount > 3 || cardCount < 1 {
panic("The argument cardCount must be within the values 1 and 3")
}
c := *CardFromCode(cardCode)
if v := c.GetCardMinVersion(); v > d.Version {
d.Version = v
}
if f := c.GetCardMinFormat(); f > d.Format {
d.Format = f
}
d.CardGroups = append(d.CardGroups, CardGroup{
Count: cardCount,
Card: c,
})
}
func (d *Deck) SortDeck() {
sort.Slice(d.CardGroups, func(i, j int) bool {
return d.CardGroups[i].Card.GetCardCode() > d.CardGroups[j].Card.GetCardCode()
})
}
func CardFromCode(cardCode string) *Card {
set, _ := strconv.Atoi(cardCode[:2])
faction := idFromFactionString(cardCode[2:4])
id, _ := strconv.Atoi(cardCode[4:])
return &Card{
Set: uint8(set),
Faction: uint8(faction),
Id: uint8(id),
}
}
func (c Card) GetFactionStringId() string {
return Factions[int(c.Faction)]
}
func (c Card) GetCardCode() string {
return fmt.Sprintf("%02d%s%03d", c.Set, c.GetFactionStringId(), c.Id)
}
func (c Card) getGroupId() string {
return fmt.Sprintf("%d.%d", c.Set, c.Faction)
}
func (c Card) GetCardMinVersion() uint8 {
return FactionsVersion[c.Faction][1]
}
func (c Card) GetCardMinFormat() uint8 {
return FactionsVersion[c.Faction][0]
}
type CardGroup struct {
Count uint8
Card Card
}
type Card struct {
Set uint8
Faction uint8
Id uint8
}
type Faction struct {
Id uint8
TextId string
}