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
| 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
| @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
| 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
| interface DatasetVisualisation : Parcelable { | |
| // String resource | |
| val name: Int | |
| // Global minimum value | |
| val minValue: Int | |
| // Global maximum value | |
| val maxValue: Int | |
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 offset = remember { Animatable(currentOffset ?: targetOffset, Offset.VectorConverter) } | |
| LaunchedEffect(targetOffset) { | |
| offset.animateTo(targetOffset, tween(100, easing = LinearEasing)) | |
| } | |
| LaunchedEffect(isFlipped) { | |
| offset.snapTo(targetOffset) | |
| } |
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 offset = remember { Animatable(currentOffset ?: targetOffset, Offset.VectorConverter) } | |
| LaunchedEffect(targetOffset) { | |
| offset.animateTo(targetOffset, tween(100, easing = LinearEasing)) | |
| } | |
| Piece( | |
| piece = piece, | |
| modifier = offset.value.toModifier() | |
| ) |
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 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 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
| BoxWithConstraints( | |
| modifier = Modifier | |
| .fillMaxWidth() | |
| .aspectRatio(1f) | |
| ) { | |
| val squareSize = maxWidth / 8 | |
| } |
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
| private fun Modifier.pill(): Modifier = | |
| this.background( | |
| color = someColour, | |
| shape = RoundedCornerShape(6.dp) | |
| ) |