io.elderscrollslegends.CardGrouping.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elderscrolls-legends-sdk-java Show documentation
Show all versions of elderscrolls-legends-sdk-java Show documentation
A java wrapper around the Elder Scrolls: Legends API of https://elderscrollslegends.io
package io.elderscrollslegends
open class CardGrouping(val cards: List) {
// A map of count to list of cards with that count in the deck, e.g. {1: [Adoring Fan, Aela the Huntress], 2: [Aldmeri Patriot]}
private val countToCardListMap = cards
.groupBy { it.id } // Map>
.map { it.value.size to it.value.first() } // List>
.groupBy { it.first } // Map>>
.map { it.key to it.value.map { p -> p.second }.sortedBy { card -> card.name } } // List>
.toMap() // Map>
// A map of cardId to DeckCard
private val deckCardMap = cards
.groupBy { it.id }
.map { it.value.first().id to CardCount(card = it.value.first(), count = it.value.size) }
.toMap()
fun of(count: Int) = countToCardListMap.getOrDefault(count, emptyList())
fun byId(cardId: String): CardCount {
return deckCardMap.getOrDefault(cardId, CardCount())
}
}
data class CardCount(
val card: Card? = null,
val count: Int = 0
)