knowyt/server/src/game/getGameInfo.go

35 lines
694 B
Go
Raw Normal View History

2022-02-27 19:54:13 +00:00
package game
import ()
func (gm *Game) GetGameInfo() *GameInfoJson {
gameInfo := gm.initGameInfoJson()
for i, _ := range gameInfo.Players {
gameInfo.Players[i].Quotes = gm.getQuotesInfoByUserId(gameInfo.Players[i].Id)
}
return gameInfo
}
func (gm *Game) initGameInfoJson() *GameInfoJson {
2022-02-27 19:54:13 +00:00
gm.mu.Lock()
defer gm.mu.Unlock()
gameInfo := GameInfoJson{
Name: gm.name,
Players: make([]PlayerInfoJson, 0),
2022-02-27 19:54:13 +00:00
}
for _, player := range gm.players {
gameInfo.Players = append(gameInfo.Players, PlayerInfoJson{
Id: player.id,
Name: player.name,
Score: player.score,
IsPlaying: player.isPlaying,
IsIdle: player.isIdle,
})
}
2022-02-27 19:54:13 +00:00
return &gameInfo
}