other players styling and cards calc logic

This commit is contained in:
efim 2023-04-28 21:20:09 +04:00
parent 76303ba097
commit 340fcdcf41
2 changed files with 18 additions and 6 deletions

View File

@ -9,11 +9,23 @@ object OtherPlayers {
val otherPlayers = roomStateSignal.map { state =>
state.players.filterNot(_.id == state.me).zipWithIndex
}
def playerCardsAmountSignal(id: PlayerID): Signal[Int] = {
roomStateSignal.map(state => {
val totalCards = state.allowedCards.size
val playerModification = state.round match {
case RoundStateView.Viewing(votes) if votes.toMap.contains(id) => -1
case RoundStateView.Voting(_, votedPlayers) if votedPlayers.contains(id) => -1
case _ => 0
}
totalCards + playerModification
})
}
div(
className := "flex flex-row",
children <-- otherPlayers.split(_._1.id) { (id, initial, playerSignal) =>
renderPlayer(playerSignal, roomStateSignal.map(_.allowedCards.size))
children <-- otherPlayers.split(_._1.id) { (playerID, initial, playerSignal) =>
renderPlayer(playerSignal, playerCardsAmountSignal(playerID))
}
)
}
@ -21,7 +33,7 @@ object OtherPlayers {
def renderPlayer(p: Signal[(Player, Int)], cardsAmount: Signal[Int]): Element = {
val xOffsetStyleSignal = p.map(_._2)
div(
className := "w-20 h-20 border-2 border-amber-400 m-2 absolute",
className := "bg-green-200 border-b-2 border-black rounded p-2 m-2 absolute drop-shadow-xl",
// left <-- p.map(tuple => ((1 + tuple._2) * 10000).toString()),
styleAttr <-- p.map(tuple => s"left: ${(1 + tuple._2) * 100}px"),
child.text <-- p.map(_._1.name),
@ -32,7 +44,7 @@ object OtherPlayers {
def renderHandCardBacks(amountSignal: Signal[Int]): Element = {
def renderCard(index: Int): Element =
div(
className := "w-4 h-8 m-1 rounded bg-gray-600 text-yellow"
className := "w-8 h-12 rounded bg-green-500 text-yellow m-1 border border-green-700 drop-shadow-md"
)
div(

View File

@ -19,9 +19,9 @@ object TableView {
)
div(
className := "w-full h-full border-2 border-amber-700 flex flex-col justify-center items-center bg-green-100",
className := "w-full h-full flex flex-col justify-center items-center bg-green-100",
div(
className := "w-full border-2 border-amber-600 flex flex-row justify-center items-center bg-green-100",
className := "w-full flex flex-row justify-center items-center bg-green-100",
children <-- playerIdToCardTypeSignal.split(_._1) { (id, initial, cardTypeSignal) =>
renderPlayerCard(cardTypeSignal.map(_._2))
}