Skip to content

Commit 6d1d7a3

Browse files
committed
disallow selection if it isn't your turn to select
Signed-off-by: Ryan1729 <[email protected]>
1 parent fd44c4b commit 6d1d7a3

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

PieceView.elm

+17-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Svg exposing (Svg, svg, rect, path, Attribute, ellipse, g)
55
import Svg.Attributes exposing (..)
66
import Svg.Events exposing (onClick)
77
import Msg exposing (Msg(..))
8-
import Model exposing (Piece(..), Rack, Shape(..), Colour(..), Pattern(..))
8+
import Model exposing (Piece(..), Rack, Shape(..), Colour(..), Pattern(..), TurnState(..))
99

1010

1111
rackWidth =
@@ -24,8 +24,8 @@ rackHeightString =
2424
toString rackHeight
2525

2626

27-
renderRack : Maybe Piece -> Rack -> Html Msg
28-
renderRack selected rack =
27+
renderRack : TurnState -> Maybe Piece -> Rack -> Html Msg
28+
renderRack turnState selected rack =
2929
svg
3030
[ width rackWidthString
3131
, height rackHeightString
@@ -45,11 +45,6 @@ renderRack selected rack =
4545
, Svg.stop [ offset "87.5%", stopColor (colourToString Blue), stopOpacity "0" ] []
4646
]
4747
]
48-
-- <linearGradient id="Gradient2" x1="0" x2="1" y1="0" y2="1">
49-
-- <stop offset="0%" stop-color="red"></stop>
50-
-- <stop offset="100%" stop-color="red" stop-opacity="0"></stop>
51-
--
52-
-- </linearGradient>
5348
, Svg.rect
5449
[ x "0"
5550
, y "0"
@@ -61,11 +56,11 @@ renderRack selected rack =
6156
]
6257
[]
6358
]
64-
++ renderPieces selected rack
59+
++ renderPieces turnState selected rack
6560

6661

67-
renderPieces : Maybe Piece -> Rack -> List (Svg Msg)
68-
renderPieces selected rack =
62+
renderPieces : TurnState -> Maybe Piece -> Rack -> List (Svg Msg)
63+
renderPieces turnState selected rack =
6964
let
7065
isSelected =
7166
case selected of
@@ -78,7 +73,8 @@ renderPieces selected rack =
7873
Model.piecePossibilities
7974
|> List.indexedMap
8075
(\index piece ->
81-
renderPieceInRack (indexToPosition index)
76+
renderPieceInRack turnState
77+
(indexToPosition index)
8278
(isSelected piece)
8379
(Model.isInRack piece rack)
8480
piece
@@ -89,12 +85,18 @@ nullSvg =
8985
Svg.text ""
9086

9187

92-
renderPieceInRack : ( Float, Float ) -> Bool -> Bool -> Piece -> Svg Msg
93-
renderPieceInRack (( xPos, yPos ) as point) isSelected isPresent piece =
88+
renderPieceInRack : TurnState -> ( Float, Float ) -> Bool -> Bool -> Piece -> Svg Msg
89+
renderPieceInRack turnState (( xPos, yPos ) as point) isSelected isPresent piece =
9490
if isPresent then
9591
let
92+
extraAttributes =
93+
if turnState == SelectPiece then
94+
[ onClick (Select piece) ]
95+
else
96+
[]
97+
9698
renderedPiece =
97-
renderPiece [ onClick (Select piece) ] point piece
99+
renderPiece extraAttributes point piece
98100
in
99101
if isSelected then
100102
g []

View.elm

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ view model =
2525
[ text "New Game" ]
2626
, Grid.grid []
2727
[ Grid.cell [ Grid.size All 5 ]
28-
[ PieceView.renderRack model.selected model.rack
28+
[ PieceView.renderRack model.turnState model.selected model.rack
2929
]
3030
, Grid.cell [ Grid.size All 6 ]
3131
[ Html.div [ Html.Attributes.style [ ( "width", boardWidthString ++ "px" ), ( "display", "flex" ), ( "justify-content", "center" ), ( "font-size", (boardWidth / 32 |> toString) ++ "px" ) ] ]

0 commit comments

Comments
 (0)