aboutsummaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-07-29 21:51:54 +0200
committerJasper Van der Jeugt2020-07-29 21:51:54 +0200
commit231b46d9fbafaff2a8cdcc7bd6c9a813b1a61742 (patch)
treeac4136d80b8fbaa94b55850beba8e46d7a5fd789 /client/src
parent49b346b7ebe98051a618d88a39d9b02f13edf33c (diff)
Collect player sinks
Diffstat (limited to 'client/src')
-rw-r--r--client/src/Client.elm3
-rw-r--r--client/src/Messages.elm18
2 files changed, 13 insertions, 8 deletions
diff --git a/client/src/Client.elm b/client/src/Client.elm
index ffb2b0e..0644a12 100644
--- a/client/src/Client.elm
+++ b/client/src/Client.elm
@@ -46,7 +46,8 @@ update msg model = case msg of
WebSocketIn json ->
case Json.Decode.decodeString Messages.jsonDecServerMessage json of
Err str -> (Error <| Json.Decode.errorToString str, Cmd.none)
- Ok Messages.Welcome -> Debug.log "Welcome" (model, Cmd.none)
+ Ok (Messages.Welcome playerId) ->
+ Debug.log ("Welcome " ++ String.fromInt playerId) (model, Cmd.none)
Ok Messages.Bye -> Debug.log "Bye" (model, Cmd.none)
main : Program () Model Msg
diff --git a/client/src/Messages.elm b/client/src/Messages.elm
index 2510544..76b24f5 100644
--- a/client/src/Messages.elm
+++ b/client/src/Messages.elm
@@ -9,18 +9,22 @@ import Set exposing (Set)
type ServerMessage =
- Welcome
+ Welcome Int
| Bye
jsonDecServerMessage : Json.Decode.Decoder ( ServerMessage )
-jsonDecServerMessage =
- let jsonDecDictServerMessage = Dict.fromList [("Welcome", Welcome), ("Bye", Bye)]
- in decodeSumUnaries "ServerMessage" jsonDecDictServerMessage
+jsonDecServerMessage =
+ let jsonDecDictServerMessage = Dict.fromList
+ [ ("Welcome", Json.Decode.lazy (\_ -> Json.Decode.map Welcome (Json.Decode.int)))
+ , ("Bye", Json.Decode.lazy (\_ -> Json.Decode.succeed Bye))
+ ]
+ in decodeSumObjectWithSingleField "ServerMessage" jsonDecDictServerMessage
jsonEncServerMessage : ServerMessage -> Value
jsonEncServerMessage val =
- case val of
- Welcome -> Json.Encode.string "Welcome"
- Bye -> Json.Encode.string "Bye"
+ let keyval v = case v of
+ Welcome v1 -> ("Welcome", encodeValue (Json.Encode.int v1))
+ Bye -> ("Bye", encodeValue (Json.Encode.list identity []))
+ in encodeSumObjectWithSingleField keyval val