summaryrefslogtreecommitdiff
blob: cf600e6f1b88138947d87ce889b67905edb07125 (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
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
module Model.RequestDirection exposing (apply_to)

import Dict

import Battlemap
import Battlemap.Direction
import Battlemap.Location


import Character

import Model
import Error

make_it_so : Model.Type -> Battlemap.Direction.Type -> Model.Type
make_it_so model dir =
   case model.selection of
      (Model.SelectedCharacter char_id) ->
         let
            new_bmap =
               (Battlemap.try_adding_step_to_navigator
                  model.battlemap
                  (\loc ->
                     (List.all
                        (\char ->
                           (
                              ((Character.get_ref char) == char_id)
                              ||
                              (
                                 (Battlemap.Location.get_ref
                                    (Character.get_location char)
                                 )
                                 /=
                                 (Battlemap.Location.get_ref loc)
                              )
                           )
                        )
                        (Dict.values model.characters)
                     )
                  )
                  dir
               )
         in
            case new_bmap of
               (Just bmap) ->
                  {model |
                     state = Model.MovingCharacterWithButtons,
                     battlemap = bmap
                  }

               Nothing ->
                  (Model.invalidate
                     model
                     (Error.new
                        Error.IllegalAction
                        "Unreachable/occupied tile."
                     )
                  )

      _ ->
         (Model.invalidate
            model
            (Error.new
               Error.Programming
               "DirectionRequest: model moving char, no char selected."
            )
         )

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."
            )
         )