aboutsummaryrefslogtreecommitdiff
blob: e0694392bb420dfbad66b086347d0cb9a858a78e (plain)
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
module Update.DirectionRequest exposing (apply_to)

import Dict

import Battlemap.Direction
import Battlemap.Navigator.Move

import Model
import Error

make_it_so : Model.Type -> Battlemap.Direction.Type -> Model.Type
make_it_so model dir =
   case model.selection of
      Nothing ->
         (Model.invalidate
            model
            (Error.new
               Error.Programming
               "DirectionRequest: model moving char, no selection."
            )
         )
      (Just selection) ->
         let
            (new_bmap, new_nav) =
               (Battlemap.Navigator.Move.to
                  model.battlemap
                  selection.navigator
                  dir
                  (Dict.values model.characters)
               )
         in
            {model |
               state = Model.MovingCharacterWithButtons,
               battlemap = new_bmap,
               selection = (Just {selection | navigator = new_nav})
            }


apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type
apply_to model dir =
   case (Model.get_state model) of
      Model.MovingCharacterWithButtons -> (make_it_so model dir)
      Model.MovingCharacterWithClick -> (make_it_so model dir)
      _ ->
         (Model.invalidate
            model
            (Error.new
               Error.IllegalAction
               "This can only be done while moving a character."
            )
         )