Commit 669a23b46f8c08ee143c8e820be5e0a2e8bbb2e7

Authored by 王家文
1 parent 6db6913d
Exists in master and in 1 other branch dev-wjw

feat✨:机器人头像增加统一路径

configs/confglobal/config.go
... ... @@ -10,9 +10,10 @@ import (
10 10  
11 11 // GlobalConfig 全局配置
12 12 type GlobalConfig struct {
13   - Raw *Raw `json:"-"`
14   - Names []string
15   - Avatars []string
  13 + Raw *Raw `json:"-"`
  14 + Names []string
  15 + Avatars []string
  16 + AvatarPath string
16 17 }
17 18  
18 19 func (c *GlobalConfig) GetUid() string {
... ... @@ -41,6 +42,7 @@ type Raw struct {
41 42 GameId string `gorm:"column:gameid"`
42 43 NameConfig string
43 44 AvatarConfig string
  45 + AvatarPath string
44 46 }
45 47  
46 48 // Decode 解析配置原始数据
... ... @@ -61,4 +63,5 @@ func (c *GlobalConfig) Decode(gameId string, rawData any) {
61 63 return
62 64 }
63 65 }
  66 + c.AvatarPath = raw.AvatarPath
64 67 }
... ...
controllers/common.go
... ... @@ -34,6 +34,7 @@ func (c *CommonController) GetAvatar() {
34 34 return
35 35 }
36 36 rsp := models.RspCommonGetAvatar{}
  37 + rsp.AvatarPath = svcommon.GetAvatarPath(req.GameID)
37 38 count := lo.Clamp(req.Count, 1, 100)
38 39 for i := 0; i < count; i++ {
39 40 rsp.Values = append(rsp.Values, svcommon.GetAvatar(req.GameID))
... ... @@ -49,6 +50,7 @@ func (c *CommonController) GetNameAvatar() {
49 50 return
50 51 }
51 52 rsp := models.RspCommonGetNameAvatar{}
  53 + rsp.AvatarPath = svcommon.GetAvatarPath(req.GameID)
52 54 count := lo.Clamp(req.Count, 1, 100)
53 55 for i := 0; i < count; i++ {
54 56 v := make([]string, 0)
... ...
models/common.go
... ... @@ -21,7 +21,8 @@ type ReqCommonGetAvatar struct {
21 21  
22 22 // RspCommonGetAvatar 返回
23 23 type RspCommonGetAvatar struct {
24   - Values []string `form:"values" json:"values"` // 结果列表
  24 + AvatarPath string `form:"avatar_path" json:"avatar_path"` // 头像路径
  25 + Values []string `form:"values" json:"values"` // 结果列表
25 26 }
26 27  
27 28 // ReqCommonGetNameAvatar 请求
... ... @@ -33,5 +34,6 @@ type ReqCommonGetNameAvatar struct {
33 34  
34 35 // RspCommonGetNameAvatar 返回
35 36 type RspCommonGetNameAvatar struct {
36   - Values [][]string `form:"values" json:"values"` // 结果列表
  37 + AvatarPath string `form:"avatar_path" json:"avatar_path"` // 头像路径
  38 + Values [][]string `form:"values" json:"values"` // 结果列表
37 39 }
... ...
models/roomrank.go
... ... @@ -31,6 +31,7 @@ type RoomRankInfo struct {
31 31 UserClass int `form:"user_class" json:"user_class"` // 用户评级
32 32 SelfRank int `form:"self_rank" json:"self_rank"` // 自己排名
33 33 SelfScore int64 `form:"self_score" json:"self_score"` // 自己积分
  34 + RobotAvatarPath string `form:"robot_avatar_path" json:"robot_avatar_path"` // 机器人头像路径
34 35 Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表
35 36 }
36 37  
... ...
service-common/svcommon/simulate.go
... ... @@ -28,3 +28,12 @@ func GetAvatar(gameId string) string {
28 28 }
29 29 return "lisi_icon"
30 30 }
  31 +
  32 +// GetAvatarPath 随机模拟玩家头像路径
  33 +func GetAvatarPath(gameId string) string {
  34 + config, err := confglobal.GetConfig(gameId)
  35 + if err == nil {
  36 + return config.AvatarPath
  37 + }
  38 + return ""
  39 +}
... ...
service/roomrank/handle.go
... ... @@ -79,7 +79,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan
79 79 TryReSort(room, config)
80 80 SavePlayer(gameId, player)
81 81 SaveRoom(gameId, room)
82   - rsp.RoomRankInfo = GetInfoFromRoom(player, room, config)
  82 + rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config)
83 83  
84 84 return
85 85 }
... ... @@ -202,7 +202,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs
202 202 SavePlayer(gameId, player)
203 203 SaveRoom(gameId, room)
204 204  
205   - rsp.RoomRankInfo = GetInfoFromRoom(player, room, config)
  205 + rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config)
206 206  
207 207 // 记录日志
208 208 recordBase := NewRecordBase(player.Uid, req.TopType, config.Id)
... ...
service/roomrank/player.go
... ... @@ -87,7 +87,7 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode
87 87 }
88 88  
89 89 // GetInfoFromRoom 活动信息 从房间
90   -func GetInfoFromRoom(player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo {
  90 +func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo {
91 91 info := models.RoomRankInfo{}
92 92 info.UserClass = player.UserClass
93 93 for i := 0; i < len(room.Details.Players); i++ {
... ... @@ -111,5 +111,6 @@ func GetInfoFromRoom(player *Player, room *Room, config *confroomrank.ActivityCo
111 111 }
112 112 info.Tops = append(info.Tops, node)
113 113 }
  114 + info.RobotAvatarPath = svcommon.GetAvatarPath(gameId)
114 115 return info
115 116 }
... ...