| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 17:41:07 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 17:41:07 +0200 | 
| commit | c9786fd27954c79faf901963003a8b7b3131ca4c (patch) | |
| tree | 85919cf11c2e54908cfeeebe59acf03283f131c8 /client/elm/battlemap/src/Battlemap/Navigator.elm | |
| parent | 9a2d8f37dea8e14afa57affb135def13954df547 (diff) | |
Adds UI to test the Navigator.
Diffstat (limited to 'client/elm/battlemap/src/Battlemap/Navigator.elm')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 33 | 
1 files changed, 21 insertions, 12 deletions
| 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 +         ) | 


