summaryrefslogtreecommitdiff
path: root/sw-client/src/commonMain/kotlin/org
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2021-03-08 00:09:30 +0100
committerJoffrey Bion <joffrey.bion@gmail.com>2021-03-08 00:11:00 +0100
commitaff9c012e15286718ec6358b153dfabcc3e8d573 (patch)
tree647c6a1093f755b83ed9ad35db2025148c21980b /sw-client/src/commonMain/kotlin/org
parentFix empty guilds check (diff)
downloadseven-wonders-aff9c012e15286718ec6358b153dfabcc3e8d573.tar.gz
seven-wonders-aff9c012e15286718ec6358b153dfabcc3e8d573.tar.bz2
seven-wonders-aff9c012e15286718ec6358b153dfabcc3e8d573.zip
Move GameState to the client
Diffstat (limited to 'sw-client/src/commonMain/kotlin/org')
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/GameState.kt47
1 files changed, 47 insertions, 0 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/GameState.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/GameState.kt
new file mode 100644
index 00000000..e8a393f7
--- /dev/null
+++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/GameState.kt
@@ -0,0 +1,47 @@
+package org.luxons.sevenwonders.client
+
+import org.luxons.sevenwonders.model.Age
+import org.luxons.sevenwonders.model.PlayerMove
+import org.luxons.sevenwonders.model.TurnAction
+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
+
+data class GameState(
+ val gameId: Long,
+ val playerIndex: Int,
+ val currentAge: Age,
+ val players: List<PlayerDTO>,
+ val boards: List<Board>,
+ val handRotationDirection: HandRotationDirection,
+ val action: TurnAction,
+ val preparedCardsByUsername: Map<String, CardBack?> = 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<Board> {
+ 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] }
+}
bgstack15