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># Players:</td>
<td colspan="2">{{ players.length }}</td> <td colspan="2">{{ players.length }}</td>
</tr> </tr>
<tr>
<td># Quotes played:</td>
<td colspan="2">
{{ gameinfo.numQuotesTotal - gameinfo.numQuotesLeft }} / {{ gameinfo.numQuotesTotal }}
</td>
</tr>
</table> </table>
</AdminTile> </AdminTile>
</template> </template>

View File

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

View File

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

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