From aff9c012e15286718ec6358b153dfabcc3e8d573 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Mon, 8 Mar 2021 00:09:30 +0100 Subject: Move GameState to the client --- .../org/luxons/sevenwonders/model/PlayerState.kt | 43 ---------------------- 1 file changed, 43 deletions(-) (limited to 'sw-common-model') diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt index 725b1654..90d23aa9 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt @@ -1,51 +1,8 @@ package org.luxons.sevenwonders.model import kotlinx.serialization.Serializable -import org.luxons.sevenwonders.model.api.PlayerDTO -import org.luxons.sevenwonders.model.boards.Board -import org.luxons.sevenwonders.model.boards.RelativeBoardPosition -import org.luxons.sevenwonders.model.cards.CardBack -import org.luxons.sevenwonders.model.cards.HandCard -import org.luxons.sevenwonders.model.cards.HandRotationDirection import org.luxons.sevenwonders.model.wonders.WonderBuildability -@Serializable -data class GameState( - val gameId: Long, - val playerIndex: Int, - val currentAge: Age, - val players: List, - val boards: List, - val handRotationDirection: HandRotationDirection, - val action: TurnAction, - val preparedCardsByUsername: Map = emptyMap(), - val currentPreparedMove: PlayerMove? = null, -) { - val currentPreparedCard: HandCard? - get() { - val hand = (action as? TurnAction.PlayFromHand)?.hand - return hand?.firstOrNull { it.name == currentPreparedMove?.cardName } - } - - val RelativeBoardPosition.absoluteIndex: Int - get() = getIndexFrom(playerIndex, boards.size) -} - -fun GameState.getOwnBoard(): Board = boards[playerIndex] - -fun GameState.getBoard(position: RelativeBoardPosition): Board = boards[position.absoluteIndex] - -fun GameState.getNonNeighbourBoards(): List { - val nPlayers = boards.size - if (nPlayers <= 3) { - return emptyList() - } - val first = (playerIndex + 2) % nPlayers - val last = (playerIndex - 2 + nPlayers) % nPlayers - val range = if (first <= last) first..last else ((first until nPlayers) + (0..last)) - return range.map { boards[it] } -} - @Serializable data class PlayerTurnInfo( val playerIndex: Int, -- cgit