Skip to content

Commit

Permalink
Make choosing action a player concern
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Oct 20, 2016
1 parent 60fce4f commit be9e5bc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
57 changes: 35 additions & 22 deletions src/Action.elm
Expand Up @@ -5,12 +5,13 @@ import Model exposing (Model)
import String
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Tabletop exposing (Inch, posX, posY)
import Tabletop exposing (Inch, posX, posY, transformTranslate)
import Turn exposing (Turn, Phase(..))


type Action
= Await
| Cancel
| Move
| Charge
| Run
Expand All @@ -23,16 +24,16 @@ select : Phase -> Model -> List Action
select phase fighter =
case phase of
Movement ->
[ Await, Move, Charge, Run, Hide ]
[ Move, Charge, Run, Hide, Cancel ]

Shooting ->
[ Await, Shoot ]
[ Shoot, Cancel ]

HandToHand ->
[ Fight ]
[ Cancel ]

Recovery ->
[ Await ]
[ Cancel ]


symbol : Action -> String
Expand All @@ -48,28 +49,40 @@ symbol action =
String.fromChar '🔜'


view : Action -> Phase -> Model -> Svg msg
view action phase model =
case action of
Await ->
viewSelection phase model

_ ->
g [ transformTranslate model.position ]
[ circle
[ r (Tabletop.millimeter 25 |> toString)
, fill "red"
, opacity "0.15"
]
[]
]


{-| TODO: Just drawing a circle for now until can come up with better HUD.
-}
viewSelection : Phase -> Model -> Svg msg
viewSelection phase { position } =
let
translate : Tabletop.Position -> String
translate ( x, y ) =
String.concat
[ "translate"
, "("
, (String.join "," [ (toString x), (toString y) ])
, ")"
]
in
g [ transform (translate position) ]
[ circle
[ r (Tabletop.millimeter 35 |> toString)
, fill "white"
, opacity "0.15"
]
[]
g [ transformTranslate position ]
[ circle
[ r (Tabletop.millimeter 35 |> toString)
, fill "white"
, opacity "0.15"
]
[]
]


emptyView : Svg msg
emptyView =
g [] []


{-| TODO: Make the below `view` fn better.
Expand Down
4 changes: 1 addition & 3 deletions src/Main.elm
Expand Up @@ -200,9 +200,7 @@ view game =
|> Maybe.withDefault (g [] [])

actionSelection =
Player.getSelectedGangMember game.player
|> Maybe.map (\fighter -> Action.viewSelection (Turn.phase game.turn) fighter)
|> Maybe.withDefault (g [] [])
Player.view game.player (Turn.phase game.turn)

selectedFighterProfile =
Player.getSelectedGangMember game.player
Expand Down
12 changes: 12 additions & 0 deletions src/Player.elm
@@ -1,15 +1,19 @@
module Player exposing (..)

import Action exposing (Action(..))
import Gang exposing (Gang)
import Maybe exposing (andThen)
import Model exposing (Model)
import Svg exposing (Svg)
import Tabletop exposing (Tabletop, Position)
import Turn exposing (Phase)


type alias Player =
{ gang : Gang
, selection : Maybe Model.Id
, movementIntention : Position
, action : Action
}


Expand All @@ -18,6 +22,7 @@ init table =
{ gang = Gang.empty
, selection = Nothing
, movementIntention = Tabletop.center table
, action = Await
}


Expand All @@ -44,3 +49,10 @@ deselectAll player =
getSelectedGangMember : Player -> Maybe Model
getSelectedGangMember player =
player.selection `andThen` (flip Gang.get) player.gang


view : Player -> Phase -> Svg msg
view player phase =
getSelectedGangMember player
|> Maybe.map (Action.view player.action phase)
|> Maybe.withDefault (Action.emptyView)
10 changes: 9 additions & 1 deletion src/Tabletop.elm
@@ -1,6 +1,7 @@
module Tabletop exposing (..)

import Random exposing (Generator)
import String
import Svg exposing (Svg, rect, g, line)
import Svg.Attributes exposing (..)

Expand All @@ -24,7 +25,6 @@ type alias Position =
( Float, Float )



posX : Position -> Float
posX ( x', _ ) =
x'
Expand Down Expand Up @@ -161,3 +161,11 @@ viewMeasuringTape start end range =
]
[]
]


transformTranslate : Position -> Svg.Attribute msg
transformTranslate ( x, y ) =
List.map toString [ x, y ]
|> String.join ","
|> (\str -> String.concat [ "translate(", str, ")" ])
|> transform

0 comments on commit be9e5bc

Please sign in to comment.