change Map to List in model, scalajs didn't decode

This commit is contained in:
efim
2023-04-23 23:15:59 +04:00
parent f3e51a4750
commit 77b34a2ca7
4 changed files with 5 additions and 28 deletions

View File

@@ -22,10 +22,6 @@ object Models {
}
object RoomStateView {
given Encoder[Map[PlayerID, String]] = Encoder.encodeMap[PlayerID, String]
given Decoder[Map[PlayerID, String]] = Decoder.decodeMap[PlayerID, String]
given Codec[Map[PlayerID, String]] = Codec.from(summon[Decoder[Map[PlayerID, String]]], summon[Encoder[Map[PlayerID, String]]])
val empty = RoomStateView(
List.empty, PlayerID(0), List.empty, RoundState.Voting(None, List.empty), false
)
@@ -45,16 +41,9 @@ object Models {
/** view state for round after opening the votes
*/
case Viewing(
votes: Map[PlayerID, String]
votes: List[(PlayerID, String)]
)
final case class PlayerID(id: Long) derives Codec.AsObject
object PlayerID {
given KeyEncoder[PlayerID] with
def apply(key: PlayerID): String = key.toString
given KeyDecoder[PlayerID] with
def apply(key: String): Option[PlayerID] = key.toLongOption.map(PlayerID.apply(_))
}
final case class Player(name: String, id: PlayerID) derives Codec.AsObject

View File

@@ -23,7 +23,7 @@ object TestModels {
me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Viewing(
Map(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
List(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
),
canCloseRound = true
)
@@ -98,7 +98,7 @@ object TestModels {
me = me.id,
allowedCards = List("xs", "s", "m", "l", "xl"),
round = RoundState.Viewing(
Map(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
List(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m")
),
canCloseRound = true
)