feat: BAC-27 Implemented endpoint which returns information about the current state #103
@@ -2,14 +2,12 @@ package controllers
|
||||
|
||||
import auth.{AuthAction, AuthenticatedRequest}
|
||||
import de.knockoutwhist.control.GameState.{FinishedMatch, InGame, Lobby, MainMenu, SelectTrump, TieBreak}
|
||||
import de.knockoutwhist.player.AbstractPlayer
|
||||
import logic.PodManager
|
||||
import logic.game.GameLobby
|
||||
import logic.user.SessionManager
|
||||
import model.users.User
|
||||
import play.api.libs.json.{JsValue, Json}
|
||||
import play.api.mvc.{Action, *}
|
||||
import util.WebUIUtils
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -97,41 +95,13 @@ class StatusController @Inject()(
|
||||
"players" -> gameLobby.getUsers.map(p => Json.obj("id" -> p.id, "name" -> p.name, "isSelf" -> (p.id == user.id)))
|
||||
)
|
||||
case SelectTrump =>
|
||||
val findSelector: Option[AbstractPlayer] = gameLobby.logic.getCurrentMatch match {
|
||||
case Some(matchImpl) =>
|
||||
if (matchImpl.roundlist.isEmpty) None
|
||||
else {
|
||||
matchImpl.roundlist.last.winner match {
|
||||
case Some(winner) => Some(winner)
|
||||
case None => None
|
||||
}
|
||||
}
|
||||
case None => None
|
||||
}
|
||||
|
||||
findSelector match {
|
||||
case Some(selector) =>
|
||||
val isSelf = selector.id == user.id
|
||||
val playerHand = {
|
||||
val userPlayer = gameLobby.getPlayerByUser(user)
|
||||
val handOpt = userPlayer.currentHand()
|
||||
handOpt match {
|
||||
case Some(hand) =>
|
||||
WebUIUtils.handToJson(hand)
|
||||
case None => Json.arr()
|
||||
}
|
||||
}
|
||||
Json.obj(
|
||||
"selector" -> selector.name,
|
||||
"isSelf" -> isSelf,
|
||||
"hand" -> playerHand
|
||||
)
|
||||
case None => Json.obj(
|
||||
"error" -> "No winner found. Please try again later."
|
||||
)
|
||||
}
|
||||
Json.obj(
|
||||
|
||||
)
|
||||
case MainMenu =>
|
||||
Json.obj()
|
||||
Json.obj(
|
||||
|
||||
)
|
||||
case InGame =>
|
||||
Json.obj(
|
||||
|
||||
@@ -143,7 +113,7 @@ class StatusController @Inject()(
|
||||
case FinishedMatch =>
|
||||
Json.obj(
|
||||
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user