| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm/battlemap/src/Battlemap')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 69 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Location.elm | 4 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 30 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 44 | 
4 files changed, 103 insertions, 44 deletions
diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index 9f519d1..dc90ed4 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -1,32 +1,57 @@  module Battlemap.Html exposing (view)  import Html exposing (Html, text, table, tr, td) +import Html.Events exposing (onClick) +  -- import List as Lt exposing (map)  import Array as Ay exposing (foldr) -import Update exposing (Msg) +import Update exposing (Msg(..))  import Model exposing (Model)  import Battlemap exposing (Battlemap, random)  import Battlemap.Tile exposing (Tile) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..))  view_battlemap_cell : Tile -> (Html Msg)  view_battlemap_cell t = -   (td -      [] -      [ -         (text -            (case t.nav_level of -               Right -> "R" -               Left -> "L" -               Up -> "U" -               Down -> "D" -               None -> (toString t.floor_level) -            ) +   case t.char_level of +      Nothing -> +         (td +            [] +            [ +               (text "[_]"), +               (text +                  ( +                     (case t.nav_level of +                        Right -> "R" +                        Left -> "L" +                        Up -> "U" +                        Down -> "D" +                        None -> (toString t.floor_level) +                     ) +                  ) +               ) +            ] +         ) +      (Just char_id) -> +         (td +            [ (onClick (SelectCharacter char_id)) ] +            [ +               (text ("[" ++ char_id ++ "]")), +               (text +                  ( +                     (case t.nav_level of +                        Right -> "R" +                        Left -> "L" +                        Up -> "U" +                        Down -> "D" +                        None -> (toString t.floor_level) +                     ) +                  ) +               ) +            ]           ) -      ] -   )  type alias GridBuilder =     { @@ -37,21 +62,21 @@ type alias GridBuilder =     }  foldr_to_html : Tile -> GridBuilder -> GridBuilder -foldr_to_html t bg = -   if (bg.row_size == bg.bmap.width) +foldr_to_html t gb = +   if (gb.row_size == gb.bmap.width)     then -      {bg | +      {gb |           row = [(view_battlemap_cell t)],           row_size = 1,           columns =              ( -               (tr [] bg.row) :: bg.columns +               (tr [] gb.row) :: gb.columns              )        }     else -      {bg | -         row = ((view_battlemap_cell t) :: bg.row), -         row_size = (bg.row_size + 1) +      {gb | +         row = ((view_battlemap_cell t) :: gb.row), +         row_size = (gb.row_size + 1)        }  grid_builder_to_html : GridBuilder -> (List (Html Msg)) diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm index 2fa6d5d..5c7bc48 100644 --- a/client/elm/battlemap/src/Battlemap/Location.elm +++ b/client/elm/battlemap/src/Battlemap/Location.elm @@ -1,6 +1,6 @@  module Battlemap.Location exposing (..) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..))  type alias Location =     { @@ -8,7 +8,7 @@ type alias Location =        y : Int     } -type alias LocationComparable = (Int, Int) +type alias LocationRef = (Int, Int)  neighbor : Location -> Direction -> Location  neighbor loc dir = diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index b040676..df0e2cf 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -1,16 +1,29 @@ -module Battlemap.Navigator exposing (Navigator, new_navigator, go) +module Battlemap.Navigator exposing +   ( +      Navigator, +      new_navigator, +      reset_navigation, +      go +   )  import Set exposing (Set, member, empty, insert)  import Battlemap exposing (Battlemap, has_location, apply_to_tile) -import Battlemap.Location exposing (..) -import Battlemap.Direction exposing (..) -import Battlemap.Tile exposing (set_direction) +import Battlemap.Direction exposing (Direction(..)) +import Battlemap.Tile exposing (Tile, set_direction) + +import Battlemap.Location exposing +   ( +      Location, +      LocationRef, +      neighbor, +      to_comparable +   )  type alias Navigator =     {        current_location : Location, -      visited_locations : (Set LocationComparable) +      visited_locations : (Set LocationRef)     }  new_navigator : Location -> Navigator @@ -20,6 +33,13 @@ new_navigator start =        visited_locations = empty     } + +reset_navigation : Tile -> Tile +reset_navigation t = +   {t | +      nav_level = None +   } +  go : Battlemap -> Navigator -> Direction -> (Battlemap, Navigator)  go battlemap nav dir =     let diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index acedfa4..70268bf 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -1,28 +1,42 @@  module Battlemap.Tile exposing (Tile, generate, set_direction) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..)) +import Character exposing (CharacterRef)  import List exposing (map)  import Array exposing (Array, fromList) +import Set exposing (Set)  type alias Tile =     {        floor_level : Int, -      nav_level : Direction ---      char_level : Int, ---      mod_level : Int +      nav_level : Direction, +      char_level : (Maybe CharacterRef) +--    mod_level : (Set TileModifier)     }  set_direction : Direction -> Tile -> Tile  set_direction d t = -   {t | nav_level = d} +   {t | +      nav_level = d +   }  from_int : Int -> Tile  from_int i = -   { -      floor_level = i, -      nav_level = None -   } +   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 = @@ -30,12 +44,12 @@ generate width height =        (map           (from_int)           [ -            1, 1, 1, 2, 2, 2, -            1, 0, 0, 0, 0, 2, -            1, 0, 1, 2, 0, 2, -            3, 0, 3, 4, 0, 4, -            3, 0, 0, 0, 0, 4, -            3, 3, 3, 4, 4, 4 +            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           ]        )     )  | 


