feat(api): Implement received hand event handling and UI updates (#83)

#76

Reviewed-on: #83
This commit is contained in:
2025-11-24 14:31:31 +01:00
parent 10a26404b3
commit 52e5033afc
10 changed files with 143 additions and 14 deletions

View File

@@ -1,8 +1,9 @@
package util
import de.knockoutwhist.cards.Card
import de.knockoutwhist.cards.{Card, Hand}
import de.knockoutwhist.cards.CardValue.*
import de.knockoutwhist.cards.Suit.{Clubs, Diamonds, Hearts, Spades}
import play.api.libs.json.{JsArray, Json}
import play.twirl.api.Html
import scalafx.scene.image.Image
@@ -36,4 +37,22 @@ object WebUIUtils {
f"$cv$s"
}
/**
* Map a Hand to a JsArray of cards
* Per card it has the string and the index in the hand
* @param hand
* @return
*/
def handToJson(hand: Hand): JsArray = {
val cards = hand.cards
JsArray(
cards.zipWithIndex.map { case (card, index) =>
Json.obj(
"idx" -> index,
"card" -> cardtoString(card)
)
}
)
}
}