From af9ba36883d902d2415811377e4a67fab4d11226 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 2 Aug 2020 17:39:26 +0200 Subject: Start voting phase --- client/src/Messages.elm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'client/src/Messages.elm') diff --git a/client/src/Messages.elm b/client/src/Messages.elm index 11c34ca..3979587 100644 --- a/client/src/Messages.elm +++ b/client/src/Messages.elm @@ -78,15 +78,22 @@ jsonEncOpponent val = type TableView = Proposing BlackCard (List WhiteCard) + | Voting BlackCard (List WhiteCard) (List (List WhiteCard)) (Maybe Int) jsonDecTableView : Json.Decode.Decoder ( TableView ) jsonDecTableView = - Json.Decode.lazy (\_ -> Json.Decode.map2 Proposing (Json.Decode.index 0 (jsonDecBlackCard)) (Json.Decode.index 1 (Json.Decode.list (jsonDecWhiteCard)))) - + let jsonDecDictTableView = Dict.fromList + [ ("Proposing", Json.Decode.lazy (\_ -> Json.Decode.map2 Proposing (Json.Decode.index 0 (jsonDecBlackCard)) (Json.Decode.index 1 (Json.Decode.list (jsonDecWhiteCard))))) + , ("Voting", Json.Decode.lazy (\_ -> Json.Decode.map4 Voting (Json.Decode.index 0 (jsonDecBlackCard)) (Json.Decode.index 1 (Json.Decode.list (jsonDecWhiteCard))) (Json.Decode.index 2 (Json.Decode.list (Json.Decode.list (jsonDecWhiteCard)))) (Json.Decode.index 3 (Json.Decode.maybe (Json.Decode.int))))) + ] + in decodeSumObjectWithSingleField "TableView" jsonDecDictTableView jsonEncTableView : TableView -> Value -jsonEncTableView (Proposing v1 v2) = - Json.Encode.list identity [jsonEncBlackCard v1, (Json.Encode.list jsonEncWhiteCard) v2] +jsonEncTableView val = + let keyval v = case v of + Proposing v1 v2 -> ("Proposing", encodeValue (Json.Encode.list identity [jsonEncBlackCard v1, (Json.Encode.list jsonEncWhiteCard) v2])) + Voting v1 v2 v3 v4 -> ("Voting", encodeValue (Json.Encode.list identity [jsonEncBlackCard v1, (Json.Encode.list jsonEncWhiteCard) v2, (Json.Encode.list (Json.Encode.list jsonEncWhiteCard)) v3, (maybeEncode (Json.Encode.int)) v4])) + in encodeSumObjectWithSingleField keyval val -- cgit v1.2.3