summaryrefslogtreecommitdiff
blob: 2e02d19ca5fb49c67d10232cf0fdc836e9d3bed6 (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
module Update.EndTurn exposing (apply_to)

import Dict

import Battlemap
import Battlemap.Direction
import Battlemap.Navigator
import Battlemap.Tile

import Model

update_model : Model.Type -> Battlemap.Navigator.Type -> String -> Model.Type
update_model model nav char_id =
   case (Dict.get char_id model.characters) of
      Nothing -> model
      (Just char) ->
         {model |
            navigator = Nothing,
            battlemap =
               (Battlemap.apply_to_all_tiles
                  (Battlemap.apply_to_tile_unsafe
                     (Battlemap.apply_to_tile_unsafe
                        model.battlemap
                        char.location
                        (\t -> {t | char_level = Nothing})
                     )
                     nav.current_location
                     (\t -> {t | char_level = (Just char_id)})
                  )
                  (Battlemap.Tile.set_navigation Battlemap.Direction.None)
               ),
            characters =
               (Dict.update
                  char_id
                  (\mc ->
                     case mc of
                        Nothing -> Nothing
                        (Just c) ->
                           (Just {c | location = nav.current_location})
                  )
                  model.characters
               )
         }

apply_to : Model.Type -> Model.Type
apply_to model =
   case (model.navigator, model.selection) of
      (_, Nothing) -> model
      (Nothing, _) -> model
      ((Just nav), (Just char_id)) -> (update_model model nav char_id)