From c9786fd27954c79faf901963003a8b7b3131ca4c Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 15 Sep 2017 17:41:07 +0200 Subject: Adds UI to test the Navigator. --- client/elm/battlemap/src/Battlemap/Navigator.elm | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'client/elm/battlemap/src/Battlemap/Navigator.elm') 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 + ) -- cgit v1.2.3-70-g09d2