99 lines
2.4 KiB
Scala
99 lines
2.4 KiB
Scala
package industries.sunshine.planningpoker.common
|
|
|
|
import java.util.UUID
|
|
import io.circe._
|
|
|
|
object Models {
|
|
|
|
/** view of the single planning poker round
|
|
* @param players
|
|
* \- people who are currently playing
|
|
* @param allowedCards-
|
|
* the cards values that can be used by players
|
|
* @param round
|
|
* \- state of the selected cards of the players
|
|
* @param canCloseRound
|
|
* \- whether current player has access to button to finish the round
|
|
*/
|
|
final case class RoomStateView(
|
|
players: List[Player],
|
|
me: PlayerID,
|
|
allowedCards: List[String],
|
|
round: RoundState,
|
|
canCloseRound: Boolean = false
|
|
) derives Codec.AsObject {
|
|
def playersCount: Int = players.size
|
|
}
|
|
|
|
object RoomStateView {
|
|
val empty = RoomStateView(
|
|
List.empty,
|
|
PlayerID(0),
|
|
List.empty,
|
|
RoundState.Voting(None, List.empty),
|
|
false
|
|
)
|
|
}
|
|
|
|
enum RoundState derives Codec.AsObject:
|
|
|
|
/** view state for round before votes are open player can know their vote
|
|
* and who of the other players have voted
|
|
*/
|
|
case Voting(
|
|
myCard: Option[String],
|
|
alreadyVoted: List[Player]
|
|
)
|
|
|
|
/** view state for round after opening the votes
|
|
*/
|
|
case Viewing(
|
|
votes: List[(PlayerID, String)]
|
|
)
|
|
final case class PlayerID(id: Long) derives Codec.AsObject
|
|
|
|
final case class Player(name: String, id: PlayerID) derives Codec.AsObject
|
|
|
|
final case class RoomID(name: String) derives Codec.AsObject
|
|
|
|
final case class Room(
|
|
id: RoomID,
|
|
players: List[Player],
|
|
owner: PlayerID,
|
|
password: String,
|
|
allowedCards: List[String],
|
|
round: RoundState
|
|
) {
|
|
def toViewFor(playerId: PlayerID): RoomStateView = {
|
|
players
|
|
.find(_.id == playerId)
|
|
.fold(ifEmpty = RoomStateView.empty)((me: Player) =>
|
|
RoomStateView(
|
|
players,
|
|
me.id,
|
|
allowedCards,
|
|
round,
|
|
playerId == owner
|
|
)
|
|
)
|
|
}
|
|
}
|
|
object Room {
|
|
val testRoom = Room(
|
|
id = RoomID("testroom"),
|
|
players = List(
|
|
Player("me", PlayerID(1L)),
|
|
Player("horsey", PlayerID(444L)),
|
|
Player("froggy", PlayerID(555L)),
|
|
Player("owley", PlayerID(777L))
|
|
),
|
|
owner = PlayerID(1L),
|
|
password = "password",
|
|
allowedCards = List("S", "M", "L"),
|
|
// TODO - this needs to be a different hting
|
|
round = RoundState.Voting(None, List.empty)
|
|
)
|
|
}
|
|
|
|
}
|