From 880a4fff4232317dd00ab0ee9992a33d459b9862 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Wed, 1 Aug 2018 02:24:40 +0200 Subject: Fix comparisons of ResourceTransactions This commit abstracts away the actual type of collection in the ResourceTransactions typealias. Incidentally, it also changes it to Set, so that tests can compare without concerns about order. This also means that duplicates are not tolerated anymore, and I still haven't decided whether this is good or bad. --- .../src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt | 5 +++-- .../org/luxons/sevenwonders/game/resources/ResourceTransactions.kt | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'game-engine/src/main/kotlin/org') diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt index 95e6b13c..22cc36f0 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/PlayerMove.kt @@ -1,10 +1,11 @@ package org.luxons.sevenwonders.game.api import org.luxons.sevenwonders.game.moves.MoveType -import org.luxons.sevenwonders.game.resources.ResourceTransaction +import org.luxons.sevenwonders.game.resources.ResourceTransactions +import org.luxons.sevenwonders.game.resources.noTransactions data class PlayerMove( val type: MoveType, val cardName: String, - val transactions: Collection = emptyList() + val transactions: ResourceTransactions = noTransactions() ) diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt index c7ab3636..d45d0ce7 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactions.kt @@ -4,10 +4,10 @@ import org.luxons.sevenwonders.game.Player typealias ResourceTransactions = Collection -fun noTransactions(): ResourceTransactions = emptyList() +fun noTransactions(): ResourceTransactions = emptySet() -fun Map.toTransactions() = - filter { (_, res) -> !res.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) } +fun Map.toTransactions(): ResourceTransactions = + filter { (_, res) -> !res.isEmpty() }.map { (p, res) -> ResourceTransaction(p, res) }.toSet() fun ResourceTransactions.asResources(): Resources = map { it.resources }.merge() -- cgit