calculate number of quotes left/total, send to client
This commit is contained in:
parent
32f9fa68b3
commit
237a0d0345
@ -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)
|
||||||
|
}
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user