Skip to content

Commit

Permalink
Wire click action for Campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Dec 23, 2016
1 parent 77e855e commit b9c7f52
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Campaign.elm
Expand Up @@ -55,6 +55,7 @@ type Msg
= Begin Game
| Select Model
| Hover Mouse.Position
| Click Mouse.Position
| KeyPress KeyCode
| Resize Window.Size
| NoOp
Expand Down Expand Up @@ -99,6 +100,27 @@ update msg campaign =
, Cmd.none
)

Click ({ x, y } as mouse) ->
let
pos : Tabletop.Position
pos =
tabletopPositionFromMousePosition mouse campaign
in
( { campaign
| game =
Player.getSelectedGangMember activePlayer
|> Maybe.map
(\{ position } ->
if Tabletop.isWithinDistance 2 position pos then
campaign.game
else
Game.mapActivePlayer (Player.deselectAll) campaign.game
)
|> Maybe.withDefault campaign.game
}
, Cmd.none
)

KeyPress key ->
case key of
27 ->
Expand Down Expand Up @@ -162,6 +184,7 @@ subscriptions campaign =
Sub.batch
[ Window.resizes Resize
, Keyboard.presses KeyPress
, Mouse.clicks Click
, case activePlayer.selection of
Just _ ->
Mouse.moves Hover
Expand Down

0 comments on commit b9c7f52

Please sign in to comment.