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 Game() { | |
Column { | |
Moves() | |
CapturedPieces(WHITE) | |
Board() | |
CapturedPieces(BLACK) | |
Controls() | |
} | |
} |
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
import androidx.compose.ui.graphics.Color | |
// reds | |
val md_red_50 = Color(0xFFFFEBEE) | |
val md_red_100 = Color(0xFFFFCDD2) | |
val md_red_200 = Color(0xFFEF9A9A) | |
val md_red_300 = Color(0xFFE57373) | |
val md_red_400 = Color(0xFFEF5350) | |
val md_red_500 = Color(0xFFF44336) | |
val md_red_600 = Color(0xFFE53935) |
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
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 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
fun State.next(): State = | |
when (this) { | |
is Queued -> if (queueNumber == 0) Bottom else Queued(queueNumber - 1) | |
is Bottom -> Top | |
else -> this | |
} |
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
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 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
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 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
class VoteLike<T : Any> internal constructor() : CardsOperation<T> { | |
// Returns a modified list of elements with new target states applied | |
override fun invoke(elements: CardsElements<T>): CardsElements<T> = | |
elements.map { element -> | |
if (element.targetState == Cards.State.Top) { | |
element.transitionTo( | |
newTargetState = Cards.State.VoteLike, | |
operation = this | |
) |
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
internal class PromoteAll<T : Any> : CardsOperation<T> { | |
override fun invoke(elements: CardsElements<T>): CardsElements<T> = | |
elements.map { | |
it.transitionTo( | |
// This uses State.next() we defined earlier: | |
newTargetState = it.targetState.next(), | |
operation = this | |
) | |
} |
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 Props( | |
val offsetX: Dp = 0.dp, | |
val scale: Float = 1f, | |
val rotationZ: Float = 0f, | |
val zIndex: Float = 0f, | |
) |
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
// Scaled down to 0% (not visible) | |
private val queued = Props( | |
scale = 0f, | |
) | |
// Scaled down to 85% | |
private val bottom = Props( | |
scale = 0.85f, | |
) |