feat(base): Fixed logic for websockets and added GameStateEvent. Might've caused instability on other feature branches!

This commit is contained in:
2025-11-26 10:57:51 +01:00
parent 52e5033afc
commit 22cd198ef6
14 changed files with 209 additions and 134 deletions

View File

@@ -16,8 +16,7 @@ import javax.inject.*
@Singleton
class MainMenuController @Inject()(
val controllerComponents: ControllerComponents,
val authAction: AuthAction,
val ingameController: IngameController
val authAction: AuthAction
) extends BaseController {
// Pass the request-handling function directly to authAction (no nested Action)
@@ -46,7 +45,7 @@ class MainMenuController @Inject()(
Ok(Json.obj(
"status" -> "success",
"redirectUrl" -> routes.IngameController.game(gameLobby.id).url,
"content" -> ingameController.returnInnerHTML(gameLobby, request.user).toString
"content" -> IngameController.returnInnerHTML(gameLobby, gameLobby.logic.getCurrentState, request.user).toString
))
} else {
BadRequest(Json.obj(
@@ -67,10 +66,17 @@ class MainMenuController @Inject()(
game match {
case Some(g) =>
g.addUser(request.user)
if (g.getPlayers.size >= 2) {
for (player <- g.getPlayers) {
if (player._2.host) {
g.startGame(player._2.user)
}
}
}
Ok(Json.obj(
"status" -> "success",
"redirectUrl" -> routes.IngameController.game(g.id).url,
"content" -> ingameController.returnInnerHTML(g, request.user).toString
"content" -> IngameController.returnInnerHTML(g, g.logic.getCurrentState, request.user).toString
))
case None =>
NotFound(Json.obj(