decode.go
1.2 KB
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
package confroomrank
import (
"apigame/util/util-lx/lxalilog"
"encoding/json"
)
// Decode 解析配置原始数据
func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) {
c.GameId = gameId
c.Raw = configRaw
c.Id = configRaw.Id
c.OpenLevel = configRaw.OpenLevel
c.PreviewTime = configRaw.PreviewTime
c.StartTime = configRaw.StartTime
c.EndTime = configRaw.EndTime
c.Robot = make(map[int]RobotConfig)
c.Room = make(map[int]RoomConfig)
// 解析 机器人
{
configs := make([]RobotConfig, 0)
err := json.Unmarshal([]byte(configRaw.Robot), &configs)
if err != nil {
lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id)
return
}
for _, i2 := range configs {
c.Robot[i2.Id] = i2
}
}
// 解析 房间
{
configs := make([]RoomConfig, 0)
err := json.Unmarshal([]byte(configRaw.Room), &configs)
if err != nil {
lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id)
return
}
for _, i2 := range configs {
c.Room[i2.Id] = i2
}
}
c.GenerateConfigClient()
}
// GenerateConfigClient 生成给客户端的配置
func (c *ActivityConfig) GenerateConfigClient() {
configClient := &ActivityConfigClient{
Id: c.Id,
}
c.Client = configClient
}