| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm/battlemap/src')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 19 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/RangeIndicator.elm | 66 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 24 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Shim/Battlemap.elm | 4 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Shim/Battlemap/Tile.elm | 121 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Shim/Model.elm | 10 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/EndTurn.elm | 2 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update/SelectCharacter.elm | 65 | 
8 files changed, 225 insertions, 86 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index e474901..f67bdf0 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -35,7 +35,13 @@ view_battlemap_cell t =           (Html.td              []              [ -               (Html.text "[_]"), +               (Html.text +                  (case t.mod_level of +                     Nothing -> "[_]" +                     (Just Battlemap.Tile.CanBeReached) -> "[M]" +                     (Just Battlemap.Tile.CanBeAttacked) -> "[A]" +                  ) +               ),                 (Html.text (nav_level_to_text t))              ]           ) @@ -73,16 +79,7 @@ grid_builder_to_html gb =     then        gb.columns     else -      (grid_builder_to_html -         {gb | -            row = [], -            row_size = 0, -            columns = -               ( -                  (Html.tr [] gb.row) :: gb.columns -               ) -         } -      ) +     ((Html.tr [] gb.row) :: gb.columns)  view : Battlemap.Type -> (Html.Html Update.Type)  view battlemap = diff --git a/client/elm/battlemap/src/Battlemap/RangeIndicator.elm b/client/elm/battlemap/src/Battlemap/RangeIndicator.elm index 3311f42..d6c00cc 100644 --- a/client/elm/battlemap/src/Battlemap/RangeIndicator.elm +++ b/client/elm/battlemap/src/Battlemap/RangeIndicator.elm @@ -2,6 +2,7 @@ module Battlemap.RangeIndicator exposing (Type, generate)  import Dict  import List +import Debug  import Battlemap  import Battlemap.Direction @@ -16,41 +17,56 @@ type alias Type =        node_cost: Int     } -generate_grid : ( +generate_row : (        Battlemap.Location.Type ->        Int ->        Int ->        Int -> +      (List Battlemap.Location.Type) -> +      (List Battlemap.Location.Type) +   ) +generate_row src max_x_mod curr_y curr_x_mod curr_row = +   if (curr_x_mod > max_x_mod) +   then +      curr_row +   else +      (generate_row +         src +         max_x_mod +         curr_y +         (curr_x_mod + 1) +         ({x = (src.x + curr_x_mod), y = curr_y} :: curr_row) +      ) + +generate_grid : ( +      Battlemap.Location.Type -> +      Int ->        Int ->        (List Battlemap.Location.Type) ->        (List Battlemap.Location.Type)     ) -generate_grid src max_dist curr_dist curr_y_mod curr_x_mod curr_list = -   if (curr_x_mod > curr_dist) +generate_grid src dist curr_y_mod curr_list = +   if (curr_y_mod > dist)     then -      if (curr_y_mod > max_dist) -      then -         curr_list -      else -         let -            new_limit = (max_dist - (abs curr_y_mod)) -         in -         (generate_grid -            src -            max_dist -            new_limit -            (curr_y_mod + 1) -            (-new_limit) -            curr_list -         ) +      curr_list     else +      let +         new_limit = (dist - (abs curr_y_mod)) +      in           (generate_grid              src -            max_dist -            curr_dist -            curr_y_mod -            (curr_x_mod + 1) -            ({x = (src.x + curr_x_mod), y = (src.y + curr_y_mod)} :: curr_list) +            dist +            (curr_y_mod + 1) +            ( +               (generate_row +                  src +                  new_limit +                  (src.y + curr_y_mod) +                  (-new_limit) +                  [] +               ) +               ++ curr_list +            )           )  get_closest : ( @@ -118,7 +134,7 @@ search : (        (Dict.Dict Battlemap.Location.Ref Type)     )  search result remaining dist = -   if (Dict.isEmpty remaining) +   if (Dict.isEmpty (Debug.log "Search call" remaining))     then        result     else @@ -207,7 +223,7 @@ generate battlemap location dist =           battlemap           location           dist -         (generate_grid location dist 0 (-dist) (-dist) []) +         (generate_grid location dist (-dist) [])           Dict.empty        )        dist diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index 068ee30..6d2a65b 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -1,14 +1,25 @@ -module Battlemap.Tile exposing (Type, set_direction, set_navigation) +module Battlemap.Tile exposing +   ( +      Type, +      TileModifier(..), +      set_direction, +      set_navigation, +      reset_tile +   )  import Battlemap.Direction  import Character +type TileModifier = +   CanBeReached +   | CanBeAttacked +  type alias Type =     {        floor_level : Int,        nav_level : Battlemap.Direction.Type, -      char_level : (Maybe Character.Ref) ---    mod_level : (Set TileModifier) +      char_level : (Maybe Character.Ref), +      mod_level : (Maybe TileModifier)     }  set_direction : Battlemap.Direction.Type -> Type -> Type @@ -22,3 +33,10 @@ set_navigation dir t =     {t |        nav_level = dir     } + +reset_tile : Type -> Type +reset_tile t = +   {t | +      nav_level = Battlemap.Direction.None, +      mod_level = Nothing +   } diff --git a/client/elm/battlemap/src/Shim/Battlemap.elm b/client/elm/battlemap/src/Shim/Battlemap.elm index 820ceec..2f795e1 100644 --- a/client/elm/battlemap/src/Shim/Battlemap.elm +++ b/client/elm/battlemap/src/Shim/Battlemap.elm @@ -5,7 +5,7 @@ import Shim.Battlemap.Tile  --generate : Battlemap.Type  generate =     { -      width = 6, -      height = 6, +      width = 32, +      height = 32,        content = (Shim.Battlemap.Tile.generate)     } diff --git a/client/elm/battlemap/src/Shim/Battlemap/Tile.elm b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm index e3ab7bb..55feb14 100644 --- a/client/elm/battlemap/src/Shim/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm @@ -13,28 +13,119 @@ from_int i =        {           floor_level = (i - 10),           nav_level = Battlemap.Direction.None, -         char_level = (Just (toString (i - 10))) +         char_level = (Just (toString (i - 10))), +         mod_level = Nothing        }     else        {           floor_level = i,           nav_level = Battlemap.Direction.None, -         char_level = Nothing +         char_level = Nothing, +         mod_level = Nothing        }  generate : (Array.Array Battlemap.Tile.Type)  generate = -   (Array.fromList -      (List.map -         (from_int) -         [ -            10,   1,    1,    2,    2,    2, -            1,    0,    0,    0,    11,   2, -            1,    0,    1,    2,    0,    2, -            3,    0,    3,    4,    0,    4, -            3,    12,   0,    0,    0,    4, -            3,    3,    3,    4,    4,    4 -         ] -      ) -   ) +   let +      as_int_list = +         ( +            [ +              10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [ +              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +            ++ [  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +            ] +         ) +      as_list = (List.map (from_int) as_int_list) +   in +      (Array.fromList as_list) diff --git a/client/elm/battlemap/src/Shim/Model.elm b/client/elm/battlemap/src/Shim/Model.elm index 0371b53..4a0146d 100644 --- a/client/elm/battlemap/src/Shim/Model.elm +++ b/client/elm/battlemap/src/Shim/Model.elm @@ -20,8 +20,8 @@ generate =                 name = "Char2",                 icon = "Icon2",                 portrait = "Portrait2", -               location = {x = 1, y = 4}, -               movement_points = 6 +               location = {x = 0, y = 1}, +               movement_points = 5              }              (Dict.insert                 "1" @@ -30,8 +30,8 @@ generate =                    name = "Char1",                    icon = "Icon1",                    portrait = "Portrait1", -                  location = {x = 4, y = 1}, -                  movement_points = 10 +                  location = {x = 1, y = 0}, +                  movement_points = 4                 }                 (Dict.insert                    "0" @@ -41,7 +41,7 @@ generate =                       icon = "Icon0",                       portrait = "Portrait0",                       location = {x = 0, y = 0}, -                     movement_points = 16 +                     movement_points = 3                    }                    Dict.empty                 ) diff --git a/client/elm/battlemap/src/Update/EndTurn.elm b/client/elm/battlemap/src/Update/EndTurn.elm index 2e02d19..3490d57 100644 --- a/client/elm/battlemap/src/Update/EndTurn.elm +++ b/client/elm/battlemap/src/Update/EndTurn.elm @@ -27,7 +27,7 @@ update_model model nav char_id =                       nav.current_location                       (\t -> {t | char_level = (Just char_id)})                    ) -                  (Battlemap.Tile.set_navigation Battlemap.Direction.None) +                  (Battlemap.Tile.reset_tile)                 ),              characters =                 (Dict.update diff --git a/client/elm/battlemap/src/Update/SelectCharacter.elm b/client/elm/battlemap/src/Update/SelectCharacter.elm index 7ee8dfa..c8a0ddb 100644 --- a/client/elm/battlemap/src/Update/SelectCharacter.elm +++ b/client/elm/battlemap/src/Update/SelectCharacter.elm @@ -6,40 +6,57 @@ import Character  import Battlemap  import Battlemap.Direction +import Battlemap.Location  import Battlemap.Navigator  import Battlemap.Tile  import Battlemap.RangeIndicator  import Model +display_range : ( +      Battlemap.Location.Ref -> +      Battlemap.RangeIndicator.Type -> +      Battlemap.Type -> +      Battlemap.Type +   ) +display_range loc_ref indicator bmap = +   (Battlemap.apply_to_tile_unsafe +      bmap +      (Battlemap.Location.from_ref loc_ref) +      (\e -> {e | mod_level = (Just Battlemap.Tile.CanBeReached)}) +   ) + +  apply_to : Model.Type -> Character.Ref -> Model.Type  apply_to model char_id = -   {model | -      selection = (Just char_id), -      battlemap = -         (Battlemap.apply_to_all_tiles -            model.battlemap -            (Battlemap.Tile.set_navigation Battlemap.Direction.None) -         ), -      navigator = -         (case (Dict.get char_id model.characters) of -            Nothing -> Nothing -            (Just char) -> -               (Just -                  (Battlemap.Navigator.new_navigator -                     char.location -                     char.movement_points -                  ) -               ) -         ), -      range_indicator = -         (case (Dict.get char_id model.characters) of -            Nothing -> Dict.empty -            (Just char) -> +   case (Dict.get char_id model.characters) of +      Nothing -> model +      (Just char) -> +         let +            new_range_indicator =                 (Battlemap.RangeIndicator.generate                    model.battlemap                    char.location                    char.movement_points                 ) -         ) -   } +         in +            {model | +               selection = (Just char_id), +               battlemap = +                  (Battlemap.apply_to_all_tiles +                     (Dict.foldl +                        (display_range) +                        model.battlemap +                        new_range_indicator +                     ) +                     (Battlemap.Tile.set_navigation Battlemap.Direction.None) +                  ), +               navigator = +                  (Just +                     (Battlemap.Navigator.new_navigator +                        char.location +                        char.movement_points +                     ) +                  ), +               range_indicator = new_range_indicator +            } | 


