summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-26 19:13:04 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-26 19:13:04 +0200 |
commit | 33e57128d48a012533c42635f52037fcdedd4c56 (patch) | |
tree | 05deb83b77311d25168e5966c14c1bf20f17fb79 | |
parent | 9293fb062b0bf66995c72b30e037c762318be000 (diff) |
Range indicators are now clickable.
-rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 16 | ||||
-rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 24 | ||||
-rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 3 | ||||
-rw-r--r-- | client/elm/battlemap/src/Error.elm | 5 | ||||
-rw-r--r-- | client/elm/battlemap/src/Event.elm | 13 | ||||
-rw-r--r-- | client/elm/battlemap/src/Model.elm | 28 | ||||
-rw-r--r-- | client/elm/battlemap/src/Shim/Battlemap.elm | 2 | ||||
-rw-r--r-- | client/elm/battlemap/src/Shim/Battlemap/Tile.elm | 52 | ||||
-rw-r--r-- | client/elm/battlemap/src/Shim/Model.elm | 5 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update.elm | 33 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/DirectionRequest.elm | 25 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/EndTurn.elm | 82 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/SelectCharacter.elm | 33 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update/SelectTile.elm | 80 | ||||
-rw-r--r-- | client/elm/battlemap/src/View.elm | 3 | ||||
-rw-r--r-- | client/elm/battlemap/src/View/Controls.elm | 12 | ||||
-rw-r--r-- | client/elm/battlemap/src/View/Status.elm | 48 |
17 files changed, 318 insertions, 146 deletions
diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index f67bdf0..6506c0f 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -9,12 +9,12 @@ import Battlemap import Battlemap.Tile import Battlemap.Direction -import Update +import Event type alias GridBuilder = { - row : (List (Html.Html Update.Type)), - columns : (List (Html.Html Update.Type)), + row : (List (Html.Html Event.Type)), + columns : (List (Html.Html Event.Type)), row_size : Int, bmap : Battlemap.Type } @@ -28,12 +28,12 @@ nav_level_to_text t = Battlemap.Direction.Down -> "D" Battlemap.Direction.None -> (toString t.floor_level) -view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Update.Type) +view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Event.Type) view_battlemap_cell t = case t.char_level of Nothing -> (Html.td - [] + [ (Html.Events.onClick (Event.SelectTile t.location)) ] [ (Html.text (case t.mod_level of @@ -47,7 +47,7 @@ view_battlemap_cell t = ) (Just char_id) -> (Html.td - [ (Html.Events.onClick (Update.SelectCharacter char_id)) ] + [ (Html.Events.onClick (Event.SelectCharacter char_id)) ] [ (Html.text ("[" ++ char_id ++ "]")), (Html.text (nav_level_to_text t)) @@ -73,7 +73,7 @@ foldr_to_html t gb = row_size = (gb.row_size + 1) } -grid_builder_to_html : GridBuilder -> (List (Html.Html Update.Type)) +grid_builder_to_html : GridBuilder -> (List (Html.Html Event.Type)) grid_builder_to_html gb = if (gb.row_size == 0) then @@ -81,7 +81,7 @@ grid_builder_to_html gb = else ((Html.tr [] gb.row) :: gb.columns) -view : Battlemap.Type -> (Html.Html Update.Type) +view : Battlemap.Type -> (Html.Html Event.Type) view battlemap = (Html.table [] diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index 3a0ca05..b040013 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -1,7 +1,8 @@ module Battlemap.Navigator exposing ( Type, - new_navigator + new, + reset ) import Set @@ -17,14 +18,27 @@ type alias Type = current_location : Battlemap.Location.Type, visited_locations : (Set.Set Battlemap.Location.Ref), previous_directions : (List Battlemap.Direction.Type), - remaining_points : Int + remaining_points : Int, + starting_location : Battlemap.Location.Type, + starting_points : Int } -new_navigator : Battlemap.Location.Type -> Int -> Type -new_navigator start points = +new : Battlemap.Location.Type -> Int -> Type +new start points = { current_location = start, visited_locations = Set.empty, previous_directions = [], - remaining_points = points + remaining_points = points, + starting_location = start, + starting_points = points + } + +reset : Type -> Type +reset nav = + {nav | + current_location = nav.starting_location, + visited_locations = Set.empty, + previous_directions = [], + remaining_points = nav.starting_points } diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index 6d2a65b..986cb2a 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -8,6 +8,8 @@ module Battlemap.Tile exposing ) import Battlemap.Direction +import Battlemap.Location + import Character type TileModifier = @@ -16,6 +18,7 @@ type TileModifier = type alias Type = { + location : Battlemap.Location.Ref, floor_level : Int, nav_level : Battlemap.Direction.Type, char_level : (Maybe Character.Ref), diff --git a/client/elm/battlemap/src/Error.elm b/client/elm/battlemap/src/Error.elm new file mode 100644 index 0000000..e2906dc --- /dev/null +++ b/client/elm/battlemap/src/Error.elm @@ -0,0 +1,5 @@ +module Error exposing (Type(..)) + +type Type = + IllegalAction + | Programming diff --git a/client/elm/battlemap/src/Event.elm b/client/elm/battlemap/src/Event.elm new file mode 100644 index 0000000..2c46360 --- /dev/null +++ b/client/elm/battlemap/src/Event.elm @@ -0,0 +1,13 @@ +module Event exposing (Type(..)) + +import Battlemap +import Battlemap.Direction +import Battlemap.Location + +import Character + +type Type = + DirectionRequest Battlemap.Direction.Type + | SelectTile Battlemap.Location.Ref + | SelectCharacter Character.Ref + | EndTurn diff --git a/client/elm/battlemap/src/Model.elm b/client/elm/battlemap/src/Model.elm index f5f57c0..4303b6f 100644 --- a/client/elm/battlemap/src/Model.elm +++ b/client/elm/battlemap/src/Model.elm @@ -1,4 +1,4 @@ -module Model exposing (Type, State(..)) +module Model exposing (Type, CharacterSelection, State(..)) import Dict @@ -7,22 +7,32 @@ import Battlemap.Navigator import Battlemap.Location import Battlemap.RangeIndicator +import Error + import Character +type alias CharacterSelection = + { + character: Character.Ref, + navigator: Battlemap.Navigator.Type, + range_indicator: + (Dict.Dict + Battlemap.Location.Ref + Battlemap.RangeIndicator.Type + ) + } + type State = Default - | MovingCharacter Character.Ref + | Error Error.Type + | MovingCharacterWithButtons + | MovingCharacterWithClick + | FocusingTile --- MODEL type alias Type = { state: State, battlemap: Battlemap.Type, - navigator: (Maybe Battlemap.Navigator.Type), characters: (Dict.Dict Character.Ref Character.Type), - range_indicator: - (Dict.Dict - Battlemap.Location.Ref - Battlemap.RangeIndicator.Type - ) + selection: (Maybe CharacterSelection) } diff --git a/client/elm/battlemap/src/Shim/Battlemap.elm b/client/elm/battlemap/src/Shim/Battlemap.elm index 2f795e1..f35cb67 100644 --- a/client/elm/battlemap/src/Shim/Battlemap.elm +++ b/client/elm/battlemap/src/Shim/Battlemap.elm @@ -7,5 +7,5 @@ generate = { width = 32, height = 32, - content = (Shim.Battlemap.Tile.generate) + content = (Shim.Battlemap.Tile.generate 32) } diff --git a/client/elm/battlemap/src/Shim/Battlemap/Tile.elm b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm index 55feb14..4f5b40b 100644 --- a/client/elm/battlemap/src/Shim/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Shim/Battlemap/Tile.elm @@ -3,30 +3,42 @@ module Shim.Battlemap.Tile exposing (generate) import Array import List +import Battlemap.Location import Battlemap.Direction import Battlemap.Tile -from_int : Int -> Battlemap.Tile.Type -from_int i = - if (i >= 10) - then - { - floor_level = (i - 10), - nav_level = Battlemap.Direction.None, - char_level = (Just (toString (i - 10))), - mod_level = Nothing - } - else - { - floor_level = i, - nav_level = Battlemap.Direction.None, - char_level = Nothing, - mod_level = Nothing - } +from_int : Int -> Int -> Int -> Battlemap.Tile.Type +from_int map_width index i = + let + location = + (Battlemap.Location.get_ref + { + x = (index % map_width), + y = (index // map_width) + } + ) + in + if (i >= 10) + then + { + location = location, + floor_level = (i - 10), + nav_level = Battlemap.Direction.None, + char_level = (Just (toString (i - 10))), + mod_level = Nothing + } + else + { + location = location, + floor_level = i, + nav_level = Battlemap.Direction.None, + char_level = Nothing, + mod_level = Nothing + } -generate : (Array.Array Battlemap.Tile.Type) -generate = +generate : Int -> (Array.Array Battlemap.Tile.Type) +generate map_width = let as_int_list = ( @@ -126,6 +138,6 @@ generate = ++ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ) - as_list = (List.map (from_int) as_int_list) + as_list = (List.indexedMap (from_int map_width) as_int_list) in (Array.fromList as_list) diff --git a/client/elm/battlemap/src/Shim/Model.elm b/client/elm/battlemap/src/Shim/Model.elm index 3d6cc5a..03c2450 100644 --- a/client/elm/battlemap/src/Shim/Model.elm +++ b/client/elm/battlemap/src/Shim/Model.elm @@ -10,8 +10,8 @@ import Shim.Battlemap generate = { state = Model.Default, + selection = Nothing, battlemap = (Shim.Battlemap.generate), - navigator = Nothing, characters = (Dict.insert "2" @@ -49,6 +49,5 @@ generate = Dict.empty ) ) - ), - range_indicator = Dict.empty + ) } diff --git a/client/elm/battlemap/src/Update.elm b/client/elm/battlemap/src/Update.elm index 5c97ab8..b6b2a80 100644 --- a/client/elm/battlemap/src/Update.elm +++ b/client/elm/battlemap/src/Update.elm @@ -1,32 +1,25 @@ -module Update exposing (update, Type(..)) +module Update exposing (update) + +import Event import Model import Update.DirectionRequest +import Update.SelectTile import Update.SelectCharacter import Update.EndTurn -import Battlemap -import Battlemap.Direction -import Battlemap.Navigator - -import Dict - -import Character - -type Type = - DirectionRequest Battlemap.Direction.Type - | SelectCharacter Character.Ref - | EndTurn - -update : Type -> Model.Type -> Model.Type -update msg model = - case msg of - (DirectionRequest d) -> +update : Event.Type -> Model.Type -> Model.Type +update event model = + case event of + (Event.DirectionRequest d) -> (Update.DirectionRequest.apply_to model d) - (SelectCharacter char_id) -> + (Event.SelectTile loc) -> + (Update.SelectTile.apply_to model loc) + + (Event.SelectCharacter char_id) -> (Update.SelectCharacter.apply_to model char_id) - EndTurn -> + Event.EndTurn -> (Update.EndTurn.apply_to model) diff --git a/client/elm/battlemap/src/Update/DirectionRequest.elm b/client/elm/battlemap/src/Update/DirectionRequest.elm index 477ba71..da32240 100644 --- a/client/elm/battlemap/src/Update/DirectionRequest.elm +++ b/client/elm/battlemap/src/Update/DirectionRequest.elm @@ -6,23 +6,32 @@ import Battlemap.Direction import Battlemap.Navigator.Move import Model +import Error -apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type -apply_to model dir = - case (model.state, model.navigator) of - (_ , Nothing) -> model - ((Model.MovingCharacter _), (Just nav)) -> +make_it_so : Model.Type -> Battlemap.Direction.Type -> Model.Type +make_it_so model dir = + case model.selection of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just selection) -> let (new_bmap, new_nav) = (Battlemap.Navigator.Move.to model.battlemap - nav + selection.navigator dir (Dict.values model.characters) ) in {model | + state = Model.MovingCharacterWithButtons, battlemap = new_bmap, - navigator = (Just new_nav) + selection = (Just {selection | navigator = new_nav}) } - (_, _) -> model + + +apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type +apply_to model dir = + case model.state of + Model.MovingCharacterWithButtons -> (make_it_so model dir) + Model.MovingCharacterWithClick -> (make_it_so model dir) + _ -> {model | state = (Model.Error Error.IllegalAction)} diff --git a/client/elm/battlemap/src/Update/EndTurn.elm b/client/elm/battlemap/src/Update/EndTurn.elm index cc81028..7172b2f 100644 --- a/client/elm/battlemap/src/Update/EndTurn.elm +++ b/client/elm/battlemap/src/Update/EndTurn.elm @@ -9,43 +9,53 @@ import Battlemap.Tile 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}) +import Error + +make_it_so : Model.Type -> Model.Type +make_it_so model = + case model.selection of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just selection) -> + case (Dict.get selection.character model.characters) of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just char) -> + {model | + state = Model.Default, + selection = 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}) + ) + selection.navigator.current_location + (\t -> {t | char_level = (Just selection.character)}) + ) + (Battlemap.Tile.reset_tile) + ), + characters = + (Dict.update + selection.character + (\mc -> + case mc of + Nothing -> Nothing + (Just c) -> + (Just + {c | + location = selection.navigator.current_location + } + ) + ) + model.characters ) - nav.current_location - (\t -> {t | char_level = (Just char_id)}) - ) - (Battlemap.Tile.reset_tile) - ), - 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.state, model.navigator) of - (_, Nothing) -> model - ((Model.MovingCharacter char_id), (Just nav)) -> - (update_model model nav char_id) - (_, _) -> model + case model.state of + Model.MovingCharacterWithButtons -> (make_it_so model) + Model.MovingCharacterWithClick -> (make_it_so model) + _ -> {model | state = (Model.Error Error.IllegalAction)} + diff --git a/client/elm/battlemap/src/Update/SelectCharacter.elm b/client/elm/battlemap/src/Update/SelectCharacter.elm index 3fa2ab2..0e7b1c4 100644 --- a/client/elm/battlemap/src/Update/SelectCharacter.elm +++ b/client/elm/battlemap/src/Update/SelectCharacter.elm @@ -12,6 +12,8 @@ import Battlemap.Tile import Battlemap.RangeIndicator import Model +import Event +import Error display_range : ( Int -> @@ -39,10 +41,10 @@ display_range dist loc_ref indicator bmap = ) -apply_to : Model.Type -> Character.Ref -> Model.Type -apply_to model char_id = +make_it_so : Model.Type -> Character.Ref -> Model.Type +make_it_so model char_id = case (Dict.get char_id model.characters) of - Nothing -> model + Nothing -> {model | state = (Model.Error Error.Programming)} (Just char) -> let new_range_indicator = @@ -54,7 +56,7 @@ apply_to model char_id = ) in {model | - state = (Model.MovingCharacter char_id), + state = Model.MovingCharacterWithClick, battlemap = ( (Dict.foldl @@ -66,12 +68,21 @@ apply_to model char_id = new_range_indicator ) ), - navigator = + selection = (Just - (Battlemap.Navigator.new_navigator - char.location - char.movement_points - ) - ), - range_indicator = new_range_indicator + { + character = char_id, + navigator = + (Battlemap.Navigator.new + char.location + char.movement_points + ), + range_indicator = new_range_indicator + } + ) } + +apply_to : Model.Type -> Character.Ref -> Model.Type +apply_to model char_id = + case model.state of + _ -> (make_it_so model char_id) diff --git a/client/elm/battlemap/src/Update/SelectTile.elm b/client/elm/battlemap/src/Update/SelectTile.elm new file mode 100644 index 0000000..aa89c30 --- /dev/null +++ b/client/elm/battlemap/src/Update/SelectTile.elm @@ -0,0 +1,80 @@ +module Update.SelectTile exposing (apply_to) + +import Dict + +import Character + +import Battlemap +import Battlemap.Direction +import Battlemap.Location +import Battlemap.Navigator +import Battlemap.Tile +import Battlemap.RangeIndicator + +import Update.DirectionRequest +import Update.EndTurn + +import Model +import Error + +autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type +autopilot dir model = + (Update.DirectionRequest.apply_to model dir) + +go_to_tile : Model.Type -> Battlemap.Location.Ref -> Model.Type +go_to_tile model loc_ref = + case model.selection of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just selection) -> + case (Dict.get loc_ref selection.range_indicator) of + Nothing -> {model | state = Model.Default, selection = Nothing} + (Just indicator) -> + let + new_model = + (List.foldr + (autopilot) + {model | + battlemap = + (Battlemap.apply_to_all_tiles + model.battlemap + (Battlemap.Tile.set_direction + Battlemap.Direction.None + ) + ), + selection = + (Just + { + selection | + navigator = + (Battlemap.Navigator.reset + selection.navigator + ) + } + ) + } + indicator.path + ) + in + if + ( + (model.state == Model.MovingCharacterWithClick) + && + ( + (Battlemap.Location.get_ref + selection.navigator.current_location + ) + == loc_ref + ) + ) + then + (Update.EndTurn.apply_to new_model) + else + {new_model | state = model.state} + + +apply_to : Model.Type -> Battlemap.Location.Ref -> Model.Type +apply_to model loc_ref = + case model.state of + Model.MovingCharacterWithButtons -> (go_to_tile model loc_ref) + Model.MovingCharacterWithClick -> (go_to_tile model loc_ref) + _ -> {model | state = (Model.Error Error.IllegalAction)} diff --git a/client/elm/battlemap/src/View.elm b/client/elm/battlemap/src/View.elm index ce869cd..3450f9c 100644 --- a/client/elm/battlemap/src/View.elm +++ b/client/elm/battlemap/src/View.elm @@ -7,10 +7,11 @@ import Battlemap.Html import View.Controls import View.Status +import Event import Update import Model -view : Model.Type -> (Html.Html Update.Type) +view : Model.Type -> (Html.Html Event.Type) view model = (Html.div [] diff --git a/client/elm/battlemap/src/View/Controls.elm b/client/elm/battlemap/src/View/Controls.elm index 203fcdb..be698bf 100644 --- a/client/elm/battlemap/src/View/Controls.elm +++ b/client/elm/battlemap/src/View/Controls.elm @@ -5,27 +5,27 @@ import Html.Events import Battlemap.Direction -import Update +import Event -direction_button : Battlemap.Direction.Type -> String -> (Html.Html Update.Type) +direction_button : Battlemap.Direction.Type -> String -> (Html.Html Event.Type) direction_button dir label = (Html.button [ (Html.Events.onClick - (Update.DirectionRequest dir) + (Event.DirectionRequest dir) ) ] [ (Html.text label) ] ) -end_turn_button : (Html.Html Update.Type) +end_turn_button : (Html.Html Event.Type) end_turn_button = (Html.button - [ (Html.Events.onClick Update.EndTurn) ] + [ (Html.Events.onClick Event.EndTurn) ] [ (Html.text "End Turn") ] ) -view : (List (Html.Html Update.Type)) +view : (List (Html.Html Event.Type)) view = [ (direction_button Battlemap.Direction.Left "Left"), diff --git a/client/elm/battlemap/src/View/Status.elm b/client/elm/battlemap/src/View/Status.elm index 3a06572..a7beb28 100644 --- a/client/elm/battlemap/src/View/Status.elm +++ b/client/elm/battlemap/src/View/Status.elm @@ -4,27 +4,39 @@ import Dict import Html -import Update +import Error +import Event import Model -view : Model.Type -> (Html.Html Update.Type) +moving_character_text : Model.Type -> String +moving_character_text model = + case model.selection of + Nothing -> "Error: no model.selection." + (Just selection) -> + case (Dict.get selection.character model.characters) of + Nothing -> "Error: Unknown character selected." + (Just char) -> + ( + "Controlling " + ++ char.name + ++ ": " + ++ (toString selection.navigator.remaining_points) + ++ "/" + ++ (toString char.movement_points) + ++ " movement points remaining." + ) + +view : Model.Type -> (Html.Html Event.Type) view model = (Html.text - (case (model.state, model.navigator) of - (_, Nothing) -> "" - ((Model.MovingCharacter char_id), (Just nav)) -> - case (Dict.get char_id model.characters) of - Nothing -> "" - (Just char) -> - ( - "Controlling " - ++ char.name - ++ ": " - ++ (toString nav.remaining_points) - ++ "/" - ++ (toString char.movement_points) - ++ " movement points remaining." - ) - (_, _) -> "" + (case model.state of + Model.Default -> "Click on a character to control it." + Model.MovingCharacterWithButtons -> (moving_character_text model) + Model.MovingCharacterWithClick -> (moving_character_text model) + Model.FocusingTile -> "Error: Unimplemented." + (Model.Error Error.Programming) -> + "Error of programming, please report." + (Model.Error Error.IllegalAction) -> + "This cannot be done while in this state." ) ) |