feat(ui): Websocket
Started implementing functionality to the Websocket
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user