Hide tiles of other players

This commit is contained in:
Correl Roush 2017-11-21 19:40:50 -05:00
parent 6df327f340
commit d29dc79583
5 changed files with 37 additions and 10 deletions

View file

@ -2,7 +2,7 @@ module Client.Decode exposing (..)
import Client.Hand exposing (Hand) import Client.Hand exposing (Hand)
import Client.Game exposing (Game) import Client.Game exposing (Game)
import Client.Player exposing (Player) import Client.Player exposing (Player, Wind(..))
import Json.Decode exposing (..) import Json.Decode exposing (..)
import Json.Decode.Extra exposing (fromResult) import Json.Decode.Extra exposing (fromResult)
import Tile exposing (Tile) import Tile exposing (Tile)
@ -36,10 +36,23 @@ hand =
(field "tiles" (list tile)) (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 : Decoder Player
player = player =
map2 Player map4 Player
(field "name" <| map (\s -> s == "Websocket") string)
(field "name" string) (field "name" string)
(field "seat" wind)
(field "hand" hand) (field "hand" hand)

View file

@ -1,7 +1,7 @@
module Client.Hand exposing (..) module Client.Hand exposing (..)
import Html exposing (Html, div, text) import Html exposing (Html, div, text)
import Html.Attributes exposing (class) import Html.Attributes exposing (class, classList)
import Tile exposing (Tile) import Tile exposing (Tile)
@ -10,9 +10,15 @@ type alias Hand =
} }
view : Hand -> Html a view : Hand -> Bool -> Html a
view model = view model open =
div [ class "hand" ] div [ class "hand" ]
[ div [ class "tiles open" ] <| [ div
List.map Tile.view model.tiles [ class "tiles" ]
<|
case open of
True ->
List.map Tile.view model.tiles
False ->
List.map Tile.viewHidden model.tiles
] ]

View file

@ -3,9 +3,12 @@ module Client.Player exposing (..)
import Client.Hand exposing (Hand) import Client.Hand exposing (Hand)
import Html exposing (..) import Html exposing (..)
type Wind = East | South | West | North
type alias Player = type alias Player =
{ name : String { isMe : Bool
, name : String
, seat : Wind
, hand : Hand , hand : Hand
} }
@ -13,6 +16,6 @@ type alias Player =
view : Player -> Html msg view : Player -> Html msg
view player = view player =
fieldset [] fieldset []
[ legend [] [ text ("Player: " ++ player.name) ] [ legend [] [ text ("Player: " ++ player.name ++ "(" ++ (toString player.seat) ++ ")") ]
, Client.Hand.view player.hand , Client.Hand.view player.hand player.isMe
] ]

View file

@ -79,6 +79,7 @@ tiles =
, "Nan" , "Nan"
, "Shaa" , "Shaa"
, "Pei" , "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 "Pin")
, List.range 1 9 |> List.map toString |> List.map (String.append "Sou") , List.range 1 9 |> List.map toString |> List.map (String.append "Sou")

View file

@ -157,3 +157,7 @@ cssName tile =
view : Tile -> Html a view : Tile -> Html a
view tile = view tile =
span [ class [ (S.Tile (cssName tile)) ] ] [ span [] [] ] span [ class [ (S.Tile (cssName tile)) ] ] [ span [] [] ]
viewHidden : Tile -> Html a
viewHidden _ =
span [ class [ (S.Tile "Back") ] ] [ span [] []]