aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/Client.elm8
-rw-r--r--client/src/Messages.elm26
2 files changed, 30 insertions, 4 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm
index 94e33cf..178e406 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -45,6 +45,12 @@ parseRoomId url = case String.split "/" url.path of
_ :: "rooms" :: roomId :: _ -> Ok roomId
_ -> Err <| "Invalid path: " ++ url.path
+viewOpponent : Messages.Opponent -> Html msg
+viewOpponent opponent = Html.div [] <|
+ [ Html.text opponent.name
+ ] ++
+ if opponent.ready then [Html.text " ✅"] else []
+
view : Model -> List (Html Msg)
view model = case model of
Error str ->
@@ -58,7 +64,7 @@ view model = case model of
Game game ->
[ Html.h1 [] [Html.text "Opponents"]
, Html.ul [] <| List.map
- (\p -> Html.li [] [Html.text p])
+ (\o -> Html.li [] [viewOpponent o])
game.view.opponents
, Html.h1 [] [Html.text "You"]
, Html.form
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)