feat(ui): add Lobby and Main Menu Body

Added main Menu body and a Lobby with Bootstrap
This commit is contained in:
LQ63
2025-11-04 19:11:19 +01:00
parent 44c88c8f60
commit 89d1626bb2
7 changed files with 154 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ import model.sessions.{PlayerSession, UserSession}
import play.api.*
import play.api.mvc.*
import java.util.UUID
import javax.inject.*
import scala.util.Try
@@ -28,7 +29,7 @@ class IngameController @Inject()(
game match {
case Some(g) =>
g.logic.getCurrentState match {
case Lobby => Ok("Lobby: " + gameId)
case Lobby => Ok(views.html.lobby.lobby(Some(request.user), g))
case InGame =>
Ok(views.html.ingame.ingame(
g.getPlayerByUser(request.user),
@@ -63,7 +64,7 @@ class IngameController @Inject()(
}
}
if (result.isSuccess) {
NoContent
Redirect(routes.IngameController.game(gameId))
} else {
val throwable = result.failed.get
throwable match {
@@ -78,6 +79,16 @@ class IngameController @Inject()(
}
}
}
def kickPlayer(gameId: String, playerToKick: UUID): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val game = podManager.getGame(gameId)
game.get.leaveGame(playerToKick)
Redirect(routes.IngameController.game(gameId))
}
def leaveGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val game = podManager.getGame(gameId)
game.get.leaveGame(request.user.id)
Redirect(routes.MainMenuController.mainMenu())
}
def joinGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val game = podManager.getGame(gameId)
val result = Try {

View File

@@ -21,7 +21,7 @@ class MainMenuController @Inject()(
// Pass the request-handling function directly to authAction (no nested Action)
def mainMenu(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
Ok(views.html.mainmenu.navbar(Some(request.user)))
Ok(views.html.mainmenu.creategame(Some(request.user)))
}
def index(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
@@ -29,12 +29,20 @@ class MainMenuController @Inject()(
}
def createGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>
val gameLobby = podManager.createGame(
host = request.user,
name = s"${request.user.name}'s Game",
maxPlayers = 4
)
Redirect(routes.IngameController.game(gameLobby.id))
val postData = request.body.asFormUrlEncoded
if (postData.isDefined) {
val gamename = postData.get.get("lobbyname").flatMap(_.headOption).getOrElse(s"${request.user.name}'s Game")
val playeramount = postData.get.get("playeramount").flatMap(_.headOption).getOrElse("")
val gameLobby = podManager.createGame(
host = request.user,
name = gamename,
maxPlayers = playeramount.toInt
)
Redirect(routes.IngameController.game(gameLobby.id))
} else {
BadRequest("Invalid form submission")
}
}
def joinGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] =>