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

This commit is contained in:
2025-11-23 17:39:36 +01:00
committed by Janis
parent 11478a096d
commit 5136d14522
9 changed files with 124 additions and 7 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)
)
}
)
}
}