summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/GameState.kt47
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt43
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt8
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt2
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt2
5 files changed, 57 insertions, 45 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] }
+}
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,52 +1,9 @@
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<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] }
-}
-
-@Serializable
data class PlayerTurnInfo(
val playerIndex: Int,
val table: TableState,
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 03ee881f..976bb2a6 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,13 @@ import com.palantir.blueprintjs.*
import kotlinx.css.*
import kotlinx.css.properties.transform
import kotlinx.css.properties.translate
-import org.luxons.sevenwonders.model.*
+import org.luxons.sevenwonders.client.GameState
+import org.luxons.sevenwonders.client.getBoard
+import org.luxons.sevenwonders.client.getNonNeighbourBoards
+import org.luxons.sevenwonders.client.getOwnBoard
+import org.luxons.sevenwonders.model.MoveType
+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
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
index 2d5d8b8d..1e60dcd4 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
@@ -4,6 +4,8 @@ import com.palantir.blueprintjs.*
import kotlinx.css.*
import kotlinx.css.properties.*
import kotlinx.html.DIV
+import org.luxons.sevenwonders.client.GameState
+import org.luxons.sevenwonders.client.getOwnBoard
import org.luxons.sevenwonders.model.*
import org.luxons.sevenwonders.model.boards.Board
import org.luxons.sevenwonders.model.cards.CardPlayability
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
index 082387c6..3fb72904 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
@@ -1,6 +1,6 @@
package org.luxons.sevenwonders.ui.redux
-import org.luxons.sevenwonders.model.GameState
+import org.luxons.sevenwonders.client.GameState
import org.luxons.sevenwonders.model.api.ConnectedPlayer
import org.luxons.sevenwonders.model.api.GameListEvent
import org.luxons.sevenwonders.model.api.LobbyDTO
bgstack15