calculate number of quotes left/total, send to client

This commit is contained in:
Settel 2021-12-03 18:36:19 +01:00
parent 32f9fa68b3
commit 237a0d0345
2 changed files with 29 additions and 10 deletions

View File

@ -9,6 +9,8 @@ func (gm *Game) populateSyncDataCb(syncData *syncdata.SyncData) {
} }
func (gm *Game) populateGameInfo() syncdata.GameInfo { func (gm *Game) populateGameInfo() syncdata.GameInfo {
numQuotesLeft, numQuotesTotal := gm.countQuotes()
gm.mu.Lock() gm.mu.Lock()
defer gm.mu.Unlock() defer gm.mu.Unlock()
@ -18,5 +20,20 @@ func (gm *Game) populateGameInfo() syncdata.GameInfo {
Phase: gm.phase, Phase: gm.phase,
Players: gm.populateGetPlayers(), Players: gm.populateGetPlayers(),
Round: gm.populateGetRoundInfo(), 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)
}

View File

@ -36,6 +36,8 @@ type GameInfo struct {
Phase string `json:"phase"` Phase string `json:"phase"`
Players []PlayerInfo `json:"players"` Players []PlayerInfo `json:"players"`
Round *RoundInfo `json:"round"` Round *RoundInfo `json:"round"`
NumQuotesLeft int `json:"numQuotesLeft"`
NumQuotesTotal int `json:"numQuotesTotal"`
} }
type SyncData struct { type SyncData struct {