|
|
|
|
@ -27,6 +27,10 @@ enum class HHKeyboard { |
|
|
|
|
|
|
|
|
|
class HHSelection(var index: Int, var tag: Int) |
|
|
|
|
|
|
|
|
|
interface PlayerSetupCreationListener { |
|
|
|
|
fun playerSetupCreated() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer, ActionListListener { |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
@ -197,11 +201,14 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
addStreetHeader(rows, street) |
|
|
|
|
|
|
|
|
|
val positions = this.sortedActions.activePositions(lastActionIndex, true) |
|
|
|
|
positions.forEach { |
|
|
|
|
val positionIndex = this.sortedActions.positions.indexOf(it) |
|
|
|
|
val playerCardsRow = PlayerCardsRow(it, positionIndex, this.handHistory, |
|
|
|
|
this.handHistory.playerSetupForPosition(positionIndex), this.playerHandMaxCards) |
|
|
|
|
// val playerCardsRow = PlayerCardsRow.newInstance(it, this.handHistory, positionIndex, this.playerHandMaxCards) |
|
|
|
|
positions.forEach { position -> |
|
|
|
|
val positionIndex = this.sortedActions.positions.indexOf(position) |
|
|
|
|
val playerCardsRow = PlayerCardsRow(this, |
|
|
|
|
position, |
|
|
|
|
positionIndex, |
|
|
|
|
this.handHistory, |
|
|
|
|
this.handHistory.playerSetupForPosition(positionIndex), |
|
|
|
|
this.playerHandMaxCards) |
|
|
|
|
rows.add(playerCardsRow) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -272,7 +279,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Returns a list of positions that needs to act |
|
|
|
|
* Returns a list of positions that needs to act after the current selected index |
|
|
|
|
*/ |
|
|
|
|
fun positionsToAct(): List<Position> { |
|
|
|
|
return this.sortedActions.positionsToActAfterIndex(this.actionIndexForSelection) |
|
|
|
|
@ -436,16 +443,16 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
/*** |
|
|
|
|
* Called when the board has changed |
|
|
|
|
*/ |
|
|
|
|
fun boardChanged(cards: List<Card>) { |
|
|
|
|
this.rowRepresentables.filterIsInstance<StreetCardsRow>().forEach { |
|
|
|
|
// it.cards = cards |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// fun boardChanged(cards: List<Card>) { |
|
|
|
|
// this.rowRepresentables.filterIsInstance<StreetCardsRow>().forEach { |
|
|
|
|
// // it.cards = cards |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Saves the current hand state in the database |
|
|
|
|
*/ |
|
|
|
|
private fun save() { |
|
|
|
|
fun save() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -493,6 +500,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
this.createRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun playerSetupCreated() { |
|
|
|
|
this.createRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun amountChanged(amount: String?) { |
|
|
|
|
this.currentAmount = amount |
|
|
|
|
} |
|
|
|
|
@ -561,6 +572,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
is StreetCardsRow -> row.cardsForTag(tag)?.formatted(context) |
|
|
|
|
is PlayerSetupRow -> { |
|
|
|
|
when (tag) { |
|
|
|
|
PlayerSetupRow.Tag.POSITION.ordinal -> row.position?.value |
|
|
|
|
PlayerSetupRow.Tag.CARDS.ordinal -> row.cardHolder?.cards?.formatted(context) |
|
|
|
|
PlayerSetupRow.Tag.STACK.ordinal -> row.playerSetup?.stack?.formatted() |
|
|
|
|
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") |
|
|
|
|
@ -612,7 +624,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
val hh = this.handHistory |
|
|
|
|
|
|
|
|
|
val arrangedSetups = hh.playerSetups.sortedBy { it.position }.map { |
|
|
|
|
createPlayerSetupRow(false, it) |
|
|
|
|
val position = this.positionForIndex(it.position) |
|
|
|
|
createPlayerSetupRow(false, position, it) |
|
|
|
|
}.toMutableList() |
|
|
|
|
|
|
|
|
|
val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex } |
|
|
|
|
@ -621,7 +634,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
arrangedSetups.remove(it) |
|
|
|
|
arrangedSetups.add(0, it) |
|
|
|
|
} ?: run { |
|
|
|
|
arrangedSetups.add(createPlayerSetupRow(true)) |
|
|
|
|
arrangedSetups.add(0, createPlayerSetupRow(true)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (arrangedSetups.size < hh.numberOfPlayers) { |
|
|
|
|
@ -629,42 +642,48 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return arrangedSetups |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Convenience method to create a PlayerSetupRow |
|
|
|
|
*/ |
|
|
|
|
private fun createPlayerSetupRow(hero: Boolean, playerSetup: PlayerSetup? = null): PlayerSetupRow { |
|
|
|
|
return PlayerSetupRow(hero, null, null, this.handHistory, playerSetup, this.playerHandMaxCards) |
|
|
|
|
private fun createPlayerSetupRow(hero: Boolean, position: Position? = null, playerSetup: PlayerSetup? = null): PlayerSetupRow { |
|
|
|
|
return PlayerSetupRow(hero, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Sets the both [positionIndex] and position for a PlayerSetup inside a [psRowRepresentable] |
|
|
|
|
* Sets the both [positionIndex] and position for a PlayerSetup inside a [playerSetupRow] |
|
|
|
|
*/ |
|
|
|
|
fun setPlayerSetupPosition(psRowRepresentable: PlayerSetupRow, positionIndex: Int) { |
|
|
|
|
fun setPlayerSetupPosition(playerSetupRow: PlayerSetupRow, positionIndex: Int) { |
|
|
|
|
|
|
|
|
|
var setupCreated = false |
|
|
|
|
psRowRepresentable.playerSetup?.let { setup -> |
|
|
|
|
setup.position = positionIndex |
|
|
|
|
playerSetupRow.playerSetup?.let { playerSetup -> |
|
|
|
|
playerSetup.position = positionIndex |
|
|
|
|
} ?: run { |
|
|
|
|
psRowRepresentable.playerSetup = this.handHistory.createPlayerSetup(positionIndex) |
|
|
|
|
playerSetupRow.playerSetup = this.handHistory.createPlayerSetup(positionIndex) |
|
|
|
|
setupCreated = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val position = this.sortedActions.positions.elementAt(positionIndex) |
|
|
|
|
psRowRepresentable.position = position |
|
|
|
|
val position = this.positionForIndex(positionIndex) |
|
|
|
|
playerSetupRow.position = position |
|
|
|
|
|
|
|
|
|
if (!psRowRepresentable.hero && setupCreated) { |
|
|
|
|
if (!playerSetupRow.hero && setupCreated) { |
|
|
|
|
|
|
|
|
|
if (this.handHistory.undefinedPositions().isNotEmpty()) { |
|
|
|
|
val newPlayerRow = createPlayerSetupRow(false) |
|
|
|
|
val index = this.indexOfRowRepresentable(psRowRepresentable) |
|
|
|
|
val index = this.indexOfRowRepresentable(playerSetupRow) |
|
|
|
|
this.rowsLiveData.value?.add(index + 1, newPlayerRow) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (playerSetupRow.hero) { |
|
|
|
|
this.handHistory.heroIndex = positionIndex |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun positionForIndex(positionIndex: Int): Position { |
|
|
|
|
return this.sortedActions.positions.elementAt(positionIndex) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |