summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-05-20 11:46:01 +0200
committerjbion <joffrey.bion@amadeus.com>2019-05-20 11:46:01 +0200
commit036fc87fa4759dca994964ede7732ffa9f6dd4a3 (patch)
tree2cbcb27e6abbafa8e9511379b172cf71ade73aec
parentFix some tests (diff)
downloadseven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.tar.gz
seven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.tar.bz2
seven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.zip
Move some declarations to a better place
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/ApiTable.kt (renamed from sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt)5
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt2
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/boards/Boards.kt (renamed from sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt)14
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt2
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Provider.kt8
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt9
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Resources.kt (renamed from sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt)18
-rw-r--r--sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt63
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt2
-rw-r--r--sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt5
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt4
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt4
14 files changed, 73 insertions, 67 deletions
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/ApiTable.kt
index 23ab6ee2..595064b1 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/ApiTable.kt
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.game.api
+import org.luxons.sevenwonders.game.boards.ApiBoard
import org.luxons.sevenwonders.game.cards.HandRotationDirection
import org.luxons.sevenwonders.game.cards.TableCard
import org.luxons.sevenwonders.game.moves.MoveType
@@ -7,8 +8,8 @@ import org.luxons.sevenwonders.game.resources.ResourceTransactions
typealias Age = Int
-data class Table(
- val boards: List<Board>,
+data class ApiTable(
+ val boards: List<ApiBoard>,
val currentAge: Age,
val handRotationDirection: HandRotationDirection,
val lastPlayedMoves: List<PlayedMove>
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt
index c5feb6c5..db177fee 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerTurnInfo.kt
@@ -17,7 +17,7 @@ enum class Action(val message: String) {
data class PlayerTurnInfo(
val playerIndex: Int,
- val table: Table,
+ val table: ApiTable,
val action: Action,
val hand: List<HandCard>,
val preparedMove: PlayedMove?,
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/boards/Boards.kt
index 698615e9..eb044cf2 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/boards/Boards.kt
@@ -1,10 +1,11 @@
-package org.luxons.sevenwonders.game.api
+package org.luxons.sevenwonders.game.boards
import org.luxons.sevenwonders.game.cards.TableCard
+import org.luxons.sevenwonders.game.resources.CountedResource
import org.luxons.sevenwonders.game.resources.ResourceType
import org.luxons.sevenwonders.game.wonders.ApiWonder
-data class Board(
+data class ApiBoard(
val playerIndex: Int,
val wonder: ApiWonder,
val production: ApiProduction,
@@ -17,19 +18,14 @@ data class Board(
data class ApiRequirements(
val gold: Int = 0,
- val resources: List<ApiCountedResource> = emptyList()
+ val resources: List<CountedResource> = emptyList()
)
data class ApiProduction(
- val fixedResources: List<ApiCountedResource>,
+ val fixedResources: List<CountedResource>,
val alternativeResources: Set<Set<ResourceType>>
)
-data class ApiCountedResource(
- val count: Int,
- val type: ResourceType
-)
-
data class ApiMilitary(
val nbShields: Int,
val totalPoints: Int,
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt
index ab0e0297..1fc228d1 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/cards/Cards.kt
@@ -1,6 +1,6 @@
package org.luxons.sevenwonders.game.cards
-import org.luxons.sevenwonders.game.api.ApiRequirements
+import org.luxons.sevenwonders.game.boards.ApiRequirements
import org.luxons.sevenwonders.game.resources.ResourceTransactions
data class TableCard(
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Provider.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Provider.kt
deleted file mode 100644
index 5d0f3159..00000000
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Provider.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.luxons.sevenwonders.game.resources
-
-import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
-
-enum class Provider(val boardPosition: RelativeBoardPosition) {
- LEFT_PLAYER(RelativeBoardPosition.LEFT),
- RIGHT_PLAYER(RelativeBoardPosition.RIGHT)
-}
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
deleted file mode 100644
index 77a8670d..00000000
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.luxons.sevenwonders.game.resources
-
-import org.luxons.sevenwonders.game.api.ApiCountedResource
-
-typealias ResourceTransactions = Collection<ResourceTransaction>
-
-data class ResourceTransaction(val provider: Provider, val resources: List<ApiCountedResource>)
-
-fun noTransactions(): ResourceTransactions = emptySet()
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Resources.kt
index 5c92b887..926cd570 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/resources/Resources.kt
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.game.resources
+import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
+
enum class ResourceType(val symbol: Char) {
WOOD('W'),
STONE('S'),
@@ -24,3 +26,19 @@ enum class ResourceType(val symbol: Char) {
typesPerSymbol[symbol] ?: throw IllegalArgumentException("Unknown resource type symbol '$symbol'")
}
}
+
+data class CountedResource(
+ val count: Int,
+ val type: ResourceType
+)
+
+enum class Provider(val boardPosition: RelativeBoardPosition) {
+ LEFT_PLAYER(RelativeBoardPosition.LEFT),
+ RIGHT_PLAYER(RelativeBoardPosition.RIGHT)
+}
+
+data class ResourceTransaction(val provider: Provider, val resources: List<CountedResource>)
+
+typealias ResourceTransactions = Collection<ResourceTransaction>
+
+fun noTransactions(): ResourceTransactions = emptySet()
diff --git a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt
index 6480e935..13fee8e2 100644
--- a/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt
+++ b/sw-common-model/src/main/kotlin/org/luxons/sevenwonders/game/wonders/Wonder.kt
@@ -1,6 +1,6 @@
package org.luxons.sevenwonders.game.wonders
-import org.luxons.sevenwonders.game.api.ApiRequirements
+import org.luxons.sevenwonders.game.boards.ApiRequirements
import org.luxons.sevenwonders.game.cards.CardBack
import org.luxons.sevenwonders.game.cards.PlayabilityLevel
import org.luxons.sevenwonders.game.resources.ResourceTransactions
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
index 266a57a5..70198f15 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/Game.kt
@@ -18,7 +18,7 @@ import org.luxons.sevenwonders.game.effects.SpecialAbility
import org.luxons.sevenwonders.game.moves.Move
import org.luxons.sevenwonders.game.moves.resolve
import org.luxons.sevenwonders.game.score.ScoreBoard
-import org.luxons.sevenwonders.game.api.Table as ApiTable
+import org.luxons.sevenwonders.game.api.ApiTable as ApiTable
class Game internal constructor(
val id: Long,
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
index 5dff8636..1fe3295a 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Boards.kt
@@ -1,6 +1,11 @@
package org.luxons.sevenwonders.game.api
import org.luxons.sevenwonders.game.Player
+import org.luxons.sevenwonders.game.boards.ApiBoard
+import org.luxons.sevenwonders.game.boards.ApiMilitary
+import org.luxons.sevenwonders.game.boards.ApiProduction
+import org.luxons.sevenwonders.game.boards.ApiRequirements
+import org.luxons.sevenwonders.game.boards.ApiScience
import org.luxons.sevenwonders.game.boards.Military
import org.luxons.sevenwonders.game.boards.Science
import org.luxons.sevenwonders.game.boards.ScienceType
@@ -8,6 +13,7 @@ import org.luxons.sevenwonders.game.cards.Requirements
import org.luxons.sevenwonders.game.cards.TableCard
import org.luxons.sevenwonders.game.moves.Move
import org.luxons.sevenwonders.game.moves.MoveType
+import org.luxons.sevenwonders.game.resources.CountedResource
import org.luxons.sevenwonders.game.resources.Production
import org.luxons.sevenwonders.game.resources.Resources
import org.luxons.sevenwonders.game.wonders.ApiWonder
@@ -16,16 +22,17 @@ import org.luxons.sevenwonders.game.boards.Board as InternalBoard
import org.luxons.sevenwonders.game.wonders.Wonder as InternalWonder
import org.luxons.sevenwonders.game.wonders.WonderStage as InternalWonderStage
-internal fun InternalBoard.toApiBoard(player: Player, lastMove: Move?): Board = Board(
- playerIndex = playerIndex,
- wonder = wonder.toApiWonder(player, lastMove),
- production = production.toApiProduction(),
- publicProduction = publicProduction.toApiProduction(),
- science = science.toApiScience(),
- military = military.toApiMilitary(),
- playedCards = getPlayedCards().map { it.toTableCard(lastMove) }.toColumns(),
- gold = gold
-)
+internal fun InternalBoard.toApiBoard(player: Player, lastMove: Move?): ApiBoard =
+ ApiBoard(
+ playerIndex = playerIndex,
+ wonder = wonder.toApiWonder(player, lastMove),
+ production = production.toApiProduction(),
+ publicProduction = publicProduction.toApiProduction(),
+ science = science.toApiScience(),
+ military = military.toApiMilitary(),
+ playedCards = getPlayedCards().map { it.toTableCard(lastMove) }.toColumns(),
+ gold = gold
+ )
internal fun List<TableCard>.toColumns(): List<List<TableCard>> {
val cardsByColor = this.groupBy { it.color }
@@ -58,24 +65,26 @@ internal fun InternalWonderStage.toApiWonderStage(
builtDuringLastMove = lastMove?.type == MoveType.UPGRADE_WONDER && isLastBuiltStage
)
-internal fun Production.toApiProduction(): ApiProduction = ApiProduction(
- fixedResources = getFixedResources().toCountedResourcesList(),
- alternativeResources = getAlternativeResources()
-)
+internal fun Production.toApiProduction(): ApiProduction =
+ ApiProduction(
+ fixedResources = getFixedResources().toCountedResourcesList(), alternativeResources = getAlternativeResources()
+ )
-internal fun Requirements.toApiRequirements(): ApiRequirements = ApiRequirements(
- gold = gold,
- resources = resources.toCountedResourcesList()
-)
+internal fun Requirements.toApiRequirements(): ApiRequirements =
+ ApiRequirements(
+ gold = gold, resources = resources.toCountedResourcesList()
+ )
-internal fun Resources.toCountedResourcesList(): List<ApiCountedResource> =
- quantities.map { (type, count) -> ApiCountedResource(count, type) }.sortedBy { it.type }
+internal fun Resources.toCountedResourcesList(): List<CountedResource> =
+ quantities.map { (type, count) -> CountedResource(count, type) }.sortedBy { it.type }
-internal fun Military.toApiMilitary(): ApiMilitary = ApiMilitary(nbShields, totalPoints, nbDefeatTokens)
+internal fun Military.toApiMilitary(): ApiMilitary =
+ ApiMilitary(nbShields, totalPoints, nbDefeatTokens)
-internal fun Science.toApiScience(): ApiScience = ApiScience(
- jokers = jokers,
- nbWheels = getQuantity(ScienceType.WHEEL),
- nbCompasses = getQuantity(ScienceType.COMPASS),
- nbTablets = getQuantity(ScienceType.TABLET)
-)
+internal fun Science.toApiScience(): ApiScience =
+ ApiScience(
+ jokers = jokers,
+ nbWheels = getQuantity(ScienceType.WHEEL),
+ nbCompasses = getQuantity(ScienceType.COMPASS),
+ nbTablets = getQuantity(ScienceType.TABLET)
+ )
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt
index de6e587d..a5f95456 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt
@@ -4,7 +4,7 @@ import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.moves.Move
import org.luxons.sevenwonders.game.boards.Table as InternalTable
-internal fun InternalTable.toApiTable(): Table = Table(
+internal fun InternalTable.toApiTable(): ApiTable = ApiTable(
boards = boards.mapIndexed { i, b -> b.toApiBoard(SimplePlayer(i, this), lastPlayedMoves.getOrNull(i)) },
currentAge = currentAge,
handRotationDirection = handRotationDirection,
diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
index 4a3a483c..134240a5 100644
--- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
+++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt
@@ -1,7 +1,6 @@
package org.luxons.sevenwonders.game.resources
import org.luxons.sevenwonders.game.Player
-import org.luxons.sevenwonders.game.api.ApiCountedResource
import org.luxons.sevenwonders.game.api.toCountedResourcesList
fun Map<Provider, Resources>.toTransactions(): ResourceTransactions =
@@ -13,9 +12,9 @@ fun ResourceTransactions.asResources(): Resources = flatMap { it.resources }.asR
fun ResourceTransaction.asResources(): Resources = resources.asResources()
-fun List<ApiCountedResource>.asResources(): Resources = map { it.asResources() }.merge()
+fun List<CountedResource>.asResources(): Resources = map { it.asResources() }.merge()
-fun ApiCountedResource.asResources(): Resources = resourcesOf(type to count)
+fun CountedResource.asResources(): Resources = resourcesOf(type to count)
internal fun ResourceTransactions.execute(player: Player) = forEach { it.execute(player) }
diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
index 0e6eb2b7..07e22a56 100644
--- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
+++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
@@ -3,7 +3,7 @@ package org.luxons.sevenwonders.game.test
import org.luxons.sevenwonders.game.Player
import org.luxons.sevenwonders.game.PlayerContext
import org.luxons.sevenwonders.game.Settings
-import org.luxons.sevenwonders.game.api.ApiCountedResource
+import org.luxons.sevenwonders.game.resources.CountedResource
import org.luxons.sevenwonders.game.api.CustomizableSettings
import org.luxons.sevenwonders.game.api.PlayerMove
import org.luxons.sevenwonders.game.boards.Board
@@ -75,7 +75,7 @@ internal fun createTransactions(provider: Provider, vararg resources: ResourceTy
internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions = transactions.toSet()
internal fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction =
- ResourceTransaction(provider, resources.map { ApiCountedResource(1, it) })
+ ResourceTransaction(provider, resources.map { CountedResource(1, it) })
internal fun createRequirements(vararg types: ResourceType): Requirements = Requirements(resources = resourcesOf(*types))
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 b37c9c7c..cd9cb732 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.game.Game
-import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.api.ApiTable
import org.luxons.sevenwonders.game.cards.CardBack
import org.luxons.sevenwonders.lobby.Player
import org.luxons.sevenwonders.repositories.PlayerRepository
@@ -88,7 +88,7 @@ class GameController @Autowired constructor(
}
}
- private fun sendPlayedMoves(gameId: Long, table: Table) =
+ private fun sendPlayedMoves(gameId: Long, table: ApiTable) =
template.convertAndSend("/topic/game/$gameId/tableUpdates", table)
private fun sendPreparedCard(gameId: Long, preparedCard: PreparedCard) =
bgstack15