diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-10 01:21:34 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-10 01:29:23 +0100 |
commit | 1436794fd23df9bcdda172fd1bcb4ff07b16fe3e (patch) | |
tree | 870a25b9654f62df1322c529f71ba81d664813bb | |
parent | Add key binding for random name generation (diff) | |
download | seven-wonders-1436794fd23df9bcdda172fd1bcb4ff07b16fe3e.tar.gz seven-wonders-1436794fd23df9bcdda172fd1bcb4ff07b16fe3e.tar.bz2 seven-wonders-1436794fd23df9bcdda172fd1bcb4ff07b16fe3e.zip |
Fix non-neighbour boards order
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/106
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt | 14 | ||||
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt | 13 |
2 files changed, 17 insertions, 10 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt index bee7fb15..f0f96971 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt @@ -45,12 +45,22 @@ data class PlayerTurnInfo( val currentAge: Int = table.currentAge val message: String = action.message val wonderBuildability: WonderBuildability = table.boards[playerIndex].wonder.buildability + + val RelativeBoardPosition.index: Int + get() = getIndexFrom(playerIndex, table.boards.size) } fun PlayerTurnInfo.getOwnBoard(): Board = table.boards[playerIndex] -fun PlayerTurnInfo.getBoard(position: RelativeBoardPosition): Board = - table.boards[position.getIndexFrom(playerIndex, table.boards.size)] +fun PlayerTurnInfo.getBoard(position: RelativeBoardPosition): Board = table.boards[position.index] + +fun PlayerTurnInfo.getNonNeighbourBoards(): List<Board> { + val nPlayers = table.boards.size + 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 { table.boards[it] } +} // TODO move to server code fun Collection<PlayerTurnInfo>.hideHandsAndWaitForReadiness() = map { it.copy(action = Action.SAY_READY, hand = null) } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt index e9b7b5ad..2dd6135a 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt @@ -4,7 +4,6 @@ import com.palantir.blueprintjs.* import kotlinx.css.* import kotlinx.css.properties.transform import kotlinx.css.properties.translate -import kotlinx.html.DIV import org.luxons.sevenwonders.model.* import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.boards.Board @@ -13,7 +12,6 @@ import org.luxons.sevenwonders.model.cards.HandCard import org.luxons.sevenwonders.ui.components.GlobalStyles import org.luxons.sevenwonders.ui.redux.* import react.* -import styled.StyledDOMBuilder import styled.css import styled.getClassName import styled.styledDiv @@ -56,9 +54,6 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta private fun RBuilder.turnInfoScene(turnInfo: PlayerTurnInfo) { val board = turnInfo.getOwnBoard() - val leftBoard = turnInfo.getBoard(RelativeBoardPosition.LEFT) - val rightBoard = turnInfo.getBoard(RelativeBoardPosition.RIGHT) - val topBoards = (turnInfo.table.boards - board - leftBoard - rightBoard).reversed() styledDiv { css { height = 100.pct @@ -80,7 +75,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta prepareMove = props.prepareMove, cancelTransactionSelection = props.cancelTransactionsSelection, ) - boardSummaries(leftBoard, rightBoard, topBoards) + boardSummaries(turnInfo) handRotationIndicator(turnInfo.table.handRotationDirection) handCards(turnInfo, props.preparedMove, props.prepareMove, props.startTransactionsSelection) val card = props.preparedCard @@ -122,8 +117,10 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta } } - private fun StyledDOMBuilder<DIV>.boardSummaries(leftBoard: Board, rightBoard: Board, topBoards: List<Board>) { - // TODO use blueprint popover with full board preview + private fun RBuilder.boardSummaries(turnInfo: PlayerTurnInfo) { + val leftBoard = turnInfo.getBoard(RelativeBoardPosition.LEFT) + val rightBoard = turnInfo.getBoard(RelativeBoardPosition.RIGHT) + val topBoards = turnInfo.getNonNeighbourBoards().reversed() leftPlayerBoardSummary(leftBoard) rightPlayerBoardSummary(rightBoard) if (topBoards.isNotEmpty()) { |