From 4e1068c41b84f0813b82fe61816271b92ca76f48 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 30 Jul 2020 14:43:25 +0200 Subject: Basic syncing --- client/src/Client.elm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'client/src/Client.elm') diff --git a/client/src/Client.elm b/client/src/Client.elm index 0644a12..442f089 100644 --- a/client/src/Client.elm +++ b/client/src/Client.elm @@ -3,7 +3,7 @@ port module Client exposing (main) import Browser import Html exposing (Html) import Json.Decode -import Messages +import Messages exposing (GameView) import Url exposing (Url) port webSocketIn : (String -> msg) -> Sub msg @@ -19,6 +19,9 @@ type Model | Connecting { roomId : String } + | Game + { view : GameView + } parseRoomId : Url -> Result String String parseRoomId url = case String.split "/" url.path of @@ -35,6 +38,13 @@ view model = case model of [ Html.h1 [] [Html.text <| "Connecting to room " ++ state.roomId ++ "..."] ] + Game game -> + [ Html.h1 [] [Html.text "Players"] + , Html.ul [] <| List.map + (\p -> Html.li [] [Html.text p]) + game.view.players + ] + subscriptions : Model -> Sub Msg subscriptions model = webSocketIn WebSocketIn @@ -49,6 +59,8 @@ update msg model = case msg of Ok (Messages.Welcome playerId) -> Debug.log ("Welcome " ++ String.fromInt playerId) (model, Cmd.none) Ok Messages.Bye -> Debug.log "Bye" (model, Cmd.none) + Ok (Messages.SyncGameView gameView) -> + (Game {view = gameView}, Cmd.none) main : Program () Model Msg main = Browser.application -- cgit v1.2.3