| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | src/battlemap/src/Model.elm | 2 | ||||
| -rw-r--r-- | src/battlemap/src/Model/EndTurn.elm | 1 | ||||
| -rw-r--r-- | src/battlemap/src/Model/RequestDirection.elm | 8 | ||||
| -rw-r--r-- | src/battlemap/src/Model/SelectCharacter.elm | 125 | ||||
| -rw-r--r-- | src/battlemap/src/Model/SelectTile.elm | 23 | ||||
| -rw-r--r-- | src/battlemap/src/UI.elm | 43 | 
6 files changed, 140 insertions, 62 deletions
| diff --git a/src/battlemap/src/Model.elm b/src/battlemap/src/Model.elm index d770711..f85eb34 100644 --- a/src/battlemap/src/Model.elm +++ b/src/battlemap/src/Model.elm @@ -45,7 +45,7 @@ reset model characters =        battlemap = (Battlemap.reset model.battlemap),        characters = characters,        error = Nothing, -      ui = model.ui +      ui = (UI.set_previous_action model.ui Nothing)     }  invalidate : Type -> Error.Type -> Type diff --git a/src/battlemap/src/Model/EndTurn.elm b/src/battlemap/src/Model/EndTurn.elm index e7fbe3c..d24c727 100644 --- a/src/battlemap/src/Model/EndTurn.elm +++ b/src/battlemap/src/Model/EndTurn.elm @@ -4,7 +4,6 @@ module Model.EndTurn exposing (apply_to)  import Dict  -- Battlemap ------------------------------------------------------------------- -  import Battlemap  import Character diff --git a/src/battlemap/src/Model/RequestDirection.elm b/src/battlemap/src/Model/RequestDirection.elm index 3c48c93..30bc54e 100644 --- a/src/battlemap/src/Model/RequestDirection.elm +++ b/src/battlemap/src/Model/RequestDirection.elm @@ -35,8 +35,12 @@ make_it_so model char_ref dir =        case new_bmap of           (Just bmap) ->              {model | -               ui = (UI.set_has_just_used_manual_controls model.ui True), -               battlemap = bmap +               battlemap = bmap, +               ui = +                  (UI.set_previous_action +                     model.ui +                     (Just UI.UsedManualControls) +                  )              }           Nothing -> diff --git a/src/battlemap/src/Model/SelectCharacter.elm b/src/battlemap/src/Model/SelectCharacter.elm index a6b4a6b..c98766b 100644 --- a/src/battlemap/src/Model/SelectCharacter.elm +++ b/src/battlemap/src/Model/SelectCharacter.elm @@ -4,55 +4,108 @@ module Model.SelectCharacter exposing (apply_to)  import Dict  -- Battlemap ------------------------------------------------------------------- +import Battlemap +import Battlemap.Direction +  import Character -import Battlemap +import UI  import Model +import Model.RequestDirection +  import Error  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -make_it_so : Model.Type -> Character.Ref -> Model.Type -make_it_so model char_id = -   case (Dict.get char_id model.characters) of -      (Just char) -> -         if ((Character.get_team char) == model.controlled_team) -         then -            {model | -               state = (Model.ControllingCharacter char_id), -               battlemap = -                  (Battlemap.set_navigator -                     (Character.get_location char) -                     (Character.get_movement_points char) -                     (Character.get_attack_range char) -                     (Dict.values model.characters) -                     model.battlemap -                  ) -            } -         else -            (Model.invalidate -               model -               (Error.new -                  Error.IllegalAction -                  "SelectCharacter: Wrong team. Attack is not implemented." -               ) -            ) +autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type +autopilot dir model = +   (Model.RequestDirection.apply_to model dir) + +attack_character : ( +      Model.Type -> +      Character.Ref -> +      Character.Ref -> +      Character.Type -> +      Model.Type +   ) +attack_character model main_char_id target_char_id target_char = +   (Model.invalidate +      model +      (Error.new +         Error.IllegalAction +         "Attacking another character is not yet possible." +      ) +   ) -      Nothing -> -         (Model.invalidate -            model -            (Error.new -               Error.Programming -               "SelectCharacter: Unknown char selected." +select_character : ( +      Model.Type -> +      Character.Ref -> +      Character.Type -> +      Model.Type +   ) +select_character model target_char_id target_char = +   if ((Character.get_team target_char) == model.controlled_team) +   then +      {model | +         state = (Model.ControllingCharacter target_char_id), +         ui = (UI.set_previous_action model.ui Nothing), +         battlemap = +            (Battlemap.set_navigator +               (Character.get_location target_char) +               (Character.get_movement_points target_char) +               (Character.get_attack_range target_char) +               (Dict.values model.characters) +               model.battlemap              ) +      } +   else +      (Model.invalidate +         model +         (Error.new +            Error.IllegalAction +            "SelectCharacter: Wrong team. Attack is not implemented."           ) - +      )  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  apply_to : Model.Type -> Character.Ref -> Model.Type -apply_to model char_id = -   case (Model.get_state model) of -      _ -> (make_it_so model char_id) +apply_to model target_char_id = +   if +   ( +      (UI.get_previous_action model.ui) +      == +      (Just (UI.SelectedCharacter target_char_id)) +   ) +   then +      case (Dict.get target_char_id model.characters) of +         (Just target_char) -> +            case (Model.get_state model) of +               (Model.ControllingCharacter main_char_id) -> +                  (attack_character +                     model +                     main_char_id +                     target_char_id +                     target_char +                  ) + +               _ -> (select_character model target_char_id target_char) + +         Nothing -> +            (Model.invalidate +               model +               (Error.new +                  Error.Programming +                  "SelectCharacter: Unknown char selected." +               ) +            ) +   else +      {model | +         ui = +            (UI.set_previous_action +               model.ui +               (Just (UI.SelectedCharacter target_char_id)) +            ) +      } diff --git a/src/battlemap/src/Model/SelectTile.elm b/src/battlemap/src/Model/SelectTile.elm index 9ad9cdd..3ad7d5d 100644 --- a/src/battlemap/src/Model/SelectTile.elm +++ b/src/battlemap/src/Model/SelectTile.elm @@ -27,15 +27,24 @@ go_to_tile model char_ref loc_ref =           if (loc_ref == (Battlemap.Location.get_ref nav_loc))           then              -- We are already there. -            if (UI.has_just_used_manual_controls model.ui) +            if +            ( +               (UI.get_previous_action model.ui) +               == +               (Just (UI.SelectedLocation loc_ref)) +            )              then +               -- And we just clicked on that tile. +               (Model.EndTurn.apply_to model) +            else                 -- And we didn't just click on that tile.                 {model | -                  ui = (UI.set_has_just_used_manual_controls model.ui False) +                  ui = +                     (UI.set_previous_action +                        model.ui +                        (Just (UI.SelectedLocation loc_ref)) +                     )                 } -            else -               -- And we just clicked on that tile. -               (Model.EndTurn.apply_to model)           else              -- We have to try getting there.              case @@ -60,9 +69,9 @@ go_to_tile model char_ref loc_ref =                    in                       {new_model |                          ui = -                           (UI.set_has_just_used_manual_controls +                           (UI.set_previous_action                                new_model.ui -                              False +                              Nothing                             )                       } diff --git a/src/battlemap/src/UI.elm b/src/battlemap/src/UI.elm index 99d4c5e..8ffc8d2 100644 --- a/src/battlemap/src/UI.elm +++ b/src/battlemap/src/UI.elm @@ -2,6 +2,7 @@ module UI exposing     (        Type,        Tab(..), +      Action(..),        default,        -- Zoom        get_zoom_level, @@ -15,10 +16,17 @@ module UI exposing        get_all_tabs,        -- Manual Controls        has_manual_controls_enabled, -      has_just_used_manual_controls, -      set_has_just_used_manual_controls +      -- Previous Action +      get_previous_action, +      set_previous_action     ) +-- Battlemap ------------------------------------------------------------------- +import Battlemap.Location + +import Character + +  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -27,12 +35,17 @@ type Tab =     | CharactersTab     | SettingsTab +type Action = +   UsedManualControls +   | SelectedLocation Battlemap.Location.Ref +   | SelectedCharacter Character.Ref +  type alias Type =     {        zoom_level : Float,        show_manual_controls : Bool, -      just_used_manual_controls : Bool, -      displayed_tab : (Maybe Tab) +      displayed_tab : (Maybe Tab), +      previous_action : (Maybe Action)     }  -------------------------------------------------------------------------------- @@ -47,8 +60,8 @@ default =     {        zoom_level = 1.0,        show_manual_controls = True, -      just_used_manual_controls = False, -      displayed_tab = (Just StatusTab) +      displayed_tab = (Just StatusTab), +      previous_action = Nothing     }  -- Zoom ------------------------------------------------------------------------ @@ -85,13 +98,6 @@ get_all_tabs =  has_manual_controls_enabled : Type -> Bool  has_manual_controls_enabled ui = ui.show_manual_controls -has_just_used_manual_controls : Type -> Bool -has_just_used_manual_controls ui = ui.just_used_manual_controls - -set_has_just_used_manual_controls : Type -> Bool -> Type -set_has_just_used_manual_controls ui val = -   {ui | just_used_manual_controls = val} -  toggle_manual_controls : Type -> Type  toggle_manual_controls ui =     if (ui.show_manual_controls) @@ -100,5 +106,12 @@ toggle_manual_controls ui =     else        {ui | show_manual_controls = True} -set_enable_toggle_manual_controls : Type -> Bool -> Type -set_enable_toggle_manual_controls ui val = {ui | show_manual_controls = val} +set_enable_manual_controls : Type -> Bool -> Type +set_enable_manual_controls ui val = {ui | show_manual_controls = val} + +-- Previous Action ------------------------------------------------------------- +set_previous_action : Type -> (Maybe Action) -> Type +set_previous_action ui act = {ui | previous_action = act} + +get_previous_action : Type -> (Maybe Action) +get_previous_action ui = ui.previous_action | 


