GamePageViewModel

class GamePageViewModel(val game: Game, val scope: CoroutineScope, val setGame: (Game) -> Unit, val audioPlayMove: () -> Unit, val setPage: (Page) -> Unit = {}, val globalError: ReversiException? = null, val setGlobalError: (Exception?, ErrorType?) -> Unit) : ViewModel<GameUiState>

View model for the game page managing game state, UI updates, and user interactions. Handles game move execution, state polling for multiplayer games, and sound effects.

Constructors

Link copied to clipboard
constructor(game: Game, scope: CoroutineScope, setGame: (Game) -> Unit, audioPlayMove: () -> Unit, setPage: (Page) -> Unit = {}, globalError: ReversiException? = null, setGlobalError: (Exception?, ErrorType?) -> Unit)

Properties

Link copied to clipboard
protected open override val _uiState: MutableState<GameUiState>

The mutable internal UI state.

Link copied to clipboard
private val audioPlayMove: () -> Unit

Callback function to play move sound effect.

Link copied to clipboard
private val game: Game

The current game state.

Link copied to clipboard
open override val globalError: ReversiException?

Optional error to display on initial load.

Link copied to clipboard
private var pollingJob: Job?
Link copied to clipboard
private val scope: CoroutineScope

Coroutine scope for launching async game operations.

Link copied to clipboard
private val setGame: (Game) -> Unit

Callback function to persist updated game state.

Link copied to clipboard
open override val setGlobalError: (Exception?, ErrorType?) -> Unit

Callback function to update global error state.

Link copied to clipboard
private val setPage: (Page) -> Unit

Functions

Link copied to clipboard
Link copied to clipboard
fun gotoWinnerPage(game: Game)
Link copied to clipboard
Link copied to clipboard
fun pass()
Link copied to clipboard
fun playMove(coordinate: Coordinate)
Link copied to clipboard
fun setTarget(target: Boolean)
Link copied to clipboard

Starts a coroutine that periodically polls the game state to refresh it. If the game has a winner, it navigates to the winner page. If the game has not started yet or is corrupted, it sets an appropriate error. The polling runs every 50 milliseconds until cancelled.

Link copied to clipboard