diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/counter/CounterViewModel.kt b/app/src/main/java/me/zobrist/tichucounter/ui/counter/CounterViewModel.kt index c3b8b9a..651d5db 100644 --- a/app/src/main/java/me/zobrist/tichucounter/ui/counter/CounterViewModel.kt +++ b/app/src/main/java/me/zobrist/tichucounter/ui/counter/CounterViewModel.kt @@ -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 } } }