From d29dc79583154ca2154fe12fb693c956648de90c Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 21 Nov 2017 19:40:50 -0500 Subject: [PATCH] Hide tiles of other players --- priv/src/Client/Decode.elm | 17 +++++++++++++++-- priv/src/Client/Hand.elm | 16 +++++++++++----- priv/src/Client/Player.elm | 9 ++++++--- priv/src/Stylesheets.elm | 1 + priv/src/Tile.elm | 4 ++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/priv/src/Client/Decode.elm b/priv/src/Client/Decode.elm index dd9d600..26ce15d 100644 --- a/priv/src/Client/Decode.elm +++ b/priv/src/Client/Decode.elm @@ -2,7 +2,7 @@ module Client.Decode exposing (..) import Client.Hand exposing (Hand) import Client.Game exposing (Game) -import Client.Player exposing (Player) +import Client.Player exposing (Player, Wind(..)) import Json.Decode exposing (..) import Json.Decode.Extra exposing (fromResult) import Tile exposing (Tile) @@ -36,10 +36,23 @@ hand = (field "tiles" (list tile)) +wind : Decoder Wind +wind = + let + toWind s = case s of + "east" -> East + "west" -> West + "south" -> South + _ -> North + in + string |> map toWind + player : Decoder Player player = - map2 Player + map4 Player + (field "name" <| map (\s -> s == "Websocket") string) (field "name" string) + (field "seat" wind) (field "hand" hand) diff --git a/priv/src/Client/Hand.elm b/priv/src/Client/Hand.elm index f825e70..0f62737 100644 --- a/priv/src/Client/Hand.elm +++ b/priv/src/Client/Hand.elm @@ -1,7 +1,7 @@ module Client.Hand exposing (..) import Html exposing (Html, div, text) -import Html.Attributes exposing (class) +import Html.Attributes exposing (class, classList) import Tile exposing (Tile) @@ -10,9 +10,15 @@ type alias Hand = } -view : Hand -> Html a -view model = +view : Hand -> Bool -> Html a +view model open = div [ class "hand" ] - [ div [ class "tiles open" ] <| - List.map Tile.view model.tiles + [ div + [ class "tiles" ] + <| + case open of + True -> + List.map Tile.view model.tiles + False -> + List.map Tile.viewHidden model.tiles ] diff --git a/priv/src/Client/Player.elm b/priv/src/Client/Player.elm index aae0761..621ddd3 100644 --- a/priv/src/Client/Player.elm +++ b/priv/src/Client/Player.elm @@ -3,9 +3,12 @@ module Client.Player exposing (..) import Client.Hand exposing (Hand) import Html exposing (..) +type Wind = East | South | West | North type alias Player = - { name : String + { isMe : Bool + , name : String + , seat : Wind , hand : Hand } @@ -13,6 +16,6 @@ type alias Player = view : Player -> Html msg view player = fieldset [] - [ legend [] [ text ("Player: " ++ player.name) ] - , Client.Hand.view player.hand + [ legend [] [ text ("Player: " ++ player.name ++ "(" ++ (toString player.seat) ++ ")") ] + , Client.Hand.view player.hand player.isMe ] diff --git a/priv/src/Stylesheets.elm b/priv/src/Stylesheets.elm index 2e0a405..efc317c 100644 --- a/priv/src/Stylesheets.elm +++ b/priv/src/Stylesheets.elm @@ -79,6 +79,7 @@ tiles = , "Nan" , "Shaa" , "Pei" + , "Back" ] , List.range 1 9 |> List.map toString |> List.map (String.append "Pin") , List.range 1 9 |> List.map toString |> List.map (String.append "Sou") diff --git a/priv/src/Tile.elm b/priv/src/Tile.elm index 1252970..e6cafa4 100644 --- a/priv/src/Tile.elm +++ b/priv/src/Tile.elm @@ -157,3 +157,7 @@ cssName tile = view : Tile -> Html a view tile = span [ class [ (S.Tile (cssName tile)) ] ] [ span [] [] ] + +viewHidden : Tile -> Html a +viewHidden _ = + span [ class [ (S.Tile "Back") ] ] [ span [] []]