Reviewed-on: #101 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
23 lines
673 B
Scala
23 lines
673 B
Scala
package dto
|
|
|
|
import de.knockoutwhist.control.GameLogic
|
|
import play.api.libs.json.{Json, OFormat}
|
|
|
|
case class PlayerQueueDTO(currentPlayer: Option[PlayerDTO], queue: Seq[PlayerDTO])
|
|
|
|
object PlayerQueueDTO {
|
|
|
|
implicit val queueFormat: OFormat[PlayerQueueDTO] = Json.format[PlayerQueueDTO]
|
|
|
|
def apply(logic: GameLogic): PlayerQueueDTO = {
|
|
val currentPlayerDTO = logic.getCurrentPlayer.map(PlayerDTO(_))
|
|
val queueDTO = logic.getPlayerQueue.map(_.duplicate().flatMap(player => Some(PlayerDTO(player))).toSeq)
|
|
if (queueDTO.isEmpty) {
|
|
PlayerQueueDTO(currentPlayerDTO, Seq.empty)
|
|
} else {
|
|
PlayerQueueDTO(currentPlayerDTO, queueDTO.get)
|
|
}
|
|
}
|
|
|
|
}
|