feat(api): Implement received hand event handling and UI updates (#83)
#76 Reviewed-on: #83
This commit is contained in:
@@ -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)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user