diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-05-20 11:46:01 +0200 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-05-20 11:46:01 +0200 |
commit | 036fc87fa4759dca994964ede7732ffa9f6dd4a3 (patch) | |
tree | 2cbcb27e6abbafa8e9511379b172cf71ade73aec /sw-engine/src/main | |
parent | Fix some tests (diff) | |
download | seven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.tar.gz seven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.tar.bz2 seven-wonders-036fc87fa4759dca994964ede7732ffa9f6dd4a3.zip |
Move some declarations to a better place
Diffstat (limited to 'sw-engine/src/main')
4 files changed, 40 insertions, 32 deletions
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) } |