calculate number of quotes left/total, send to client
This commit is contained in:
parent
32f9fa68b3
commit
237a0d0345
@ -9,14 +9,31 @@ func (gm *Game) populateSyncDataCb(syncData *syncdata.SyncData) {
|
||||
}
|
||||
|
||||
func (gm *Game) populateGameInfo() syncdata.GameInfo {
|
||||
numQuotesLeft, numQuotesTotal := gm.countQuotes()
|
||||
|
||||
gm.mu.Lock()
|
||||
defer gm.mu.Unlock()
|
||||
|
||||
return syncdata.GameInfo{
|
||||
GameId: gm.id,
|
||||
State: gm.state,
|
||||
Phase: gm.phase,
|
||||
Players: gm.populateGetPlayers(),
|
||||
Round: gm.populateGetRoundInfo(),
|
||||
GameId: gm.id,
|
||||
State: gm.state,
|
||||
Phase: gm.phase,
|
||||
Players: gm.populateGetPlayers(),
|
||||
Round: gm.populateGetRoundInfo(),
|
||||
NumQuotesLeft: numQuotesLeft,
|
||||
NumQuotesTotal: numQuotesTotal,
|
||||
}
|
||||
}
|
||||
|
||||
func (gm *Game) countQuotes() (int, int) {
|
||||
allQuotes := gm.getAllQuotes()
|
||||
numQuotesLeft := 0
|
||||
|
||||
for _, q := range allQuotes {
|
||||
if !q.IsPlayed() {
|
||||
numQuotesLeft++
|
||||
}
|
||||
}
|
||||
|
||||
return numQuotesLeft, len(allQuotes)
|
||||
}
|
||||
|
@ -31,11 +31,13 @@ type RoundInfo struct {
|
||||
}
|
||||
|
||||
type GameInfo struct {
|
||||
GameId string `json:"id"`
|
||||
State string `json:"state"`
|
||||
Phase string `json:"phase"`
|
||||
Players []PlayerInfo `json:"players"`
|
||||
Round *RoundInfo `json:"round"`
|
||||
GameId string `json:"id"`
|
||||
State string `json:"state"`
|
||||
Phase string `json:"phase"`
|
||||
Players []PlayerInfo `json:"players"`
|
||||
Round *RoundInfo `json:"round"`
|
||||
NumQuotesLeft int `json:"numQuotesLeft"`
|
||||
NumQuotesTotal int `json:"numQuotesTotal"`
|
||||
}
|
||||
|
||||
type SyncData struct {
|
||||
|
Loading…
Reference in New Issue
Block a user