This file contains hidden or 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 | |
) |
This file contains hidden or 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
@Parcelize | |
object KnightsMoveCount : DatasetVisualisation { | |
override val name = R.string.viz_knight_move_count | |
override val minValue: Int = 2 | |
override val maxValue: Int = 8 | |
override fun dataPointAt(position: Position, state: GameSnapshotState): Datapoint { |
This file contains hidden or 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
override fun dataPointAt(position: Position, state: GameSnapshotState): Datapoint? = | |
valueAt(position, state)?.let { value -> | |
Datapoint( | |
value = value, | |
label = null, | |
colorScale = when (value) { | |
0 -> Color.Red.copy(alpha = 0.35f) to Color.Unspecified | |
else -> Color.Unspecified to Color.Unspecified | |
}, | |
) |
This file contains hidden or 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 hidden or 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
interface SquareDecoration { | |
@Composable | |
fun render(properties: SquareRenderProperties) | |
} | |
interface BoardDecoration { | |
@Composable | |
fun render(properties: BoardRenderProperties) |
This file contains hidden or 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
interface SquareRenderer { | |
val decorations: List<SquareDecoration> | |
} | |
interface BoardRenderer { | |
val decorations: List<BoardDecoration> | |
} |
This file contains hidden or 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 DefaultSquareRenderer : SquareRenderer { | |
override val decorations: List<SquareDecoration> = | |
listOf( | |
DefaultSquareBackground, | |
DefaultHighlightSquare, | |
DefaultSquarePositionLabel, | |
DatasetVisualiser, | |
TargetMarks | |
) |
This file contains hidden or 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 Board( | |
fromState: GameSnapshotState, | |
toState: GameSnapshotState, | |
uiState: UiState, | |
isFlipped: Boolean = false, | |
onClick: (Position) -> Unit, | |
) { | |
BoxWithConstraints( | |
modifier = Modifier |
This file contains hidden or 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 hidden or 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 | |
) | |
} |