From 6e17328846745375482c97383b143d86a86e7f32 Mon Sep 17 00:00:00 2001 From: Janis Date: Mon, 1 Dec 2025 19:13:32 +0100 Subject: [PATCH] feat: GameState to Title Mapping BAC-1 (#92) Reviewed-on: https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/pulls/92 Co-authored-by: Janis Co-committed-by: Janis --- knockoutwhist | 2 +- .../app/controllers/IngameController.scala | 3 ++- knockoutwhistweb/app/util/GameUtil.scala | 14 ++++++++++++++ .../app/util/mapper/GameStateEventMapper.scala | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/knockoutwhist b/knockoutwhist index d833932..ef7397f 160000 --- a/knockoutwhist +++ b/knockoutwhist @@ -1 +1 @@ -Subproject commit d833932f1652554db5a49d77033d3016051d23f9 +Subproject commit ef7397f7f1312e0d87ab7ccaab94159d7f7e9773 diff --git a/knockoutwhistweb/app/controllers/IngameController.scala b/knockoutwhistweb/app/controllers/IngameController.scala index 9c92bcc..8752f22 100644 --- a/knockoutwhistweb/app/controllers/IngameController.scala +++ b/knockoutwhistweb/app/controllers/IngameController.scala @@ -12,6 +12,7 @@ import play.api.* import play.api.libs.json.{JsValue, Json} import play.api.mvc.* import play.twirl.api.Html +import util.GameUtil import java.util.UUID import javax.inject.* @@ -33,7 +34,7 @@ class IngameController @Inject()( IngameController.returnInnerHTML(g, g.logic.getCurrentState, request.user) } if (results.isSuccess) { - Ok(views.html.main("In-Game - Knockout Whist")(results.get)) + Ok(views.html.main("Knockout Whist - " + GameUtil.stateToTitle(g.logic.getCurrentState))(results.get)) } else { InternalServerError(results.failed.get.getMessage) } diff --git a/knockoutwhistweb/app/util/GameUtil.scala b/knockoutwhistweb/app/util/GameUtil.scala index a250603..796e8be 100644 --- a/knockoutwhistweb/app/util/GameUtil.scala +++ b/knockoutwhistweb/app/util/GameUtil.scala @@ -1,5 +1,8 @@ package util +import de.knockoutwhist.control.GameState +import de.knockoutwhist.control.GameState.{FinishedMatch, InGame, Lobby, MainMenu, SelectTrump, TieBreak} + import scala.util.Random object GameUtil { @@ -25,5 +28,16 @@ object GameUtil { code.toString() } + + def stateToTitle(gameState: GameState): String = { + gameState match { + case Lobby => "Lobby" + case MainMenu => "Main Menu" + case InGame => "In Game" + case SelectTrump => "Select Trump" + case TieBreak => "Tie Break" + case FinishedMatch => "Finished Match" + } + } } diff --git a/knockoutwhistweb/app/util/mapper/GameStateEventMapper.scala b/knockoutwhistweb/app/util/mapper/GameStateEventMapper.scala index 3c4c0dc..d085fa2 100644 --- a/knockoutwhistweb/app/util/mapper/GameStateEventMapper.scala +++ b/knockoutwhistweb/app/util/mapper/GameStateEventMapper.scala @@ -4,6 +4,7 @@ import controllers.IngameController import de.knockoutwhist.events.global.GameStateChangeEvent import model.sessions.UserSession import play.api.libs.json.{JsObject, Json} +import util.GameUtil object GameStateEventMapper extends SimpleEventMapper[GameStateChangeEvent] { @@ -11,7 +12,7 @@ object GameStateEventMapper extends SimpleEventMapper[GameStateChangeEvent] { override def toJson(event: GameStateChangeEvent, session: UserSession): JsObject = { Json.obj( - //Title + "title" -> ("Knockout Whist - " + GameUtil.stateToTitle(event.newState)), "content" -> IngameController.returnInnerHTML(session.gameLobby, event.newState, session.user).toString ) }