Skip to content

Commit

Permalink
fix activegame pause state
Browse files Browse the repository at this point in the history
  • Loading branch information
bqv committed Oct 20, 2023
1 parent 046f53c commit 954fc56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/io/zenandroid/onlinego/data/db/GameDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import io.zenandroid.onlinego.data.model.local.GameNotificationWithDetails
import io.zenandroid.onlinego.data.model.local.HistoricGamesMetadata
import io.zenandroid.onlinego.data.model.local.InitialState
import io.zenandroid.onlinego.data.model.local.Message
import io.zenandroid.onlinego.data.model.local.PauseControl
import io.zenandroid.onlinego.data.model.local.Player
import io.zenandroid.onlinego.data.model.local.Puzzle
import io.zenandroid.onlinego.data.model.local.PuzzleCollection
Expand All @@ -31,8 +32,7 @@ import io.zenandroid.onlinego.data.model.local.Score
import io.zenandroid.onlinego.data.model.local.VisitedPuzzleCollection
import io.zenandroid.onlinego.data.model.ogs.JosekiPosition
import io.zenandroid.onlinego.data.model.ogs.Phase
import io.zenandroid.onlinego.data.model.ogs.PuzzleRating
import io.zenandroid.onlinego.data.model.ogs.PuzzleSolution
import io.zenandroid.onlinego.data.ogs.Pause
import kotlinx.coroutines.flow.Flow

private const val MAX_ALLOWED_SQL_PARAMS = 999
Expand Down Expand Up @@ -230,12 +230,15 @@ abstract class GameDao {
open fun updateClock(
id: Long,
playerToMoveId: Long?,
clock: Clock?) {
clock: Clock?,
pause: Pause?) {
getGame(id).blockingGet().let {
update(it.copy(
undoRequested = if(it.playerToMoveId != playerToMoveId) null else it.undoRequested,
playerToMoveId = playerToMoveId,
clock = clock,
pauseControl = (it.pauseControl ?: PauseControl())
.copy(pausedByThirdParty = pause?.paused),
pausedSince = when(clock?.newPausedState) {
true -> clock.newPausedSince
false -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ class ActiveGamesRepository(
gameDao.updateClock(
id = gameId,
playerToMoveId = clock.current_player,
clock = Clock.fromOGSClock(clock)
clock = Clock.fromOGSClock(clock),
pause = clock.pause
)
}

Expand Down Expand Up @@ -388,4 +389,4 @@ class ActiveGamesRepository(
recordException(Exception(message, t))
Log.e("ActiveGameRespository", message, t)
}
}
}

0 comments on commit 954fc56

Please sign in to comment.