| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm/battlemap/src/Battlemap')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 15 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Location.elm | 6 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 33 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 4 | 
4 files changed, 42 insertions, 16 deletions
| diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index d14e075..9f519d1 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -9,12 +9,23 @@ import Model exposing (Model)  import Battlemap exposing (Battlemap, random)  import Battlemap.Tile exposing (Tile) +import Battlemap.Direction exposing (..)  view_battlemap_cell : Tile -> (Html Msg)  view_battlemap_cell t =     (td        [] -      [ (text (toString t.floor_level)) ] +      [ +         (text +            (case t.nav_level of +               Right -> "R" +               Left -> "L" +               Up -> "U" +               Down -> "D" +               None -> (toString t.floor_level) +            ) +         ) +      ]     )  type alias GridBuilder = @@ -81,4 +92,4 @@ view_battlemap battlemap =  view : Model -> (Html Msg)  view m = -   (view_battlemap random) +   (view_battlemap m.battlemap) diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm index ffe3f0d..2fa6d5d 100644 --- a/client/elm/battlemap/src/Battlemap/Location.elm +++ b/client/elm/battlemap/src/Battlemap/Location.elm @@ -8,6 +8,8 @@ type alias Location =        y : Int     } +type alias LocationComparable = (Int, Int) +  neighbor : Location -> Direction -> Location  neighbor loc dir =     case dir of @@ -16,3 +18,7 @@ neighbor loc dir =        Up -> {loc | y = (loc.y - 1)}        Down -> {loc | y = (loc.y + 1)}        None -> loc + +to_comparable : Location -> (Int, Int) +to_comparable l = +   (l.x, l.y) diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index ffd52cc..b040676 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -1,16 +1,16 @@  module Battlemap.Navigator exposing (Navigator, new_navigator, go) -import Set exposing (Set, member, empty) +import Set exposing (Set, member, empty, insert) -import Battlemap exposing (Battlemap, has_location) +import Battlemap exposing (Battlemap, has_location, apply_to_tile)  import Battlemap.Location exposing (..)  import Battlemap.Direction exposing (..) -import Battlemap.Tile exposing (set_tile_direction) +import Battlemap.Tile exposing (set_direction)  type alias Navigator =     {        current_location : Location, -      visited_locations : (Set Location) +      visited_locations : (Set LocationComparable)     }  new_navigator : Location -> Navigator @@ -20,7 +20,7 @@ new_navigator start =        visited_locations = empty     } -go : Navigator -> Direction -> (Battlemap, Navigator) +go : Battlemap -> Navigator -> Direction -> (Battlemap, Navigator)  go battlemap nav dir =     let        next_location = (neighbor nav.current_location dir) @@ -28,23 +28,32 @@ go battlemap nav dir =        if        (           (has_location battlemap next_location) -         && (current_location != next_location) -         && (not (member next_location nav.visited_locations)) +         && (nav.current_location /= next_location) +         && (not (member (to_comparable next_location) nav.visited_locations))        )        then           ( -            (set_tile_direction -               nav.current_location -               dir +            (case +               (apply_to_tile +                  battlemap +                  nav.current_location +                  (set_direction dir) +               ) +               of +                  Nothing -> battlemap +                  (Just bmap) -> bmap              ),              {                 current_location = next_location,                 visited_locations =                    (insert -                     nav.current_location +                     (to_comparable nav.current_location)                       nav.visited_locations                    )              }           )        else -         nav +         ( +            battlemap, +            nav +         ) diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index e8f2493..acedfa4 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -13,8 +13,8 @@ type alias Tile =  --      mod_level : Int     } -set_direction : Tile -> Direction -> Tile -set_direction t d = +set_direction : Direction -> Tile -> Tile +set_direction d t =     {t | nav_level = d}  from_int : Int -> Tile | 


