| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/battlemap/src/Battlemap.elm | 9 | ||||
| -rw-r--r-- | src/battlemap/src/Model.elm | 14 | ||||
| -rw-r--r-- | src/battlemap/src/Model/EndTurn.elm | 55 | ||||
| -rw-r--r-- | src/battlemap/src/Model/RequestDirection.elm | 72 | ||||
| -rw-r--r-- | src/battlemap/src/Model/SelectCharacter.elm | 3 | ||||
| -rw-r--r-- | src/battlemap/src/Model/SelectTile.elm | 31 | ||||
| -rw-r--r-- | src/battlemap/src/Shim/Model.elm | 1 | ||||
| -rw-r--r-- | src/battlemap/src/View/Footer/TabMenu/Status.elm | 109 | 
8 files changed, 167 insertions, 127 deletions
| diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm index c524576..96be086 100644 --- a/src/battlemap/src/Battlemap.elm +++ b/src/battlemap/src/Battlemap.elm @@ -6,6 +6,7 @@ module Battlemap exposing        get_tiles,        set_navigator,        clear_navigator_path, +      try_getting_tile_at,        try_getting_navigator_location,        try_getting_navigator_path_to,        try_getting_navigator_summary, @@ -146,6 +147,14 @@ set_navigator start_loc movement_points attack_range character_list bmap =           )     } +try_getting_tile_at : ( +      Type -> +      Battlemap.Location.Type -> +      (Maybe Battlemap.Tile.Type) +   ) +try_getting_tile_at bmap loc = +   (Array.get (location_to_index bmap loc) bmap.content) +  try_adding_step_to_navigator : (        Type ->        (List Character.Type) -> diff --git a/src/battlemap/src/Model.elm b/src/battlemap/src/Model.elm index 45d875a..e463b2f 100644 --- a/src/battlemap/src/Model.elm +++ b/src/battlemap/src/Model.elm @@ -1,7 +1,6 @@  module Model exposing     (        Type, -      Selection(..),        State(..),        get_state,        invalidate, @@ -22,14 +21,9 @@ import Character  type State =     Default -   | MovingCharacterWithButtons -   | MovingCharacterWithClick -   | FocusingTile - -type Selection = -   None -   | SelectedCharacter Character.Ref -   | SelectedTile Battlemap.Location.Ref +   | MovingCharacterWithButtons Character.Ref +   | MovingCharacterWithClick Character.Ref +   | FocusingTile Battlemap.Location.Ref  type alias Type =     { @@ -37,7 +31,6 @@ type alias Type =        battlemap: Battlemap.Type,        characters: (Dict.Dict Character.Ref Character.Type),        error: (Maybe Error.Type), -      selection: Selection,        ui: UI.Type     } @@ -51,7 +44,6 @@ reset model characters =        battlemap = (Battlemap.reset model.battlemap),        characters = characters,        error = Nothing, -      selection = None,        ui = model.ui     } diff --git a/src/battlemap/src/Model/EndTurn.elm b/src/battlemap/src/Model/EndTurn.elm index 441f3b7..9ec76fb 100644 --- a/src/battlemap/src/Model/EndTurn.elm +++ b/src/battlemap/src/Model/EndTurn.elm @@ -10,49 +10,40 @@ import Error  import Model -make_it_so : Model.Type -> Model.Type -make_it_so model = -   case model.selection of -      (Model.SelectedCharacter char_id) -> -         case (Battlemap.try_getting_navigator_location model.battlemap) of -            (Just location) -> -               (Model.reset -                  model -                  (Dict.update -                     char_id -                     (\maybe_char -> -                        case maybe_char of -                           (Just char) -> -                              (Just -                                 (Character.set_location location char) -                              ) -                           Nothing -> Nothing -                     ) -                     model.characters -                  ) -               ) -            Nothing -> -               (Model.invalidate -                  model -                  (Error.new -                     Error.Programming -                     "EndTurn: model moving char, no navigator location." -                  ) +make_it_so : Model.Type -> Character.Ref -> Model.Type +make_it_so model char_ref = +   case (Battlemap.try_getting_navigator_location model.battlemap) of +      (Just location) -> +         (Model.reset +            model +            (Dict.update +               char_ref +               (\maybe_char -> +                  case maybe_char of +                     (Just char) -> +                        (Just +                           (Character.set_location location char) +                        ) +                     Nothing -> Nothing                 ) -      _ -> +               model.characters +            ) +         ) + +      Nothing ->           (Model.invalidate              model              (Error.new                 Error.Programming -               "EndTurn: model moving char, no char selected." +               "EndTurn: model moving char, no navigator location."              )           )  apply_to : Model.Type -> Model.Type  apply_to model =     case (Model.get_state model) of -      Model.MovingCharacterWithButtons -> (make_it_so model) -      Model.MovingCharacterWithClick -> (make_it_so model) +      (Model.MovingCharacterWithButtons char_ref) -> (make_it_so model char_ref) +      (Model.MovingCharacterWithClick char_ref) -> (make_it_so model char_ref)        _ ->           (Model.invalidate              model diff --git a/src/battlemap/src/Model/RequestDirection.elm b/src/battlemap/src/Model/RequestDirection.elm index a8bdce5..f39b4f8 100644 --- a/src/battlemap/src/Model/RequestDirection.elm +++ b/src/battlemap/src/Model/RequestDirection.elm @@ -5,51 +5,51 @@ import Dict  import Battlemap  import Battlemap.Direction +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 -                  (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." -                     ) -                  ) +make_it_so : ( +      Model.Type -> +      Character.Ref -> +      Battlemap.Direction.Type -> +      Model.Type +   ) +make_it_so model char_ref dir = +   let +      new_bmap = +         (Battlemap.try_adding_step_to_navigator +            model.battlemap +            (Dict.values model.characters) +            dir +         ) +   in +      case new_bmap of +         (Just bmap) -> +            {model | +               state = (Model.MovingCharacterWithButtons char_ref), +               battlemap = bmap +            } -      _ -> -         (Model.invalidate -            model -            (Error.new -               Error.Programming -               "DirectionRequest: model moving char, no char selected." +         Nothing -> +            (Model.invalidate +               model +               (Error.new +                  Error.IllegalAction +                  "Unreachable/occupied tile." +               )              ) -         )  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.MovingCharacterWithButtons char_ref) -> +         (make_it_so model char_ref dir) + +      (Model.MovingCharacterWithClick char_ref) -> +         (make_it_so model char_ref dir) +        _ ->           (Model.invalidate              model diff --git a/src/battlemap/src/Model/SelectCharacter.elm b/src/battlemap/src/Model/SelectCharacter.elm index 3795f07..3e6369d 100644 --- a/src/battlemap/src/Model/SelectCharacter.elm +++ b/src/battlemap/src/Model/SelectCharacter.elm @@ -14,8 +14,7 @@ make_it_so model char_id =     case (Dict.get char_id model.characters) of        (Just char) ->              {model | -               state = Model.MovingCharacterWithClick, -               selection = (Model.SelectedCharacter char_id), +               state = (Model.MovingCharacterWithClick char_id),                 battlemap =                    (Battlemap.set_navigator                       (Character.get_location char) diff --git a/src/battlemap/src/Model/SelectTile.elm b/src/battlemap/src/Model/SelectTile.elm index 7cc5dc1..4a9032f 100644 --- a/src/battlemap/src/Model/SelectTile.elm +++ b/src/battlemap/src/Model/SelectTile.elm @@ -4,6 +4,8 @@ import Battlemap  import Battlemap.Direction  import Battlemap.Location +import Character +  import Model.RequestDirection  import Model.EndTurn @@ -14,20 +16,20 @@ autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type  autopilot dir model =     (Model.RequestDirection.apply_to model dir) -go_to_tile : Model.Type -> Battlemap.Location.Ref -> Model.Type -go_to_tile model loc_ref = +go_to_tile : Model.Type -> Character.Ref -> Battlemap.Location.Ref -> Model.Type +go_to_tile model char_ref loc_ref =     case (Battlemap.try_getting_navigator_location model.battlemap) of        (Just nav_loc) ->           if (loc_ref == (Battlemap.Location.get_ref nav_loc))           then              -- We are already there. -            if (model.state == Model.MovingCharacterWithClick) +            if (model.state == (Model.MovingCharacterWithClick char_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 | state = Model.MovingCharacterWithClick} +               {model | state = (Model.MovingCharacterWithClick char_ref)}           else              -- We have to try getting there.              case @@ -50,7 +52,9 @@ go_to_tile model loc_ref =                             path                          )                    in -                     {new_model | state = Model.MovingCharacterWithClick} +                     {new_model | +                        state = (Model.MovingCharacterWithClick char_ref) +                     }                 Nothing -> -- Clicked outside of the range indicator                    (Model.reset model model.characters) @@ -60,13 +64,10 @@ go_to_tile model loc_ref =  apply_to : Model.Type -> Battlemap.Location.Ref -> Model.Type  apply_to model loc_ref =     case (Model.get_state model) of -      Model.MovingCharacterWithButtons -> (go_to_tile model loc_ref) -      Model.MovingCharacterWithClick -> (go_to_tile model loc_ref) -      _ -> -         (Model.invalidate -            model -            (Error.new -               Error.IllegalAction -               "This can only be done while moving a character." -            ) -         ) +      (Model.MovingCharacterWithButtons char_ref) -> +         (go_to_tile model char_ref loc_ref) + +      (Model.MovingCharacterWithClick char_ref) -> +         (go_to_tile model char_ref loc_ref) + +      _ -> {model | state = (Model.FocusingTile loc_ref)} diff --git a/src/battlemap/src/Shim/Model.elm b/src/battlemap/src/Shim/Model.elm index 5169d23..1e63301 100644 --- a/src/battlemap/src/Shim/Model.elm +++ b/src/battlemap/src/Shim/Model.elm @@ -12,7 +12,6 @@ import Shim.Battlemap  generate =     {        state = Model.Default, -      selection = Model.None,        error = Nothing,        battlemap = (Shim.Battlemap.generate),        characters = diff --git a/src/battlemap/src/View/Footer/TabMenu/Status.elm b/src/battlemap/src/View/Footer/TabMenu/Status.elm index bbcf4a6..d5b652c 100644 --- a/src/battlemap/src/View/Footer/TabMenu/Status.elm +++ b/src/battlemap/src/View/Footer/TabMenu/Status.elm @@ -8,6 +8,9 @@ import Html.Attributes  -- Battlemap -------------------------------------------------------------------  import Battlemap +import Battlemap.Location +import Battlemap.Tile +  import Character  import Util.Html @@ -19,28 +22,26 @@ import Model  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -moving_character_text : Model.Type -> String -moving_character_text model = -   case model.selection of -      (Model.SelectedCharacter char_id) -> -         case (Dict.get char_id model.characters) of -            Nothing -> "Error: Unknown character selected." -            (Just char) -> -               ( -                  "Controlling " -                  ++ char.name -                  ++ ": " -                  ++ (toString -                        (Battlemap.get_navigator_remaining_points -                           model.battlemap -                        ) +get_char_info_html : Model.Type -> Character.Ref -> (Html.Html Event.Type) +get_char_info_html model char_ref = +   case (Dict.get char_ref model.characters) of +      Nothing -> (Html.text "Error: Unknown character selected.") +      (Just char) -> +         (Html.text +            ( +               "Controlling " +               ++ char.name +               ++ ": " +               ++ (toString +                     (Battlemap.get_navigator_remaining_points +                        model.battlemap                       ) -                  ++ "/" -                  ++ (toString (Character.get_movement_points char)) -                  ++ " movement points remaining." -               ) - -      _ -> "Error: model.selection does not match its state." +                  ) +               ++ "/" +               ++ (toString (Character.get_movement_points char)) +               ++ " movement points remaining." +            ) +         )  get_error_html : Error.Type -> (Html.Html Event.Type)  get_error_html err = @@ -53,6 +54,54 @@ get_error_html err =        ]     ) +get_tile_info_html : ( +      Model.Type -> +      Battlemap.Location.Type -> +      (Html.Html Event.Type) +   ) +get_tile_info_html model loc = +   case (Battlemap.try_getting_tile_at model.battlemap loc) of +      (Just tile) -> +         (Html.div +            [ +               (Html.Attributes.class +                  "battlemap-footer-tabmenu-content-status-tile-info" +               ) +            ] +            [ +               (Html.div +                  [ +                     (Html.Attributes.class "battlemap-tile-icon"), +                     (Html.Attributes.class "battlemap-tiled"), +                     (Html.Attributes.class +                        ( +                           "asset-tile-" +                           ++ (toString (Battlemap.Tile.get_icon_id tile)) +                        ) +                     ) +                  ] +                  [ +                  ] +               ), +               (Html.div +                  [ +                  ] +                  [ +                     (Html.text +                        ( +                           "Focusing tile (" +                           ++ (toString loc.x) +                           ++ ", " +                           ++ (toString loc.y) +                           ++ ")." +                        ) +                     ) +                  ] +               ) +            ] +         ) + +      Nothing -> (Html.text "Error: Unknown tile location selected.")  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -68,16 +117,16 @@ get_html model =              (Just error) -> (get_error_html error)              Nothing -> Util.Html.nothing           ), -         (Html.text -            (case model.state of -               Model.Default -> "Click on a character to control it." -               Model.FocusingTile -> "Error: Unimplemented." -               Model.MovingCharacterWithButtons -> -                  (moving_character_text model) +         (case model.state of +            Model.Default -> (Html.text "Click on a character to control it.") +            (Model.FocusingTile tile_loc) -> +               (get_tile_info_html model (Battlemap.Location.from_ref tile_loc)) -               Model.MovingCharacterWithClick -> -                  (moving_character_text model) -            ) +            (Model.MovingCharacterWithButtons char_ref) -> +               (get_char_info_html model char_ref) + +            (Model.MovingCharacterWithClick char_ref) -> +               (get_char_info_html model char_ref)           )        ]     ) | 


