From 323ca81c96e4186747f06b6178d71d49e98c6066 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 31 Jul 2020 13:35:17 +0200 Subject: Sync opponent proposals --- client/src/Messages.elm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'client/src/Messages.elm') diff --git a/client/src/Messages.elm b/client/src/Messages.elm index 1188525..b38fbd5 100644 --- a/client/src/Messages.elm +++ b/client/src/Messages.elm @@ -56,6 +56,26 @@ jsonEncCards val = +type alias Opponent = + { name: String + , ready: Bool + } + +jsonDecOpponent : Json.Decode.Decoder ( Opponent ) +jsonDecOpponent = + Json.Decode.succeed (\pname pready -> {name = pname, ready = pready}) + |> required "name" (Json.Decode.string) + |> required "ready" (Json.Decode.bool) + +jsonEncOpponent : Opponent -> Value +jsonEncOpponent val = + Json.Encode.object + [ ("name", Json.Encode.string val.name) + , ("ready", Json.Encode.bool val.ready) + ] + + + type TableView = Proposing BlackCard (Maybe WhiteCard) @@ -71,7 +91,7 @@ jsonEncTableView (Proposing v1 v2) = type alias GameView = - { opponents: (List String) + { opponents: (List Opponent) , myName: String , table: TableView , hand: (List WhiteCard) @@ -80,7 +100,7 @@ type alias GameView = jsonDecGameView : Json.Decode.Decoder ( GameView ) jsonDecGameView = Json.Decode.succeed (\popponents pmyName ptable phand -> {opponents = popponents, myName = pmyName, table = ptable, hand = phand}) - |> required "opponents" (Json.Decode.list (Json.Decode.string)) + |> required "opponents" (Json.Decode.list (jsonDecOpponent)) |> required "myName" (Json.Decode.string) |> required "table" (jsonDecTableView) |> required "hand" (Json.Decode.list (jsonDecWhiteCard)) @@ -88,7 +108,7 @@ jsonDecGameView = jsonEncGameView : GameView -> Value jsonEncGameView val = Json.Encode.object - [ ("opponents", (Json.Encode.list Json.Encode.string) val.opponents) + [ ("opponents", (Json.Encode.list jsonEncOpponent) val.opponents) , ("myName", Json.Encode.string val.myName) , ("table", jsonEncTableView val.table) , ("hand", (Json.Encode.list jsonEncWhiteCard) val.hand) -- cgit v1.2.3