NewGameViewModel

class NewGameViewModel(val scope: CoroutineScope, val appState: AppStateImpl, val globalError: ReversiException? = null, val setGlobalError: (Exception?, ErrorType?) -> Unit, val createGame: (Game) -> Unit) : ViewModel<NewGameUiState>

ViewModel that builds local or remote games based on user inputs. Validates piece selection, triggers game creation, and exposes UI state/errors.

Parameters

scope

Coroutine scope for background operations.

playerName

Current player name used when creating non-local games.

globalError

Optional global error propagated into initial UI state.

setGlobalError

Callback to update global error when present.

createGame

Callback invoked with the created game instance.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, appState: AppStateImpl, globalError: ReversiException? = null, setGlobalError: (Exception?, ErrorType?) -> Unit, createGame: (Game) -> Unit)

Properties

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

The mutable internal UI state.

Link copied to clipboard
private val appState: AppStateImpl
Link copied to clipboard
private val createGame: (Game) -> Unit
Link copied to clipboard
open override val globalError: ReversiException?
Link copied to clipboard
private val scope: CoroutineScope
Link copied to clipboard
open override val setGlobalError: (Exception?, ErrorType?) -> Unit

Functions

Link copied to clipboard
private suspend fun createLocalGame(boardSize: Int, myPiece: PieceType): Game
Link copied to clipboard
private suspend fun createNotLocalGame(playerName: String, gameName: String, boardSize: Int, myPiece: PieceType): Game
Link copied to clipboard
fun tryCreateGame(game: Game, boardSize: Int, playerName: String?)