Skip to content

Commit

Permalink
fix: ending a game does not stop timer (closes #119)
Browse files Browse the repository at this point in the history
* also fixes a potential crash and pause icon visibility
  • Loading branch information
kaajjo committed Dec 11, 2024
1 parent 5be0749 commit 7de7e3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.kaajjo.libresudoku.data.database.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.kaajjo.libresudoku.core.qqwing.GameDifficulty
import com.kaajjo.libresudoku.core.qqwing.GameType
Expand Down Expand Up @@ -30,9 +31,9 @@ interface RecordDao {
@Delete
suspend fun delete(record: Record)

@Insert
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(record: Record)

@Insert
suspend fun insert(recrods: List<Record>)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(records: List<Record>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ fun GameScreen(
modifier = Modifier.align(Alignment.Center)
) {
AnimatedVisibility(
visible = !viewModel.gamePlaying,
visible = !viewModel.gamePlaying && !viewModel.endGame,
enter = expandVertically(clip = false) + fadeIn(),
exit = shrinkVertically(clip = false) + fadeOut()
) {
Expand Down Expand Up @@ -615,7 +615,6 @@ fun GameScreen(

LaunchedEffect(viewModel.gameCompleted) {
if (viewModel.gameCompleted) {
viewModel.endGame = true
viewModel.onGameComplete()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ class GameViewModel @Inject constructor(

fun onGameComplete() {
if (endGame) return

pauseTimer()
currCell = Cell(-1, -1, 0)
viewModelScope.launch(Dispatchers.IO) {
saveGame()
recordRepository.insert(
Expand All @@ -704,8 +707,7 @@ class GameViewModel @Inject constructor(
)
)
}
pauseTimer()
currCell = Cell(-1, -1, 0)
endGame = true
}

fun getFontSize(type: GameType = gameType, factor: Int): TextUnit {
Expand Down

0 comments on commit 7de7e3d

Please sign in to comment.