feat(ui): Websocket

Started implementing functionality to the Websocket
This commit is contained in:
LQ63
2025-11-26 18:56:26 +01:00
committed by Janis
parent 6402df43b1
commit 6e76223c4a
12 changed files with 102 additions and 54 deletions

View File

@@ -28,7 +28,7 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
else canInteract = Some(InteractionType.Card)
case _ =>
}
websocketActor.foreach(_.transmitEventToClient(event, gameLobby))
websocketActor.foreach(_.transmitEventToClient(event, gameLobby, user))
}
override def id: UUID = user.id
@@ -41,7 +41,7 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
def handleWebResponse(eventType: String, data: JsObject, user: User, gameLobby: GameLobby): Unit = {
lock.lock()
Try {
val result = Try {
eventType match {
case "Ping" =>
// No action needed for Ping
@@ -49,9 +49,32 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
case "Start Game" =>
println("INSIDE HANDLE WEB RESPONSE" + data)
gameLobby.startGame(user)
case "play Card" =>
println("PLAYING CARD..." + data)
val maybeCardIndex: Option[Int] = (data \ "cardindex").asOpt[Int]
maybeCardIndex match {
case Some(index) =>
val session = gameLobby.getUserSession(user.id)
gameLobby.playCard(session, index)
case None =>
println("Card Index not found or is not a number.")
}
case "Picked Trumpsuit" =>
val maybeSuitIndex: Option[Int] = (data \ "suitIndex").asOpt[Int]
maybeSuitIndex match {
case Some(index) =>
val session = gameLobby.getUserSession(user.id)
gameLobby.selectTrump(session, index)
case None =>
println("Card Index not found or is not a number.")
}
}
}
lock.unlock()
if (result.isFailure) {
val throwable = result.failed.get
throw throwable
}
}
}