summaryrefslogtreecommitdiff
path: root/sw-common-model
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2021-02-24 01:36:50 +0100
committerJoffrey Bion <joffrey.bion@gmail.com>2021-02-24 01:36:50 +0100
commit594a7037af815020658ab127b6649b45bca0cbc1 (patch)
tree5f1ffad6be5ddcb4107f0075888573493061591d /sw-common-model
parentRemove unnecessary flex style from selfBoardSummary (diff)
downloadseven-wonders-594a7037af815020658ab127b6649b45bca0cbc1.tar.gz
seven-wonders-594a7037af815020658ab127b6649b45bca0cbc1.tar.bz2
seven-wonders-594a7037af815020658ab127b6649b45bca0cbc1.zip
Improved state
Diffstat (limited to 'sw-common-model')
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/PlayerState.kt46
-rw-r--r--sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/TableState.kt4
2 files changed, 35 insertions, 15 deletions
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 271b2a99..725b1654 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,37 +1,59 @@
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 PlayerTurnInfo(
+data class GameState(
+ val gameId: Long,
val playerIndex: Int,
- val table: TableState,
+ 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 currentAge: Int = table.currentAge
- val message: String = action.message
- val wonderBuildability: WonderBuildability = table.boards[playerIndex].wonder.buildability
+ val currentPreparedCard: HandCard?
+ get() {
+ val hand = (action as? TurnAction.PlayFromHand)?.hand
+ return hand?.firstOrNull { it.name == currentPreparedMove?.cardName }
+ }
- val RelativeBoardPosition.index: Int
- get() = getIndexFrom(playerIndex, table.boards.size)
+ val RelativeBoardPosition.absoluteIndex: Int
+ get() = getIndexFrom(playerIndex, boards.size)
}
-fun PlayerTurnInfo.getOwnBoard(): Board = table.boards[playerIndex]
+fun GameState.getOwnBoard(): Board = boards[playerIndex]
-fun PlayerTurnInfo.getBoard(position: RelativeBoardPosition): Board = table.boards[position.index]
+fun GameState.getBoard(position: RelativeBoardPosition): Board = boards[position.absoluteIndex]
-fun PlayerTurnInfo.getNonNeighbourBoards(): List<Board> {
- val nPlayers = table.boards.size
+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 { table.boards[it] }
+ return range.map { boards[it] }
+}
+
+@Serializable
+data class PlayerTurnInfo(
+ val playerIndex: Int,
+ val table: TableState,
+ val action: TurnAction,
+) {
+ val currentAge: Int = table.currentAge
+ val wonderBuildability: WonderBuildability = table.boards[playerIndex].wonder.buildability
}
// TODO move to server code
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/TableState.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/TableState.kt
index d27fccb5..e19ce272 100644
--- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/TableState.kt
+++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/TableState.kt
@@ -12,6 +12,4 @@ data class TableState(
val currentAge: Age,
val handRotationDirection: HandRotationDirection,
val lastPlayedMoves: List<PlayedMove>,
-) {
- val nbPlayers: Int = boards.size
-}
+)
bgstack15