|
|
|
|
@ -116,6 +116,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
override var year: Int? = null |
|
|
|
|
override var dayOfMonth: Int? = null |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Configures a hand history with a [handSetup] |
|
|
|
|
*/ |
|
|
|
|
fun configure(handSetup: HandSetup) { |
|
|
|
|
|
|
|
|
|
handSetup.tableSize?.let { this.numberOfPlayers = it } |
|
|
|
|
@ -125,6 +128,10 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
this.createActions(handSetup.straddlePositions) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Creates the initial actions of the hand history using the number of players, |
|
|
|
|
* and the optional [straddlePositions] |
|
|
|
|
*/ |
|
|
|
|
private fun createActions(straddlePositions: List<Position>) { |
|
|
|
|
|
|
|
|
|
this.actions.clear() |
|
|
|
|
@ -150,6 +157,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Adds an action with the given [position], [type] and [amount] to the actions list |
|
|
|
|
*/ |
|
|
|
|
private fun addAction(position: Int, type: Action.Type? = null, amount: Double? = null) { |
|
|
|
|
val action = Action() |
|
|
|
|
action.index = this.actions.size |
|
|
|
|
@ -159,10 +169,16 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
this.actions.add(action) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the board cards for a given [street] |
|
|
|
|
*/ |
|
|
|
|
fun cardsForStreet(street: Street): MutableList<Card> { |
|
|
|
|
return this.board.sortedBy { it.index }.take(street.totalBoardCards).toMutableList() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the optional PlayerSetup object at the [position] |
|
|
|
|
*/ |
|
|
|
|
fun playerSetupForPosition(position: Int): PlayerSetup? { |
|
|
|
|
return this.playerSetups.firstOrNull { it.position == position } |
|
|
|
|
} |
|
|
|
|
@ -170,6 +186,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
override val cards: RealmList<Card> |
|
|
|
|
get() { return this.board } |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the ante sum |
|
|
|
|
*/ |
|
|
|
|
val anteSum: Double |
|
|
|
|
get() { |
|
|
|
|
return if (bigBlindAnte) { |
|
|
|
|
@ -179,11 +198,18 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the sorted list of actions by index |
|
|
|
|
*/ |
|
|
|
|
private val sortedActions: List<Action> |
|
|
|
|
get() { |
|
|
|
|
return this.actions.sortedBy { it.index } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns the list of undefined positions, |
|
|
|
|
* meaning the positions where no PlayerSetup has been created |
|
|
|
|
*/ |
|
|
|
|
fun undefinedPositions(): List<Position> { |
|
|
|
|
val positions = Position.positionsPerPlayers(this.numberOfPlayers) |
|
|
|
|
val copy = positions.clone() as LinkedHashSet<Position> |
|
|
|
|
@ -193,6 +219,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
return copy.toList() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Creates and affect a PlayerSetup at the given [positionIndex] |
|
|
|
|
*/ |
|
|
|
|
fun createPlayerSetup(positionIndex: Int): PlayerSetup { |
|
|
|
|
|
|
|
|
|
val playerSetup = if (this.realm != null) { |
|
|
|
|
@ -283,6 +312,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
return string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns a string representation of the [playerSetup] |
|
|
|
|
*/ |
|
|
|
|
private fun localizedPlayerSetup(playerSetup: PlayerSetup, positions: LinkedHashSet<Position>, context: Context): String { |
|
|
|
|
val playerItems = mutableListOf(positions.elementAt(playerSetup.position).value) |
|
|
|
|
playerItems.add("[${playerSetup.cards.formatted(context)}]") |
|
|
|
|
@ -292,6 +324,9 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
|
return playerItems.joinToString(" ") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns a string representation of the [actionReadRow] |
|
|
|
|
*/ |
|
|
|
|
private fun localizedAction(actionReadRow: ActionReadRow, context: Context): String { |
|
|
|
|
val formattedPositions = actionReadRow.positions.map { it.value }.joinToString(", ") |
|
|
|
|
val actionItems = mutableListOf(formattedPositions) |
|
|
|
|
|