Reset gameFinished on removed round.

closes: #52
This commit is contained in:
2023-09-27 18:30:03 +02:00
parent 44246e329e
commit 461dc4a30c

View File

@@ -168,6 +168,7 @@ class CounterViewModel @Inject constructor(
private val gameWon: Boolean
get() = totalScoreA >= settings.victoryPoints.value || totalScoreB >= settings.victoryPoints.value
private var lastRoundCount: Int = 0
init {
viewModelScope.launch {
gameRepository.getActiveGameFlow().collect {
@@ -183,18 +184,30 @@ class CounterViewModel @Inject constructor(
buildTeamNameSuggestions()
// Game has changed
if (it.game.uid != lastGame?.uid) {
if (lastGame != null) {
settings.gameFinished.value = false
}
lastGame = it.game
lastRoundCount = it.rounds.size
}
// Game winning condition
if (!settings.gameFinished.value) {
if (gameWon) {
showVictoryDialog = true
}
}
// Undo game winning if rounds were removed
if(lastRoundCount > it.rounds.size)
{
if(!gameWon){
settings.gameFinished.value = false
}
}
lastRoundCount = it.rounds.size
}
}
}