From 036fc87fa4759dca994964ede7732ffa9f6dd4a3 Mon Sep 17 00:00:00 2001 From: jbion Date: Mon, 20 May 2019 11:46:01 +0200 Subject: Move some declarations to a better place --- .../kotlin/org/luxons/sevenwonders/game/Game.kt | 2 +- .../org/luxons/sevenwonders/game/api/Boards.kt | 63 ++++++++++++---------- .../org/luxons/sevenwonders/game/api/Table.kt | 2 +- .../game/resources/ResourceTransactions.kt | 5 +- .../org/luxons/sevenwonders/game/test/TestUtils.kt | 4 +- 5 files changed, 42 insertions(+), 34 deletions(-) (limited to 'sw-engine') 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.toColumns(): List> { 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 = - quantities.map { (type, count) -> ApiCountedResource(count, type) }.sortedBy { it.type } +internal fun Resources.toCountedResourcesList(): List = + 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.toTransactions(): ResourceTransactions = @@ -13,9 +12,9 @@ fun ResourceTransactions.asResources(): Resources = flatMap { it.resources }.asR fun ResourceTransaction.asResources(): Resources = resources.asResources() -fun List.asResources(): Resources = map { it.asResources() }.merge() +fun List.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)) -- cgit