feat(ui): Implement countless feature using the SJWP (#89)

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #89
This commit is contained in:
2025-11-27 08:53:37 +01:00
parent 2aee79bb68
commit 1f96290371
14 changed files with 289 additions and 48 deletions

View File

@@ -4,7 +4,7 @@ import de.knockoutwhist.events.player.{RequestCardEvent, RequestTieChoiceEvent,
import de.knockoutwhist.utils.events.SimpleEvent
import logic.game.GameLobby
import model.users.User
import play.api.libs.json.JsObject
import play.api.libs.json.{JsObject, JsValue}
import java.util.UUID
import java.util.concurrent.locks.ReentrantLock
@@ -39,14 +39,38 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e
def handleWebResponse(eventType: String, data: JsObject): Unit = {
lock.lock()
Try {
val result = Try {
eventType match {
case "Ping" =>
// No action needed for Ping
()
case "Start Game" =>
gameLobby.startGame(user)
case "play Card" =>
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
}
}
}

View File

@@ -1,5 +1,6 @@
package model.users
import java.util.UUID
case class User(
@@ -16,5 +17,4 @@ case class User(
private def withPasswordHash(newPasswordHash: String): User = {
this.copy(passwordHash = newPasswordHash)
}
}
}