feat(game)!: Add winner display and return to lobby functionality

This commit is contained in:
2025-11-19 22:37:48 +01:00
parent 437f8fd466
commit 6b760ccb07
19 changed files with 562 additions and 239 deletions

View File

@@ -17,12 +17,13 @@ import javax.inject.*
class MainMenuController @Inject()(
val controllerComponents: ControllerComponents,
val authAction: AuthAction,
val podManager: PodManager
val podManager: PodManager,
val ingameController: IngameController
) extends BaseController {
// Pass the request-handling function directly to authAction (no nested Action)
def mainMenu(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
Ok(views.html.mainmenu.creategame(Some(request.user)))
Ok(views.html.main("KnockOutWhist")(views.html.mainmenu.creategame(Some(request.user))))
}
def index(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
@@ -45,7 +46,8 @@ class MainMenuController @Inject()(
)
Ok(Json.obj(
"status" -> "success",
"redirectUrl" -> routes.IngameController.game(gameLobby.id).url
"redirectUrl" -> routes.IngameController.game(gameLobby.id).url,
"content" -> ingameController.returnInnerHTML(gameLobby, request.user).toString
))
} else {
BadRequest(Json.obj(
@@ -57,18 +59,31 @@ class MainMenuController @Inject()(
}
def joinGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val postData = request.body.asFormUrlEncoded
if (postData.isDefined) {
val gameId = postData.get.get("gameId").flatMap(_.headOption).getOrElse("")
val game = podManager.getGame(gameId)
val jsonBody = request.body.asJson
val gameId: Option[String] = jsonBody.flatMap { jsValue =>
(jsValue \ "gameId").asOpt[String]
}
if (gameId.isDefined) {
val game = podManager.getGame(gameId.get)
game match {
case Some(g) =>
Redirect(routes.IngameController.joinGame(gameId))
g.addUser(request.user)
Ok(Json.obj(
"status" -> "success",
"redirectUrl" -> routes.IngameController.game(g.id).url,
"content" -> ingameController.returnInnerHTML(g, request.user).toString
))
case None =>
NotFound("Game not found")
NotFound(Json.obj(
"status" -> "failure",
"errorMessage" -> "No Game found"
))
}
} else {
BadRequest("Invalid form submission")
BadRequest(Json.obj(
"status" -> "failure",
"errorMessage" -> "Invalid form submission"
))
}
}