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