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