aboutsummaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-07-30 22:07:37 +0200
committerJasper Van der Jeugt2020-07-30 22:07:37 +0200
commitc92c0f65c733c9aba5c56313a4bc313a299e1230 (patch)
treec5bb44d969ac2b91e664e1235b00278cdece11d7 /client/src
parentab1267a757bcc997f05cc9babe2d1fb9bb681ce4 (diff)
Some logic
Diffstat (limited to 'client/src')
-rw-r--r--client/src/Client.elm12
-rw-r--r--client/src/Messages.elm22
2 files changed, 27 insertions, 7 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm
index 5c6d167..194fd80 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -72,11 +72,17 @@ view model = case model of
[Html.text "change"]
]
] ++
- (case game.view.blackCard of
- Nothing -> []
- Just c -> [blackCard game.cards c]) ++
+ [viewTable game.cards game.view.table] ++
(List.map (whiteCard game.cards) game.view.hand)
+viewTable : Cards -> Messages.TableView -> Html a
+viewTable cards (Messages.Proposing c my) = Html.div [] <|
+ [ blackCard cards c
+ ] ++
+ (case my of
+ Nothing -> []
+ Just mc -> [whiteCard cards mc])
+
blackCard : Cards -> Messages.BlackCard -> Html a
blackCard cards (Messages.BlackCard idx) =
let blank = Html.span [Html.Attributes.class "blank"] [] in
diff --git a/client/src/Messages.elm b/client/src/Messages.elm
index 15a0d1c..69d0eff 100644
--- a/client/src/Messages.elm
+++ b/client/src/Messages.elm
@@ -56,19 +56,33 @@ jsonEncCards val =
+type TableView =
+ Proposing BlackCard (Maybe WhiteCard)
+
+jsonDecTableView : Json.Decode.Decoder ( TableView )
+jsonDecTableView =
+ Json.Decode.lazy (\_ -> Json.Decode.map2 Proposing (Json.Decode.index 0 (jsonDecBlackCard)) (Json.Decode.index 1 (Json.Decode.maybe (jsonDecWhiteCard))))
+
+
+jsonEncTableView : TableView -> Value
+jsonEncTableView (Proposing v1 v2) =
+ Json.Encode.list identity [jsonEncBlackCard v1, (maybeEncode (jsonEncWhiteCard)) v2]
+
+
+
type alias GameView =
{ opponents: (List String)
, myName: String
- , blackCard: (Maybe BlackCard)
+ , table: TableView
, hand: (List WhiteCard)
}
jsonDecGameView : Json.Decode.Decoder ( GameView )
jsonDecGameView =
- Json.Decode.succeed (\popponents pmyName pblackCard phand -> {opponents = popponents, myName = pmyName, blackCard = pblackCard, hand = phand})
+ Json.Decode.succeed (\popponents pmyName ptable phand -> {opponents = popponents, myName = pmyName, table = ptable, hand = phand})
|> required "opponents" (Json.Decode.list (Json.Decode.string))
|> required "myName" (Json.Decode.string)
- |> fnullable "blackCard" (jsonDecBlackCard)
+ |> required "table" (jsonDecTableView)
|> required "hand" (Json.Decode.list (jsonDecWhiteCard))
jsonEncGameView : GameView -> Value
@@ -76,7 +90,7 @@ jsonEncGameView val =
Json.Encode.object
[ ("opponents", (Json.Encode.list Json.Encode.string) val.opponents)
, ("myName", Json.Encode.string val.myName)
- , ("blackCard", (maybeEncode (jsonEncBlackCard)) val.blackCard)
+ , ("table", jsonEncTableView val.table)
, ("hand", (Json.Encode.list jsonEncWhiteCard) val.hand)
]