@@ -29,17 +29,41 @@ type GameSummary struct {
29
29
ChatWon int `json:"chat_won"`
30
30
}
31
31
32
+ type CategoryGroupDefinition struct {
33
+ ID string `json:"id"`
34
+ Title string `json:"title"`
35
+ IsDev bool `json:"-"`
36
+ IsRelease bool `json:"-"`
37
+ Categories []CategoryDefinition `json:"categories"`
38
+ }
39
+
32
40
type CategoryGroup struct {
33
- Title string `json:"title"`
34
- IsDev bool `json:"-"`
35
- IsRelease bool `json:"-"`
41
+ CategoryGroupDefinition
36
42
Categories []Category `json:"categories"`
37
43
}
38
44
45
+ func (cg CategoryGroup ) GetDefinition () CategoryGroupDefinition {
46
+ cg .CategoryGroupDefinition .Categories = make ([]CategoryDefinition , len (cg .Categories ))
47
+ for i , c := range cg .Categories {
48
+ cg .CategoryGroupDefinition .Categories [i ] = c .GetDefinition ()
49
+ }
50
+ return cg .CategoryGroupDefinition
51
+ }
52
+
53
+ type CategoryDefinition struct {
54
+ ID string `json:"id"`
55
+ Title string `json:"title"`
56
+ Count int `json:"count,omitempty"`
57
+ }
58
+
39
59
type Category struct {
40
- Title string `json:"-"`
41
- Description string `json:"description"`
42
- Pool []* Question `json:"pool"`
60
+ CategoryDefinition
61
+ Pool []* Question `json:"pool"`
62
+ }
63
+
64
+ func (c Category ) GetDefinition () CategoryDefinition {
65
+ c .CategoryDefinition .Count = len (c .Pool )
66
+ return c .CategoryDefinition
43
67
}
44
68
45
69
type Question struct {
@@ -61,12 +85,12 @@ const (
61
85
)
62
86
63
87
type Round struct {
64
- Question string `json:"question"`
65
- Answers []string `json:"answers"`
66
- Correct int `json:"correct,omitempty"`
67
- Current int `json:"current_round"`
68
- Max int `json:"max_round"`
69
- Category string `json:"category"`
88
+ Question string `json:"question"`
89
+ Answers []string `json:"answers"`
90
+ Correct int `json:"correct,omitempty"`
91
+ Current int `json:"current_round"`
92
+ Max int `json:"max_round"`
93
+ Category CategoryDefinition `json:"category"`
70
94
}
71
95
72
96
type RoundSummary struct {
@@ -88,14 +112,22 @@ var log = logger.New(logger.Writer(), "[WEB] ", logger.LstdFlags|logger.Lmsgpref
88
112
func (cg categoryGroups ) GetCategoryByName (name string ) Category {
89
113
for _ , group := range cg {
90
114
for _ , c := range group .Categories {
91
- if c .Title == name {
115
+ if c .ID == name {
92
116
return c
93
117
}
94
118
}
95
119
}
96
120
return Category {}
97
121
}
98
122
123
+ func (cg categoryGroups ) GetDefinition () (definitions map [int ]CategoryGroupDefinition ) {
124
+ definitions = make (map [int ]CategoryGroupDefinition , len (cg ))
125
+ for color , group := range cg {
126
+ definitions [color ] = group .GetDefinition ()
127
+ }
128
+ return definitions
129
+ }
130
+
99
131
func (g Game ) GetRoundSummary () RoundSummary {
100
132
sum := RoundSummary {
101
133
StreamerPoints : g .Summary .StreamerPoints ,
@@ -198,7 +230,7 @@ func (c Category) GetRounds(n int) []*Round {
198
230
continue
199
231
}
200
232
round := q .ToRound ()
201
- round .Category = c .Title
233
+ round .Category = c .GetDefinition ()
202
234
rounds = append (rounds , & round )
203
235
}
204
236
return rounds
0 commit comments