| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm/battlemap/src/Battlemap')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Direction.elm | 6 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 75 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Location.elm | 22 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 88 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 51 | 
5 files changed, 106 insertions, 136 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/Direction.elm b/client/elm/battlemap/src/Battlemap/Direction.elm index e301177..5aad141 100644 --- a/client/elm/battlemap/src/Battlemap/Direction.elm +++ b/client/elm/battlemap/src/Battlemap/Direction.elm @@ -1,13 +1,13 @@ -module Battlemap.Direction exposing (Direction(..), opposite_of) +module Battlemap.Direction exposing (Type(..), opposite_of) -type Direction = +type Type =     None     | Left     | Right     | Up     | Down -opposite_of : Direction -> Direction +opposite_of : Type -> Type  opposite_of d =     case d of        Left -> Right diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index dc90ed4..01937e0 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -1,52 +1,51 @@  module Battlemap.Html exposing (view) -import Html exposing (Html, text, table, tr, td) -import Html.Events exposing (onClick) +import Array --- import List as Lt exposing (map) -import Array as Ay exposing (foldr) +import Html +import Html.Events -import Update exposing (Msg(..)) -import Model exposing (Model) +import Battlemap +import Battlemap.Tile +import Battlemap.Direction -import Battlemap exposing (Battlemap, random) -import Battlemap.Tile exposing (Tile) -import Battlemap.Direction exposing (Direction(..)) +import Update +import Model -view_battlemap_cell : Tile -> (Html Msg) +view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Update.Type)  view_battlemap_cell t =     case t.char_level of        Nothing -> -         (td +         (Html.td              []              [ -               (text "[_]"), -               (text +               (Html.text "[_]"), +               (Html.text                    (                       (case t.nav_level of -                        Right -> "R" -                        Left -> "L" -                        Up -> "U" -                        Down -> "D" -                        None -> (toString t.floor_level) +                        Battlemap.Direction.Right -> "R" +                        Battlemap.Direction.Left -> "L" +                        Battlemap.Direction.Up -> "U" +                        Battlemap.Direction.Down -> "D" +                        Battlemap.Direction.None -> (toString t.floor_level)                       )                    )                 )              ]           )        (Just char_id) -> -         (td -            [ (onClick (SelectCharacter char_id)) ] +         (Html.td +            [ (Html.Events.onClick (Update.SelectCharacter char_id)) ]              [ -               (text ("[" ++ char_id ++ "]")), -               (text +               (Html.text ("[" ++ char_id ++ "]")), +               (Html.text                    (                       (case t.nav_level of -                        Right -> "R" -                        Left -> "L" -                        Up -> "U" -                        Down -> "D" -                        None -> (toString t.floor_level) +                        Battlemap.Direction.Right -> "R" +                        Battlemap.Direction.Left -> "L" +                        Battlemap.Direction.Up -> "U" +                        Battlemap.Direction.Down -> "D" +                        Battlemap.Direction.None -> (toString t.floor_level)                       )                    )                 ) @@ -55,13 +54,13 @@ view_battlemap_cell t =  type alias GridBuilder =     { -      row : (List (Html Msg)), -      columns : (List (Html Msg)), +      row : (List (Html.Html Update.Type)), +      columns : (List (Html.Html Update.Type)),        row_size : Int, -      bmap : Battlemap +      bmap : Battlemap.Type     } -foldr_to_html : Tile -> GridBuilder -> GridBuilder +foldr_to_html : Battlemap.Tile.Type -> GridBuilder -> GridBuilder  foldr_to_html t gb =     if (gb.row_size == gb.bmap.width)     then @@ -70,7 +69,7 @@ foldr_to_html t gb =           row_size = 1,           columns =              ( -               (tr [] gb.row) :: gb.columns +               (Html.tr [] gb.row) :: gb.columns              )        }     else @@ -79,7 +78,7 @@ foldr_to_html t gb =           row_size = (gb.row_size + 1)        } -grid_builder_to_html : GridBuilder -> (List (Html Msg)) +grid_builder_to_html : GridBuilder -> (List (Html.Html Update.Type))  grid_builder_to_html gb =     if (gb.row_size == 0)     then @@ -91,17 +90,17 @@ grid_builder_to_html gb =              row_size = 0,              columns =                 ( -                  (tr [] gb.row) :: gb.columns +                  (Html.tr [] gb.row) :: gb.columns                 )           }        ) -view_battlemap : Battlemap -> (Html Msg) +view_battlemap : Battlemap.Type -> (Html.Html Update.Type)  view_battlemap battlemap = -   (table +   (Html.table        []        (grid_builder_to_html -         (Ay.foldr +         (Array.foldr              (foldr_to_html)              {                 row = [], @@ -115,6 +114,6 @@ view_battlemap battlemap =     ) -view : Model -> (Html Msg) +view : Model.Type -> (Html.Html Update.Type)  view m =     (view_battlemap m.battlemap) diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm index 5c7bc48..4f70e49 100644 --- a/client/elm/battlemap/src/Battlemap/Location.elm +++ b/client/elm/battlemap/src/Battlemap/Location.elm @@ -1,24 +1,24 @@  module Battlemap.Location exposing (..) -import Battlemap.Direction exposing (Direction(..)) +import Battlemap.Direction -type alias Location = +type alias Type =     {        x : Int,        y : Int     } -type alias LocationRef = (Int, Int) +type alias Ref = (Int, Int) -neighbor : Location -> Direction -> Location +neighbor : Type -> Battlemap.Direction.Type -> Type  neighbor loc dir =     case dir of -      Right -> {loc | x = (loc.x + 1)} -      Left -> {loc | x = (loc.x - 1)} -      Up -> {loc | y = (loc.y - 1)} -      Down -> {loc | y = (loc.y + 1)} -      None -> loc +      Battlemap.Direction.Right -> {loc | x = (loc.x + 1)} +      Battlemap.Direction.Left -> {loc | x = (loc.x - 1)} +      Battlemap.Direction.Up -> {loc | y = (loc.y - 1)} +      Battlemap.Direction.Down -> {loc | y = (loc.y + 1)} +      Battlemap.Direction.None -> loc -to_comparable : Location -> (Int, Int) -to_comparable l = +get_ref : Type -> Ref +get_ref l =     (l.x, l.y) diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index 3cabf8e..41593c5 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -1,81 +1,87 @@  module Battlemap.Navigator exposing     ( -      Navigator, +      Type,        new_navigator,        reset_navigation,        go     ) -import Set exposing (Set, member, empty, insert, remove) -import List as Lt exposing (head, tail) +import Set -- exposing (Set, member, empty, insert, remove) +import List -- exposing (head, tail) -import Battlemap exposing (Battlemap, has_location, apply_to_tile) -import Battlemap.Direction exposing (Direction(..), opposite_of) -import Battlemap.Tile exposing (Tile, set_direction) -import Character exposing (Character) +import Battlemap +import Battlemap.Direction +import Battlemap.Location +import Battlemap.Tile -import Battlemap.Location exposing -   ( -      Location, -      LocationRef, -      neighbor, -      to_comparable -   ) +import Character -type alias Navigator = +type alias Type =     { -      current_location : Location, -      visited_locations : (Set LocationRef), -      previous_directions : (List Direction), +      current_location : Battlemap.Location.Type, +      visited_locations : (Set.Set Battlemap.Location.Ref), +      previous_directions : (List Battlemap.Direction.Type),        remaining_points : Int     } -new_navigator : Location -> Int -> Navigator +new_navigator : Battlemap.Location.Type -> Int -> Type  new_navigator start points =     {        current_location = start, -      visited_locations = empty, +      visited_locations = Set.empty,        previous_directions = [],        remaining_points = points     } -reset_navigation : Tile -> Tile +reset_navigation : Battlemap.Tile.Type -> Battlemap.Tile.Type  reset_navigation t =     {t | -      nav_level = None +      nav_level = Battlemap.Direction.None     } -go : Battlemap -> Navigator -> Direction -> (List Character) -> (Battlemap, Navigator) +go : ( +      Battlemap.Type -> +      Type -> +      Battlemap.Direction.Type -> +      (List Character.Type) -> +      (Battlemap.Type, Type) +   )  go battlemap nav dir char_list =     let -      next_location = (neighbor nav.current_location dir) -      is_occupied = (Lt.any (\c -> (c.location == next_location)) char_list) +      next_location = (Battlemap.Location.neighbor nav.current_location dir) +      is_occupied = (List.any (\c -> (c.location == next_location)) char_list)     in        if        (           (not is_occupied)           && (nav.remaining_points > 0) -         && (has_location battlemap next_location) +         && (Battlemap.has_location battlemap next_location)           && (nav.current_location /= next_location) -         && (not (member (to_comparable next_location) nav.visited_locations)) +         && +         (not +            (Set.member +               (Battlemap.Location.get_ref next_location) +               nav.visited_locations +            ) +         )        )        then           (              (case -               (apply_to_tile +               (Battlemap.apply_to_tile                    battlemap                    nav.current_location -                  (set_direction dir) +                  (Battlemap.Tile.set_direction dir)                 )                 of                    Nothing -> battlemap                    (Just bmap0) ->                       (case -                        (apply_to_tile +                        (Battlemap.apply_to_tile                             bmap0                             next_location -                           (set_direction dir) +                           (Battlemap.Tile.set_direction dir)                          )                       of                          Nothing -> battlemap @@ -85,8 +91,8 @@ go battlemap nav dir char_list =              {nav |                 current_location = next_location,                 visited_locations = -                  (insert -                     (to_comparable nav.current_location) +                  (Set.insert +                     (Battlemap.Location.get_ref nav.current_location)                       nav.visited_locations                    ),                 previous_directions = (dir :: nav.previous_directions), @@ -97,21 +103,23 @@ go battlemap nav dir char_list =        then           case              ( -               (Lt.head nav.previous_directions), -               (Lt.tail nav.previous_directions) +               (List.head nav.previous_directions), +               (List.tail nav.previous_directions)              )           of              (Nothing, _) -> (battlemap, nav)              (_ , Nothing) -> (battlemap, nav)              ((Just prev_dir), (Just prev_dir_list)) -> -               if (dir == (opposite_of prev_dir)) +               if (dir == (Battlemap.Direction.opposite_of prev_dir))                 then                    (                       (case -                        (apply_to_tile +                        (Battlemap.apply_to_tile                             battlemap                             nav.current_location -                           (set_direction None) +                           (Battlemap.Tile.set_direction +                              Battlemap.Direction.None +                           )                          )                          of                             Nothing -> battlemap @@ -120,8 +128,8 @@ go battlemap nav dir char_list =                       {nav |                          current_location = next_location,                          visited_locations = -                           (remove -                              (to_comparable next_location) +                           (Set.remove +                              (Battlemap.Location.get_ref next_location)                                nav.visited_locations                             ),                          previous_directions = prev_dir_list, diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index 70268bf..dca7a64 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -1,55 +1,18 @@ -module Battlemap.Tile exposing (Tile, generate, set_direction) +module Battlemap.Tile exposing (Type, set_direction) -import Battlemap.Direction exposing (Direction(..)) -import Character exposing (CharacterRef) +import Battlemap.Direction +import Character -import List exposing (map) -import Array exposing (Array, fromList) -import Set exposing (Set) - -type alias Tile = +type alias Type =     {        floor_level : Int, -      nav_level : Direction, -      char_level : (Maybe CharacterRef) +      nav_level : Battlemap.Direction.Type, +      char_level : (Maybe Character.Ref)  --    mod_level : (Set TileModifier)     } -set_direction : Direction -> Tile -> Tile +set_direction : Battlemap.Direction.Type -> Type -> Type  set_direction d t =     {t |        nav_level = d     } - -from_int : Int -> Tile -from_int i = -   if (i >= 10) -   then -      { -         floor_level = (i - 10), -         nav_level = None, -         char_level = (Just (toString (i - 10))) -      } -   else -      { -         floor_level = i, -         nav_level = None, -         char_level = Nothing -      } - - -generate : Int -> Int -> (Array Tile) -generate width height = -   (fromList -      (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 -         ] -      ) -   ) | 


