This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal object CardsOnScreenResolver : OnScreenStateResolver<State> { | |
override fun isOnScreen(state: State): Boolean = | |
when (state) { | |
is State.Bottom, | |
is State.Top -> true | |
is State.Queued, | |
is State.VoteLike, | |
is State.VotePass -> false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class State { | |
// Prepared but not displayed yet | |
data class Queued(val queueNumber: Int) : State() | |
// Visible below top card | |
object Bottom : State() | |
// The main card | |
object Top : State() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cards<T : Any>( | |
initialItems: List<T> = listOf(), | |
) : BaseNavModel<T, State>( | |
screenResolver = CardsOnScreenResolver, // <- What's on screen? | |
finalStates = setOf(VoteLike, VotePass), // <- What's destroyed? | |
savedStateMap = null | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun State.next(): State = | |
when (this) { | |
is Queued -> if (queueNumber == 0) Bottom else Queued(queueNumber - 1) | |
is Bottom -> Top | |
else -> this | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun Game() { | |
Column { | |
Moves() | |
CapturedPieces(WHITE) | |
Board() | |
CapturedPieces(BLACK) | |
Controls() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class SquareRenderProperties( | |
val position: Position, | |
val isHighlighted: Boolean, | |
val clickable: Boolean, | |
val onClick: () -> Unit, | |
val isPossibleMoveWithoutCapture: Boolean, | |
val isPossibleCapture: Boolean, | |
val boardProperties: BoardRenderProperties | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val fromPosition = properties.fromState.board.find(piece)?.position | |
val currentOffset = fromPosition | |
?.toCoordinate(properties.isFlipped) | |
?.toOffset(properties.squareSize) | |
val targetOffset = toPosition | |
.toCoordinate(properties.isFlipped) | |
.toOffset(properties.squareSize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val datapoint = remember(viz, properties) { | |
viz.dataPointAt( | |
properties.position, | |
properties.boardProperties.toState | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
override fun render(properties: SquareRenderProperties) { | |
ActiveDatasetVisualisation.current.let { viz -> | |
val datapoint = viz.dataPointAt( | |
properties.position, | |
properties.boardProperties.toState | |
) | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object DatasetVisualiser : SquareDecoration { | |
@Composable | |
override fun render(properties: SquareRenderProperties) { | |
ActiveDatasetVisualisation.current.let { viz -> | |
val datapoint = viz.dataPointAt( | |
properties.position, | |
properties.boardProperties.toState | |
) |