Skip to content

Commit

Permalink
Add shooting diceroll command and control
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Jan 5, 2017
1 parent 34cd0fd commit bedd5c0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Campaign.elm
Expand Up @@ -82,6 +82,9 @@ update msg campaign =
activePlayer =
Game.activePlayer campaign.game

enemyPlayer =
Game.enemyPlayer campaign.game

currentTurn =
Game.turn campaign.game
in
Expand All @@ -104,6 +107,33 @@ update msg campaign =

Command action ->
case action of
Action.Shoot weapon ->
let
maybeTarget : Maybe Model
maybeTarget =
Player.getSelectedGangMember activePlayer
|> Maybe.andThen
(Model.withinShootingRange (Gang.toList enemyPlayer.gang) weapon
>> List.head
)
in
( { campaign
| game =
campaign.game
|> Game.mapActivePlayer
(\player ->
{ player
| action = action
, target = Maybe.map (.id) maybeTarget
}
)
, rolling =
Player.getSelectedGangMember activePlayer
|> Maybe.map2 (\target attacker -> ( 1, 6, Player.Shooting attacker target weapon )) maybeTarget
}
, Cmd.none
)

_ ->
( { campaign
| game = Game.mapActivePlayer (\p -> { p | action = action }) campaign.game
Expand Down Expand Up @@ -446,7 +476,9 @@ view campaign =
bottom =
Html.div [ id "controls" ]
[ selectedFighterProfile
, Controls.view activePlayer (Game.turn game |> Turn.phase) Command
, campaign.rolling
|> Maybe.map (\( num, val, instruction ) -> Controls.viewDice num val <| Roll instruction)
|> Maybe.withDefault (Controls.view activePlayer (Game.turn game |> Turn.phase) Command)
, targetFighterProfile
]

Expand Down
18 changes: 18 additions & 0 deletions src/View/Controls.elm
Expand Up @@ -74,6 +74,24 @@ viewControl key maybeAction msg =
]


viewDice : Int -> Int -> msg -> Html msg
viewDice num val msg =
let
diceStr =
(toString num) ++ "D" ++ (toString val)
in
Html.div [ id "player-commands" ]
[ button
[ class "command diceroll"
, title diceStr
, onClickWithoutPropagation msg
]
[ span [ class "command-symbol" ] [ text "🎲" ]
, span [ class "command-hotkey" ] [ text diceStr ]
]
]


view : Player -> Phase -> (Action -> msg) -> Html msg
view player phase msg =
availableActions player phase
Expand Down

0 comments on commit bedd5c0

Please sign in to comment.