/
Action.elm
129 lines (105 loc) · 3.05 KB
/
Action.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
module Action exposing (..)
import Html.Events exposing (onWithOptions)
import Json.Decode as Json
import List
import Model exposing (Model)
import String
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Tabletop exposing (Inch, posX, posY, transformTranslate)
import Turn exposing (Turn, Phase(..))
type Action
= Await
| Cancel
| Move
| Charge
| Run
| Hide
| Shoot
| Fight
select : Phase -> Model -> List Action
select phase fighter =
case phase of
Movement ->
-- [ Charge, Run, Hide, Cancel,
[ Move ]
Shooting ->
[ Shoot, Cancel ]
HandToHand ->
[ Cancel ]
Recovery ->
[ Cancel ]
symbol : Action -> String
symbol action =
case action of
Move ->
String.fromChar '🚶'
Run ->
String.fromChar '🏃'
_ ->
String.fromChar '🔜'
{-| TODO: Consider moving into a module
-}
onClick : msg -> Svg.Attribute msg
onClick message =
onWithOptions "click" { stopPropagation = True, preventDefault = False } (Json.succeed message)
view : Action -> Phase -> Model -> (Action -> msg) -> Svg msg
view action phase model msg =
case action of
_ ->
g [ transformTranslate model.position ]
[ circle
[ r (Tabletop.millimeter 20 |> toString)
, fill "red"
, opacity "0.15"
]
[]
]
viewControl : Action -> msg -> Svg msg
viewControl action msg =
g
[ transform "translate(0,1.15)"
, onClick msg
, Svg.Attributes.cursor "pointer"
]
[ circle
[ r (Tabletop.millimeter 12 |> toString)
, fill "white"
, opacity "0.75"
]
[]
, text'
[ fontSize (Tabletop.millimeter 15 |> toString)
, textAnchor "middle"
, alignmentBaseline "middle"
]
[ text (symbol action) ]
]
{-| TODO: Just drawing a circle for now until can come up with better HUD.
-}
viewSelection : Phase -> Model -> (Action -> msg) -> Svg msg
viewSelection phase model msg =
g [ transformTranslate model.position ] <|
circle
[ r "1.25"
, fill "white"
, opacity "0.15"
]
[]
:: List.map (\action -> viewControl action (msg action)) (select phase model)
emptyView : Svg msg
emptyView =
g [] []
{-| TODO: Make the below `view` fn better.
The actions should form a circle around the fighter character
-}
viewAll : Phase -> Model -> Svg msg
viewAll phase fighter =
select phase fighter
|> List.map symbol
|> (String.join " " >> text >> List.repeat 1)
|> text'
[ fontSize (Tabletop.millimeter 20 |> toString)
, x (fighter.position |> posX |> (flip (-)) (Tabletop.millimeter 20) |> toString)
, y (fighter.position |> posY |> (+) (Tabletop.millimeter 40) |> toString)
]