diff options
author | Jasper Van der Jeugt | 2020-07-30 20:09:47 +0200 |
---|---|---|
committer | Jasper Van der Jeugt | 2020-07-30 20:09:47 +0200 |
commit | 68588db76baaf8f2f17dd9b7f3649b09e102ea85 (patch) | |
tree | 5704809d61b4ecfb6ac40f06b1ad51e23c9d313c /client | |
parent | 3b7d11c6182b8aa3d3d4f9e36c213e4eba6c8d8f (diff) |
Pass black and white cards to the client
Diffstat (limited to 'client')
-rw-r--r-- | client/src/Client.elm | 14 | ||||
-rw-r--r-- | client/src/Messages.elm | 39 | ||||
-rw-r--r-- | client/style.css | 13 |
3 files changed, 56 insertions, 10 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm index efd97fb..41871e9 100644 --- a/client/src/Client.elm +++ b/client/src/Client.elm @@ -70,16 +70,22 @@ view model = case model of ] ++ (case game.view.blackCard of Nothing -> [] - Just c -> [blackCard c]) + Just c -> [blackCard c]) ++ + (List.map whiteCard game.view.hand) -blackCard : String -> Html a -blackCard string = +blackCard : Messages.BlackCard -> Html a +blackCard (Messages.BlackCard string) = let blank = Html.span [Html.Attributes.class "blank"] [] in - Html.div [Html.Attributes.class "black"] <| + Html.div [Html.Attributes.class "card", Html.Attributes.class "black"] <| List.intersperse blank <| List.map Html.text <| String.split "\\BLANK" string +whiteCard : Messages.WhiteCard -> Html a +whiteCard (Messages.WhiteCard string) = Html.div + [Html.Attributes.class "card", Html.Attributes.class "white"] + [Html.text string] + subscriptions : Model -> Sub Msg subscriptions model = webSocketIn WebSocketIn diff --git a/client/src/Messages.elm b/client/src/Messages.elm index 77b3830..d2c2716 100644 --- a/client/src/Messages.elm +++ b/client/src/Messages.elm @@ -8,25 +8,56 @@ import Dict exposing (Dict) import Set exposing (Set) +type BlackCard = + BlackCard String + +jsonDecBlackCard : Json.Decode.Decoder ( BlackCard ) +jsonDecBlackCard = + Json.Decode.lazy (\_ -> Json.Decode.map BlackCard (Json.Decode.string)) + + +jsonEncBlackCard : BlackCard -> Value +jsonEncBlackCard (BlackCard v1) = + Json.Encode.string v1 + + + +type WhiteCard = + WhiteCard String + +jsonDecWhiteCard : Json.Decode.Decoder ( WhiteCard ) +jsonDecWhiteCard = + Json.Decode.lazy (\_ -> Json.Decode.map WhiteCard (Json.Decode.string)) + + +jsonEncWhiteCard : WhiteCard -> Value +jsonEncWhiteCard (WhiteCard v1) = + Json.Encode.string v1 + + + type alias GameView = { opponents: (List String) , myName: String - , blackCard: (Maybe String) + , blackCard: (Maybe BlackCard) + , hand: (List WhiteCard) } jsonDecGameView : Json.Decode.Decoder ( GameView ) jsonDecGameView = - Json.Decode.succeed (\popponents pmyName pblackCard -> {opponents = popponents, myName = pmyName, blackCard = pblackCard}) + Json.Decode.succeed (\popponents pmyName pblackCard phand -> {opponents = popponents, myName = pmyName, blackCard = pblackCard, hand = phand}) |> required "opponents" (Json.Decode.list (Json.Decode.string)) |> required "myName" (Json.Decode.string) - |> fnullable "blackCard" (Json.Decode.string) + |> fnullable "blackCard" (jsonDecBlackCard) + |> required "hand" (Json.Decode.list (jsonDecWhiteCard)) jsonEncGameView : GameView -> Value jsonEncGameView val = Json.Encode.object [ ("opponents", (Json.Encode.list Json.Encode.string) val.opponents) , ("myName", Json.Encode.string val.myName) - , ("blackCard", (maybeEncode (Json.Encode.string)) val.blackCard) + , ("blackCard", (maybeEncode (jsonEncBlackCard)) val.blackCard) + , ("hand", (Json.Encode.list jsonEncWhiteCard) val.hand) ] diff --git a/client/style.css b/client/style.css index fd26c52..6cd9f5d 100644 --- a/client/style.css +++ b/client/style.css @@ -2,11 +2,20 @@ html { font-size: 18px; } +.card { + padding: 18px; + border-radius: 18px; +} + .black { color: white; background: black; - padding: 18px; - border-radius: 18px; +} + +.white { + color: black; + background: white; + border: 2px solid black; } .blank { |