feat: gamemaster: show number of quotes already played

This commit is contained in:
Settel 2022-03-25 14:24:03 +01:00
parent fcec00345e
commit 4951f0746f
5 changed files with 31 additions and 19 deletions

View File

@ -10,6 +10,12 @@
<td># Players:</td>
<td colspan="2">{{ players.length }}</td>
</tr>
<tr>
<td># Quotes played:</td>
<td colspan="2">
{{ gameinfo.numQuotesTotal - gameinfo.numQuotesLeft }} / {{ gameinfo.numQuotesTotal }}
</td>
</tr>
</table>
</AdminTile>
</template>

View File

@ -11,13 +11,17 @@ func (gm *Game) GetGameInfo() *GameInfoJson {
}
func (gm *Game) initGameInfoJson() *GameInfoJson {
numQuotesLeft, numQuotesTotal := gm.countQuotes()
gm.mu.Lock()
defer gm.mu.Unlock()
gameInfo := GameInfoJson{
Name: gm.name,
State: gm.state,
Players: make([]PlayerInfoJson, 0),
Name: gm.name,
State: gm.state,
Players: make([]PlayerInfoJson, 0),
NumQuotesLeft: numQuotesLeft,
NumQuotesTotal: numQuotesTotal,
}
for _, player := range gm.players {

View File

@ -27,3 +27,16 @@ func (gm *Game) getAllQuotes() []*quote.Quote {
}
return quotes
}
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

@ -25,16 +25,3 @@ func (gm *Game) populateGameInfo() syncdata.GameInfo {
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

@ -93,9 +93,11 @@ type PlayerInfoJson struct {
}
type GameInfoJson struct {
Name string `json:"name"`
State string `json:"state"`
Players []PlayerInfoJson `json:"players"`
Name string `json:"name"`
State string `json:"state"`
Players []PlayerInfoJson `json:"players"`
NumQuotesLeft int `json:"numQuotesLeft"`
NumQuotesTotal int `json:"numQuotesTotal"`
}
type GameStateJson struct {