@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user