| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-26 19:13:04 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-26 19:13:04 +0200 | 
| commit | 33e57128d48a012533c42635f52037fcdedd4c56 (patch) | |
| tree | 05deb83b77311d25168e5966c14c1bf20f17fb79 /client/elm/battlemap/src/Update | |
| parent | 9293fb062b0bf66995c72b30e037c762318be000 (diff) | |
Range indicators are now clickable.
Diffstat (limited to 'client/elm/battlemap/src/Update')
| -rw-r--r-- | client/elm/battlemap/src/Update/DirectionRequest.elm | 25 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/EndTurn.elm | 82 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/SelectCharacter.elm | 33 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/SelectTile.elm | 80 | 
4 files changed, 165 insertions, 55 deletions
diff --git a/client/elm/battlemap/src/Update/DirectionRequest.elm b/client/elm/battlemap/src/Update/DirectionRequest.elm index 477ba71..da32240 100644 --- a/client/elm/battlemap/src/Update/DirectionRequest.elm +++ b/client/elm/battlemap/src/Update/DirectionRequest.elm @@ -6,23 +6,32 @@ import Battlemap.Direction  import Battlemap.Navigator.Move  import Model +import Error -apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type -apply_to model dir = -   case (model.state, model.navigator) of -      (_ , Nothing) -> model -      ((Model.MovingCharacter _), (Just nav)) -> +make_it_so : Model.Type -> Battlemap.Direction.Type -> Model.Type +make_it_so model dir = +   case model.selection of +      Nothing -> {model | state = (Model.Error Error.Programming)} +      (Just selection) ->           let              (new_bmap, new_nav) =                 (Battlemap.Navigator.Move.to                    model.battlemap -                  nav +                  selection.navigator                    dir                    (Dict.values model.characters)                 )           in              {model | +               state = Model.MovingCharacterWithButtons,                 battlemap = new_bmap, -               navigator = (Just new_nav) +               selection = (Just {selection | navigator = new_nav})              } -      (_, _) -> model + + +apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type +apply_to model dir = +   case model.state of +      Model.MovingCharacterWithButtons -> (make_it_so model dir) +      Model.MovingCharacterWithClick -> (make_it_so model dir) +      _ -> {model | state = (Model.Error Error.IllegalAction)} diff --git a/client/elm/battlemap/src/Update/EndTurn.elm b/client/elm/battlemap/src/Update/EndTurn.elm index cc81028..7172b2f 100644 --- a/client/elm/battlemap/src/Update/EndTurn.elm +++ b/client/elm/battlemap/src/Update/EndTurn.elm @@ -9,43 +9,53 @@ 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}) +import Error + +make_it_so : Model.Type -> Model.Type +make_it_so model = +   case model.selection of +      Nothing -> {model | state = (Model.Error Error.Programming)} +      (Just selection) -> +         case (Dict.get selection.character model.characters) of +            Nothing -> {model | state = (Model.Error Error.Programming)} +            (Just char) -> +               {model | +                  state = Model.Default, +                  selection = 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}) +                           ) +                           selection.navigator.current_location +                           (\t -> {t | char_level = (Just selection.character)}) +                        ) +                        (Battlemap.Tile.reset_tile) +                     ), +                  characters = +                     (Dict.update +                        selection.character +                        (\mc -> +                           case mc of +                              Nothing -> Nothing +                              (Just c) -> +                                 (Just +                                    {c | +                                       location = selection.navigator.current_location +                                    } +                                 ) +                        ) +                        model.characters                       ) -                     nav.current_location -                     (\t -> {t | char_level = (Just char_id)}) -                  ) -                  (Battlemap.Tile.reset_tile) -               ), -            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.state, model.navigator) of -      (_, Nothing) -> model -      ((Model.MovingCharacter char_id), (Just nav)) -> -         (update_model model nav char_id) -      (_, _) -> model +   case model.state of +      Model.MovingCharacterWithButtons -> (make_it_so model) +      Model.MovingCharacterWithClick -> (make_it_so model) +      _ -> {model | state = (Model.Error Error.IllegalAction)} + diff --git a/client/elm/battlemap/src/Update/SelectCharacter.elm b/client/elm/battlemap/src/Update/SelectCharacter.elm index 3fa2ab2..0e7b1c4 100644 --- a/client/elm/battlemap/src/Update/SelectCharacter.elm +++ b/client/elm/battlemap/src/Update/SelectCharacter.elm @@ -12,6 +12,8 @@ import Battlemap.Tile  import Battlemap.RangeIndicator  import Model +import Event +import Error  display_range : (        Int -> @@ -39,10 +41,10 @@ display_range dist loc_ref indicator bmap =     ) -apply_to : Model.Type -> Character.Ref -> Model.Type -apply_to model char_id = +make_it_so : Model.Type -> Character.Ref -> Model.Type +make_it_so model char_id =     case (Dict.get char_id model.characters) of -      Nothing -> model +      Nothing -> {model | state = (Model.Error Error.Programming)}        (Just char) ->           let              new_range_indicator = @@ -54,7 +56,7 @@ apply_to model char_id =                 )           in              {model | -               state = (Model.MovingCharacter char_id), +               state = Model.MovingCharacterWithClick,                 battlemap =                    (                       (Dict.foldl @@ -66,12 +68,21 @@ apply_to model char_id =                          new_range_indicator                       )                    ), -               navigator = +               selection =                    (Just -                     (Battlemap.Navigator.new_navigator -                        char.location -                        char.movement_points -                     ) -                  ), -               range_indicator = new_range_indicator +                     { +                        character = char_id, +                        navigator = +                           (Battlemap.Navigator.new +                              char.location +                              char.movement_points +                           ), +                        range_indicator = new_range_indicator +                     } +                  )              } + +apply_to : Model.Type -> Character.Ref -> Model.Type +apply_to model char_id = +   case model.state of +      _ -> (make_it_so model char_id) diff --git a/client/elm/battlemap/src/Update/SelectTile.elm b/client/elm/battlemap/src/Update/SelectTile.elm new file mode 100644 index 0000000..aa89c30 --- /dev/null +++ b/client/elm/battlemap/src/Update/SelectTile.elm @@ -0,0 +1,80 @@ +module Update.SelectTile exposing (apply_to) + +import Dict + +import Character + +import Battlemap +import Battlemap.Direction +import Battlemap.Location +import Battlemap.Navigator +import Battlemap.Tile +import Battlemap.RangeIndicator + +import Update.DirectionRequest +import Update.EndTurn + +import Model +import Error + +autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type +autopilot dir model = +   (Update.DirectionRequest.apply_to model dir) + +go_to_tile : Model.Type -> Battlemap.Location.Ref -> Model.Type +go_to_tile model loc_ref = +   case model.selection of +      Nothing -> {model | state = (Model.Error Error.Programming)} +      (Just selection) -> +         case (Dict.get loc_ref selection.range_indicator) of +            Nothing -> {model | state = Model.Default, selection = Nothing} +            (Just indicator) -> +               let +                  new_model = +                     (List.foldr +                        (autopilot) +                        {model | +                           battlemap = +                              (Battlemap.apply_to_all_tiles +                                 model.battlemap +                                 (Battlemap.Tile.set_direction +                                    Battlemap.Direction.None +                                 ) +                              ), +                           selection = +                              (Just +                                 { +                                    selection | +                                    navigator = +                                       (Battlemap.Navigator.reset +                                          selection.navigator +                                       ) +                                 } +                              ) +                        } +                        indicator.path +                     ) +               in +                  if +                  ( +                     (model.state == Model.MovingCharacterWithClick) +                     && +                     ( +                        (Battlemap.Location.get_ref +                           selection.navigator.current_location +                        ) +                        == loc_ref +                     ) +                  ) +                  then +                     (Update.EndTurn.apply_to new_model) +                  else +                     {new_model | state = model.state} + + +apply_to : Model.Type -> Battlemap.Location.Ref -> Model.Type +apply_to model loc_ref = +   case model.state of +      Model.MovingCharacterWithButtons -> (go_to_tile model loc_ref) +      Model.MovingCharacterWithClick -> (go_to_tile model loc_ref) +      _ -> {model | state = (Model.Error Error.IllegalAction)}  | 


