summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-22 14:35:25 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-22 14:35:25 +0200 |
commit | 16abf2b1e598cb89a1d4251c2313e6f2e165f7da (patch) | |
tree | 403fcc9802772a54fe006f883addd4a8b3b49d16 | |
parent | 2d20dc042a386bc9f66bc5f535403227f9acf1b1 (diff) |
Clears up Update.elm a bit.
-rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 58 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update.elm | 104 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/DirectionRequest.elm | 28 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/EndTurn.elm | 48 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/SelectCharacter.elm | 32 | ||||
-rw-r--r-- | client/elm/battlemap/src/View.elm | 5 |
6 files changed, 139 insertions, 136 deletions
diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index 01937e0..e474901 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -10,7 +10,23 @@ import Battlemap.Tile import Battlemap.Direction import Update -import Model + +type alias GridBuilder = + { + row : (List (Html.Html Update.Type)), + columns : (List (Html.Html Update.Type)), + row_size : Int, + bmap : Battlemap.Type + } + +nav_level_to_text : Battlemap.Tile.Type -> String +nav_level_to_text t = + case t.nav_level of + Battlemap.Direction.Right -> "R" + Battlemap.Direction.Left -> "L" + Battlemap.Direction.Up -> "U" + Battlemap.Direction.Down -> "D" + Battlemap.Direction.None -> (toString t.floor_level) view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Update.Type) view_battlemap_cell t = @@ -20,17 +36,7 @@ view_battlemap_cell t = [] [ (Html.text "[_]"), - (Html.text - ( - (case t.nav_level of - Battlemap.Direction.Right -> "R" - Battlemap.Direction.Left -> "L" - Battlemap.Direction.Up -> "U" - Battlemap.Direction.Down -> "D" - Battlemap.Direction.None -> (toString t.floor_level) - ) - ) - ) + (Html.text (nav_level_to_text t)) ] ) (Just char_id) -> @@ -38,27 +44,10 @@ view_battlemap_cell t = [ (Html.Events.onClick (Update.SelectCharacter char_id)) ] [ (Html.text ("[" ++ char_id ++ "]")), - (Html.text - ( - (case t.nav_level of - Battlemap.Direction.Right -> "R" - Battlemap.Direction.Left -> "L" - Battlemap.Direction.Up -> "U" - Battlemap.Direction.Down -> "D" - Battlemap.Direction.None -> (toString t.floor_level) - ) - ) - ) + (Html.text (nav_level_to_text t)) ] ) -type alias GridBuilder = - { - row : (List (Html.Html Update.Type)), - columns : (List (Html.Html Update.Type)), - row_size : Int, - bmap : Battlemap.Type - } foldr_to_html : Battlemap.Tile.Type -> GridBuilder -> GridBuilder foldr_to_html t gb = @@ -95,8 +84,8 @@ grid_builder_to_html gb = } ) -view_battlemap : Battlemap.Type -> (Html.Html Update.Type) -view_battlemap battlemap = +view : Battlemap.Type -> (Html.Html Update.Type) +view battlemap = (Html.table [] (grid_builder_to_html @@ -112,8 +101,3 @@ view_battlemap battlemap = ) ) ) - - -view : Model.Type -> (Html.Html Update.Type) -view m = - (view_battlemap m.battlemap) diff --git a/client/elm/battlemap/src/Update.elm b/client/elm/battlemap/src/Update.elm index 2abddb5..5c97ab8 100644 --- a/client/elm/battlemap/src/Update.elm +++ b/client/elm/battlemap/src/Update.elm @@ -2,6 +2,10 @@ module Update exposing (update, Type(..)) import Model +import Update.DirectionRequest +import Update.SelectCharacter +import Update.EndTurn + import Battlemap import Battlemap.Direction import Battlemap.Navigator @@ -15,104 +19,14 @@ type Type = | SelectCharacter Character.Ref | EndTurn -handle_direction_request : ( - Model.Type -> - Battlemap.Direction.Type -> - Model.Type - ) -handle_direction_request model dir = - (case (model.selection, model.navigator) of - (Nothing, _) -> model - (_ , Nothing) -> model - ((Just char_id), (Just nav)) -> - let - (new_bmap, new_nav) = - (Battlemap.Navigator.go - model.battlemap - nav - dir - (Dict.values model.characters) - ) - in - {model | - battlemap = new_bmap, - navigator = (Just new_nav) - } - ) - -handle_select_character : Model.Type -> Character.Ref -> Model.Type -handle_select_character model char_id = - {model | - selection = (Just char_id), - battlemap = - (Battlemap.apply_to_all_tiles - model.battlemap - (Battlemap.Navigator.reset_navigation) - ), - navigator = - (case (Dict.get char_id model.characters) of - Nothing -> Nothing - (Just char) -> - (Just - (Battlemap.Navigator.new_navigator - char.location - char.movement_points - ) - ) - ) - } - -handle_end_turn : Model.Type -> Model.Type -handle_end_turn model = - case (model.navigator, model.selection) of - (_, Nothing) -> model - (Nothing, _) -> model - ((Just nav), (Just char_id)) -> - (case (Dict.get char_id model.characters) of - Nothing -> model - (Just char) -> - {model | - navigator = - (Just - (Battlemap.Navigator.new_navigator - nav.current_location - char.movement_points - ) - ), - battlemap = - (Battlemap.apply_to_all_tiles - (Battlemap.apply_to_tile_unsafe - (Battlemap.apply_to_tile_unsafe - model.battlemap - char.location - (\t -> {t | char_level = Nothing}) - ) - nav.current_location - (\t -> {t | char_level = (Just char_id)}) - ) - (Battlemap.Navigator.reset_navigation) - ), - characters = - (Dict.update - char_id - (\mc -> - case mc of - Nothing -> Nothing - (Just c) -> - (Just {c | location = nav.current_location}) - ) - model.characters - ) - } - ) - update : Type -> Model.Type -> Model.Type update msg model = case msg of (DirectionRequest d) -> - (handle_direction_request model d) + (Update.DirectionRequest.apply_to model d) + (SelectCharacter char_id) -> - (handle_select_character model char_id) + (Update.SelectCharacter.apply_to model char_id) + EndTurn -> - (handle_end_turn model) - --_ -> model + (Update.EndTurn.apply_to model) diff --git a/client/elm/battlemap/src/Update/DirectionRequest.elm b/client/elm/battlemap/src/Update/DirectionRequest.elm new file mode 100644 index 0000000..6f30866 --- /dev/null +++ b/client/elm/battlemap/src/Update/DirectionRequest.elm @@ -0,0 +1,28 @@ +module Update.DirectionRequest exposing (apply_to) + +import Dict + +import Battlemap.Direction +import Battlemap.Navigator + +import Model + +apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type +apply_to model dir = + case (model.selection, model.navigator) of + (Nothing, _) -> model + (_ , Nothing) -> model + ((Just char_id), (Just nav)) -> + let + (new_bmap, new_nav) = + (Battlemap.Navigator.go + model.battlemap + nav + dir + (Dict.values model.characters) + ) + in + {model | + battlemap = new_bmap, + navigator = (Just new_nav) + } diff --git a/client/elm/battlemap/src/Update/EndTurn.elm b/client/elm/battlemap/src/Update/EndTurn.elm new file mode 100644 index 0000000..3fb479b --- /dev/null +++ b/client/elm/battlemap/src/Update/EndTurn.elm @@ -0,0 +1,48 @@ +module Update.EndTurn exposing (apply_to) + +import Dict + +import Battlemap +import Battlemap.Navigator + +import Model + +update_model : Model.Type -> Battlemap.Navigator.Type -> String -> Model.Type +update_model model nav char_id = + case (Dict.get char_id model.characters) of + Nothing -> model + (Just char) -> + {model | + navigator = Nothing, + battlemap = + (Battlemap.apply_to_all_tiles + (Battlemap.apply_to_tile_unsafe + (Battlemap.apply_to_tile_unsafe + model.battlemap + char.location + (\t -> {t | char_level = Nothing}) + ) + nav.current_location + (\t -> {t | char_level = (Just char_id)}) + ) + (Battlemap.Navigator.reset_navigation) + ), + characters = + (Dict.update + char_id + (\mc -> + case mc of + Nothing -> Nothing + (Just c) -> + (Just {c | location = nav.current_location}) + ) + model.characters + ) + } + +apply_to : Model.Type -> Model.Type +apply_to model = + case (model.navigator, model.selection) of + (_, Nothing) -> model + (Nothing, _) -> model + ((Just nav), (Just char_id)) -> (update_model model nav char_id) diff --git a/client/elm/battlemap/src/Update/SelectCharacter.elm b/client/elm/battlemap/src/Update/SelectCharacter.elm new file mode 100644 index 0000000..c9c1c94 --- /dev/null +++ b/client/elm/battlemap/src/Update/SelectCharacter.elm @@ -0,0 +1,32 @@ +module Update.SelectCharacter exposing (apply_to) + +import Dict + +import Character + +import Battlemap +import Battlemap.Navigator + +import Model + +apply_to : Model.Type -> Character.Ref -> Model.Type +apply_to model char_id = + {model | + selection = (Just char_id), + battlemap = + (Battlemap.apply_to_all_tiles + model.battlemap + (Battlemap.Navigator.reset_navigation) + ), + navigator = + (case (Dict.get char_id model.characters) of + Nothing -> Nothing + (Just char) -> + (Just + (Battlemap.Navigator.new_navigator + char.location + char.movement_points + ) + ) + ) + } diff --git a/client/elm/battlemap/src/View.elm b/client/elm/battlemap/src/View.elm index 2ea5972..168223a 100644 --- a/client/elm/battlemap/src/View.elm +++ b/client/elm/battlemap/src/View.elm @@ -11,9 +11,6 @@ import Battlemap.Html import Update import Model - --- VIEW - view : Model.Type -> (Html.Html Update.Type) view model = (Html.div @@ -57,7 +54,7 @@ view model = ), (Html.div [] - [(Battlemap.Html.view model)] + [(Battlemap.Html.view model.battlemap)] ), (Html.div [] |