diff options
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/GameState.kt (renamed from sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Table.kt) | 6 | ||||
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Moves.kt | 2 | ||||
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/boards/Boards.kt | 18 | ||||
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt | 6 | ||||
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt | 4 | ||||
-rw-r--r-- | sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt | 10 | ||||
-rw-r--r-- | sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt | 70 | ||||
-rw-r--r-- | sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Table.kt | 6 | ||||
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt | 6 |
9 files changed, 63 insertions, 65 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Table.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/GameState.kt index 2e29090e..3de605b2 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/Table.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/GameState.kt @@ -1,12 +1,12 @@ package org.luxons.sevenwonders.model -import org.luxons.sevenwonders.model.boards.ApiBoard +import org.luxons.sevenwonders.model.boards.Board import org.luxons.sevenwonders.model.cards.HandRotationDirection typealias Age = Int -data class ApiTable( - val boards: List<ApiBoard>, +data class GameState( + val boards: List<Board>, val currentAge: Age, val handRotationDirection: HandRotationDirection, val lastPlayedMoves: List<PlayedMove> 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 9a80b82a..8206ec8d 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 @@ -16,7 +16,7 @@ enum class Action(val message: String) { data class PlayerTurnInfo( val playerIndex: Int, - val table: ApiTable, + val table: GameState, val action: Action, val hand: List<HandCard>, val preparedMove: PlayedMove?, diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/boards/Boards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/boards/Boards.kt index a91b2488..d06e203d 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/boards/Boards.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/boards/Boards.kt @@ -5,34 +5,34 @@ import org.luxons.sevenwonders.model.resources.CountedResource import org.luxons.sevenwonders.model.resources.ResourceType import org.luxons.sevenwonders.model.wonders.ApiWonder -data class ApiBoard( +data class Board( val playerIndex: Int, val wonder: ApiWonder, - val production: ApiProduction, - val publicProduction: ApiProduction, - val science: ApiScience, - val military: ApiMilitary, + val production: Production, + val publicProduction: Production, + val science: Science, + val military: Military, val playedCards: List<List<TableCard>>, val gold: Int ) -data class ApiRequirements( +data class Requirements( val gold: Int = 0, val resources: List<CountedResource> = emptyList() ) -data class ApiProduction( +data class Production( val fixedResources: List<CountedResource>, val alternativeResources: Set<Set<ResourceType>> ) -data class ApiMilitary( +data class Military( val nbShields: Int, val totalPoints: Int, val nbDefeatTokens: Int ) -data class ApiScience( +data class Science( val jokers: Int, val nbWheels: Int, val nbCompasses: Int, diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt index d0121019..57cf3a00 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt @@ -1,12 +1,12 @@ package org.luxons.sevenwonders.model.cards -import org.luxons.sevenwonders.model.boards.ApiRequirements +import org.luxons.sevenwonders.model.boards.Requirements import org.luxons.sevenwonders.model.resources.ResourceTransactions data class TableCard( val name: String, val color: Color, - val requirements: ApiRequirements, + val requirements: Requirements, val chainParent: String?, val chainChildren: List<String>, val image: String, @@ -21,7 +21,7 @@ data class TableCard( data class HandCard( val name: String, val color: Color, - val requirements: ApiRequirements, + val requirements: Requirements, val chainParent: String?, val chainChildren: List<String>, val image: String, diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt index 73fd6a30..a6273c5a 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.model.wonders -import org.luxons.sevenwonders.model.boards.ApiRequirements +import org.luxons.sevenwonders.model.boards.Requirements import org.luxons.sevenwonders.model.cards.CardBack import org.luxons.sevenwonders.model.cards.PlayabilityLevel import org.luxons.sevenwonders.model.resources.ResourceTransactions @@ -18,7 +18,7 @@ data class ApiWonder( data class ApiWonderStage( val cardBack: CardBack?, val isBuilt: Boolean, - val requirements: ApiRequirements, + val requirements: Requirements, val builtDuringLastMove: Boolean ) diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt index bbd96d33..8cdda393 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt @@ -5,7 +5,7 @@ import org.luxons.sevenwonders.engine.boards.Table import org.luxons.sevenwonders.engine.cards.Card import org.luxons.sevenwonders.engine.cards.Decks import org.luxons.sevenwonders.engine.cards.Hands -import org.luxons.sevenwonders.engine.converters.toApiTable +import org.luxons.sevenwonders.engine.converters.toGameState import org.luxons.sevenwonders.engine.converters.toPlayedMove import org.luxons.sevenwonders.engine.converters.toTableCard import org.luxons.sevenwonders.engine.data.LAST_AGE @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.engine.moves.Move import org.luxons.sevenwonders.engine.moves.resolve import org.luxons.sevenwonders.engine.score.ScoreBoard import org.luxons.sevenwonders.model.Action -import org.luxons.sevenwonders.model.ApiTable +import org.luxons.sevenwonders.model.GameState import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.cards.CardBack @@ -54,7 +54,7 @@ class Game internal constructor( return PlayerTurnInfo( playerIndex = player.index, - table = table.toApiTable(), + table = table.toGameState(), action = action, hand = hand, preparedMove = preparedMoves[player.index]?.toPlayedMove(), @@ -107,7 +107,7 @@ class Game internal constructor( * had not prepared their moves (unless these players had nothing to do). To avoid this, please check if everyone * is ready using [allPlayersPreparedTheirMove]. */ - fun playTurn(): ApiTable { + fun playTurn(): GameState { makeMoves() if (endOfAgeReached()) { executeEndOfAgeEvents() @@ -118,7 +118,7 @@ class Game internal constructor( rotateHandsIfRelevant() startNewTurn() } - return table.toApiTable() + return table.toGameState() } private fun makeMoves() { diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt index ad03c228..efb2613e 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Boards.kt @@ -1,26 +1,26 @@ package org.luxons.sevenwonders.engine.converters import org.luxons.sevenwonders.engine.Player -import org.luxons.sevenwonders.engine.boards.Military -import org.luxons.sevenwonders.engine.boards.Science import org.luxons.sevenwonders.engine.boards.ScienceType -import org.luxons.sevenwonders.engine.cards.Requirements import org.luxons.sevenwonders.engine.moves.Move -import org.luxons.sevenwonders.engine.resources.Production import org.luxons.sevenwonders.engine.resources.Resources import org.luxons.sevenwonders.model.MoveType -import org.luxons.sevenwonders.model.boards.ApiBoard -import org.luxons.sevenwonders.model.boards.ApiMilitary -import org.luxons.sevenwonders.model.boards.ApiProduction -import org.luxons.sevenwonders.model.boards.ApiRequirements -import org.luxons.sevenwonders.model.boards.ApiScience import org.luxons.sevenwonders.model.cards.TableCard import org.luxons.sevenwonders.model.resources.CountedResource -import org.luxons.sevenwonders.model.wonders.ApiWonder -import org.luxons.sevenwonders.model.wonders.ApiWonderStage import org.luxons.sevenwonders.engine.boards.Board as InternalBoard +import org.luxons.sevenwonders.engine.boards.Military as InternalMilitary +import org.luxons.sevenwonders.engine.boards.Science as InternalScience +import org.luxons.sevenwonders.engine.cards.Requirements as InternalRequirements +import org.luxons.sevenwonders.engine.resources.Production as InternalProduction import org.luxons.sevenwonders.engine.wonders.Wonder as InternalWonder import org.luxons.sevenwonders.engine.wonders.WonderStage as InternalWonderStage +import org.luxons.sevenwonders.model.boards.Board as ApiBoard +import org.luxons.sevenwonders.model.boards.Military as ApiMilitary +import org.luxons.sevenwonders.model.boards.Production as ApiProduction +import org.luxons.sevenwonders.model.boards.Requirements as ApiRequirements +import org.luxons.sevenwonders.model.boards.Science as ApiScience +import org.luxons.sevenwonders.model.wonders.ApiWonder as ApiWonder +import org.luxons.sevenwonders.model.wonders.ApiWonderStage as ApiWonderStage internal fun InternalBoard.toApiBoard(player: Player, lastMove: Move?): ApiBoard = ApiBoard( @@ -45,34 +45,33 @@ internal fun List<TableCard>.toColumns(): List<List<TableCard>> { return listOf(resourceCardsCol) + otherColsSorted } -internal fun InternalWonder.toApiWonder(player: Player, lastMove: Move?): ApiWonder = - ApiWonder( - name = name, - initialResource = initialResource, - stages = stages.map { it.toApiWonderStage(lastBuiltStage == it, lastMove) }, - image = image, - nbBuiltStages = nbBuiltStages, - buildability = computeBuildabilityBy(player) - ) - -internal fun InternalWonderStage.toApiWonderStage( - isLastBuiltStage: Boolean, - lastMove: Move? -): ApiWonderStage = ApiWonderStage( - cardBack = cardBack, - isBuilt = isBuilt, - requirements = requirements.toApiRequirements(), - builtDuringLastMove = lastMove?.type == MoveType.UPGRADE_WONDER && isLastBuiltStage +internal fun InternalWonder.toApiWonder(player: Player, lastMove: Move?): ApiWonder = ApiWonder( + name = name, + initialResource = initialResource, + stages = stages.map { it.toApiWonderStage(lastBuiltStage == it, lastMove) }, + image = image, + nbBuiltStages = nbBuiltStages, + buildability = computeBuildabilityBy(player) ) -internal fun Production.toApiProduction(): ApiProduction = +internal fun InternalWonderStage.toApiWonderStage(isLastBuiltStage: Boolean, lastMove: Move?): ApiWonderStage = + ApiWonderStage( + cardBack = cardBack, + isBuilt = isBuilt, + requirements = requirements.toApiRequirements(), + builtDuringLastMove = lastMove?.type == MoveType.UPGRADE_WONDER && isLastBuiltStage + ) + +internal fun InternalProduction.toApiProduction(): ApiProduction = ApiProduction( - fixedResources = getFixedResources().toCountedResourcesList(), alternativeResources = getAlternativeResources() + fixedResources = getFixedResources().toCountedResourcesList(), + alternativeResources = getAlternativeResources() ) -internal fun Requirements.toApiRequirements(): ApiRequirements = +internal fun InternalRequirements.toApiRequirements(): ApiRequirements = ApiRequirements( - gold = gold, resources = resources.toCountedResourcesList() + gold = gold, + resources = resources.toCountedResourcesList() ) internal fun Resources.toCountedResourcesList(): List<CountedResource> = @@ -80,10 +79,9 @@ internal fun Resources.toCountedResourcesList(): List<CountedResource> = .map { (type, count) -> CountedResource(count, type) } .sortedBy { it.type } -internal fun Military.toApiMilitary(): ApiMilitary = - ApiMilitary(nbShields, totalPoints, nbDefeatTokens) +internal fun InternalMilitary.toApiMilitary(): ApiMilitary = ApiMilitary(nbShields, totalPoints, nbDefeatTokens) -internal fun Science.toApiScience(): ApiScience = +internal fun InternalScience.toApiScience(): ApiScience = ApiScience( jokers = jokers, nbWheels = getQuantity(ScienceType.WHEEL), diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Table.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Table.kt index d2f5410b..77843334 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Table.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/converters/Table.kt @@ -1,12 +1,12 @@ package org.luxons.sevenwonders.engine.converters import org.luxons.sevenwonders.engine.SimplePlayer -import org.luxons.sevenwonders.engine.boards.Table import org.luxons.sevenwonders.engine.moves.Move -import org.luxons.sevenwonders.model.ApiTable import org.luxons.sevenwonders.model.PlayedMove +import org.luxons.sevenwonders.engine.boards.Table +import org.luxons.sevenwonders.model.GameState -internal fun Table.toApiTable(): ApiTable = ApiTable( +internal fun Table.toGameState(): GameState = GameState( boards = boards.mapIndexed { i, b -> b.toApiBoard(SimplePlayer(i, this), lastPlayedMoves.getOrNull(i)) }, currentAge = currentAge, handRotationDirection = handRotationDirection, diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt index a46cb18d..a923f845 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt @@ -5,7 +5,7 @@ import org.luxons.sevenwonders.actions.PrepareMoveAction import org.luxons.sevenwonders.api.PlayerDTO import org.luxons.sevenwonders.api.toDTO import org.luxons.sevenwonders.engine.Game -import org.luxons.sevenwonders.model.ApiTable +import org.luxons.sevenwonders.model.GameState import org.luxons.sevenwonders.model.cards.CardBack import org.luxons.sevenwonders.lobby.Player import org.luxons.sevenwonders.repositories.PlayerRepository @@ -88,8 +88,8 @@ class GameController @Autowired constructor( } } - private fun sendPlayedMoves(gameId: Long, table: ApiTable) = - template.convertAndSend("/topic/game/$gameId/tableUpdates", table) + private fun sendPlayedMoves(gameId: Long, gameState: GameState) = + template.convertAndSend("/topic/game/$gameId/tableUpdates", gameState) private fun sendPreparedCard(gameId: Long, preparedCard: PreparedCard) = template.convertAndSend("/topic/game/$gameId/prepared", preparedCard) |