restore method

void restore(
  1. LudoGameState state
)

Replaces the current game with state — e.g. one saved earlier with LudoGameState.toJson. Bot seats outside the new player range are dropped.

Implementation

void restore(LudoGameState state) {
  _checkNotDisposed();
  if (state.players.length < 2 || state.players.length > 4) {
    throw ArgumentError.value(
      state.players.length,
      'state.players',
      'Must have 2 to 4 players',
    );
  }
  if (state.teams != null && state.players.length != 4) {
    throw ArgumentError('Teams mode requires exactly 4 players.');
  }
  _abortInFlight();
  _state = state;
  _engine = LudoEngine(diceRules, teams: state.teams);
  _bots.removeWhere((i) => i >= state.players.length);
  _notify();
  _scheduleNext();
}