fix: FRO-29 Websocket Communication (#104)
Reviewed-on: #104 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
@@ -4,7 +4,7 @@ import dto.subDTO.UserDTO
|
||||
import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
case class LobbyInfoDTO(users: List[UserDTO], self: UserDTO, maxPlayers: Int)
|
||||
case class LobbyInfoDTO(gameId: String, users: List[UserDTO], self: UserDTO, maxPlayers: Int)
|
||||
|
||||
object LobbyInfoDTO {
|
||||
|
||||
@@ -12,6 +12,7 @@ object LobbyInfoDTO {
|
||||
val session = lobby.getUserSession(user.id)
|
||||
|
||||
LobbyInfoDTO(
|
||||
gameId = lobby.id,
|
||||
users = lobby.getPlayers.values.map(user => UserDTO(user)).toList,
|
||||
self = UserDTO(session),
|
||||
maxPlayers = lobby.maxPlayers,
|
||||
|
||||
@@ -6,7 +6,7 @@ import model.users.User
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
case class TieInfoDTO(currentPlayer: Option[PlayerDTO], self: Option[PlayerDTO], tiedPlayers: Seq[PlayerDTO], highestAmount: Int)
|
||||
case class TieInfoDTO(gameId: String, currentPlayer: Option[PlayerDTO], self: Option[PlayerDTO], tiedPlayers: Seq[PlayerDTO], highestAmount: Int)
|
||||
|
||||
object TieInfoDTO {
|
||||
|
||||
@@ -16,6 +16,7 @@ object TieInfoDTO {
|
||||
}.getOrElse(None)
|
||||
|
||||
TieInfoDTO(
|
||||
gameId = lobby.id,
|
||||
currentPlayer = lobby.logic.playerTieLogic.currentTiePlayer().map(PlayerDTO.apply),
|
||||
self = selfPlayer.map(PlayerDTO.apply),
|
||||
tiedPlayers = lobby.logic.playerTieLogic.getTiedPlayers.map(PlayerDTO.apply),
|
||||
|
||||
@@ -7,6 +7,7 @@ import model.users.User
|
||||
import scala.util.Try
|
||||
|
||||
case class TrumpInfoDTO(
|
||||
gameId: String,
|
||||
chooser: Option[PlayerDTO],
|
||||
self: Option[PlayerDTO],
|
||||
selfHand: Option[HandDTO],
|
||||
@@ -20,6 +21,7 @@ object TrumpInfoDTO {
|
||||
}.getOrElse(None)
|
||||
|
||||
TrumpInfoDTO(
|
||||
gameId = lobby.id,
|
||||
chooser = lobby.logic.getTrumpPlayer.map(PlayerDTO(_)),
|
||||
self = selfPlayer.map(PlayerDTO(_)),
|
||||
selfHand = selfPlayer.flatMap(_.currentHand()).map(HandDTO(_))
|
||||
|
||||
@@ -5,6 +5,7 @@ import logic.game.GameLobby
|
||||
import model.users.User
|
||||
|
||||
case class WonInfoDTO(
|
||||
gameId: String,
|
||||
winner: Option[PodiumPlayerDTO],
|
||||
allPlayers: Seq[PodiumPlayerDTO]
|
||||
)
|
||||
@@ -24,6 +25,7 @@ object WonInfoDTO {
|
||||
val winnerDTO = lobby.logic.getWinner
|
||||
|
||||
WonInfoDTO(
|
||||
gameId = lobby.id,
|
||||
winner = winnerDTO.map(player => PodiumPlayerDTO(lobby.logic, player)),
|
||||
allPlayers = allPlayersDTO
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package dto.subDTO
|
||||
import de.knockoutwhist.cards.Card
|
||||
import util.WebUIUtils
|
||||
|
||||
case class CardDTO(identifier: String, path: String, idx: Int) {
|
||||
case class CardDTO(identifier: String, path: String, idx: Option[Int]) {
|
||||
|
||||
def toCard: Card = {
|
||||
WebUIUtils.stringToCard(identifier)
|
||||
@@ -13,11 +13,19 @@ case class CardDTO(identifier: String, path: String, idx: Int) {
|
||||
|
||||
object CardDTO {
|
||||
|
||||
def apply(card: Card, index: Int = 0): CardDTO = {
|
||||
def apply(card: Card, index: Int): CardDTO = {
|
||||
CardDTO(
|
||||
identifier = WebUIUtils.cardtoString(card),
|
||||
path = WebUIUtils.cardToPath(card),
|
||||
idx = index
|
||||
idx = Some(index)
|
||||
)
|
||||
}
|
||||
|
||||
def apply(card: Card): CardDTO = {
|
||||
CardDTO(
|
||||
identifier = WebUIUtils.cardtoString(card),
|
||||
path = WebUIUtils.cardToPath(card),
|
||||
idx = None
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package dto.subDTO
|
||||
import de.knockoutwhist.cards.Card
|
||||
import de.knockoutwhist.cards.CardValue.Ace
|
||||
|
||||
case class RoundDTO(trumpSuit: CardDTO, firstRound: Boolean, tricklist: List[TrickDTO])
|
||||
case class RoundDTO(trumpSuit: CardDTO, firstRound: Boolean, trickList: List[TrickDTO])
|
||||
|
||||
object RoundDTO {
|
||||
|
||||
@@ -11,7 +11,7 @@ object RoundDTO {
|
||||
RoundDTO(
|
||||
trumpSuit = CardDTO(Card(Ace, round.trumpSuit)),
|
||||
firstRound = round.firstRound,
|
||||
tricklist = round.tricklist.map(trick => TrickDTO(trick))
|
||||
trickList = round.tricklist.map(trick => TrickDTO(trick))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package dto.subDTO
|
||||
|
||||
import de.knockoutwhist.rounds.Trick
|
||||
|
||||
case class TrickDTO(cards: Map[PlayerDTO, CardDTO], firstCard: Option[CardDTO], winner: Option[PlayerDTO])
|
||||
case class TrickDTO(cards: Map[String, CardDTO], firstCard: Option[CardDTO], winner: Option[PlayerDTO])
|
||||
|
||||
object TrickDTO {
|
||||
|
||||
def apply(trick: Trick): TrickDTO = {
|
||||
TrickDTO(
|
||||
cards = trick.cards.map { case (card, player) => PlayerDTO(player) -> CardDTO(card) },
|
||||
cards = trick.cards.map { case (card, player) => player.id.toString -> CardDTO(card) },
|
||||
firstCard = trick.firstCard.map(card => CardDTO(card)),
|
||||
winner = trick.winner.map(player => PlayerDTO(player))
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user