summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src')
40 files changed, 837 insertions, 795 deletions
diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm deleted file mode 100644 index 5b289d0..0000000 --- a/src/battlemap/src/Battlemap.elm +++ /dev/null @@ -1,237 +0,0 @@ -module Battlemap exposing - ( - Type, - empty, - new, - reset, - get_width, - get_height, - get_navigator_remaining_points, - get_tiles, - set_navigator, - clear_navigator_path, - get_navigator_path, - try_getting_tile_at, - try_getting_navigator_location, - try_getting_navigator_path_to, - try_getting_navigator_summary, - try_adding_step_to_navigator - ) - -import Array - -import Battlemap.Navigator -import Battlemap.Tile -import Battlemap.Direction -import Battlemap.Location - -import Character - -import Constants.Movement - --------------------------------------------------------------------------------- --- TYPES ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -type alias Type = - { - width: Int, - height: Int, - content: (Array.Array Battlemap.Tile.Type), - navigator: (Maybe Battlemap.Navigator.Type) - } - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -location_to_index : Type -> Battlemap.Location.Type -> Int -location_to_index bmap loc = - ((loc.y * bmap.width) + loc.x) - -has_location : Type -> Battlemap.Location.Type -> Bool -has_location bmap loc = - ( - (loc.x >= 0) - && (loc.y >= 0) - && (loc.x < bmap.width) - && (loc.y < bmap.height) - ) - -tile_cost_function : ( - Type -> - Battlemap.Location.Type -> - (List Character.Type) -> - Battlemap.Location.Type -> - Int - ) -tile_cost_function bmap start_loc char_list loc = - if - ( - (Battlemap.Location.get_ref start_loc) - == - (Battlemap.Location.get_ref loc) - ) - then - 0 - else - if (has_location bmap loc) - then - case - (Array.get (location_to_index bmap loc) bmap.content) - of - (Just tile) -> - if - (List.any - (\c -> ((Character.get_location c) == loc)) - char_list - ) - then - Constants.Movement.cost_when_occupied_tile - else - (Battlemap.Tile.get_cost tile) - - Nothing -> Constants.Movement.cost_when_out_of_bounds - else - Constants.Movement.cost_when_out_of_bounds - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_width : Type -> Int -get_width bmap = bmap.width - -get_height : Type -> Int -get_height bmap = bmap.height - -get_tiles : Type -> (Array.Array Battlemap.Tile.Type) -get_tiles bmap = bmap.content - -empty : Type -empty = - { - width = 0, - height = 0, - content = (Array.empty), - navigator = Nothing - } - -new : Int -> Int -> (List Battlemap.Tile.Type) -> Type -new width height tiles = - { - width = width, - height = height, - content = (Array.fromList tiles), - navigator = Nothing - } - -reset : Type -> Type -reset bmap = - {bmap | - navigator = Nothing - } - -clear_navigator_path : Type -> Type -clear_navigator_path bmap = - case bmap.navigator of - (Just navigator) -> - {bmap | navigator = (Just (Battlemap.Navigator.clear_path navigator))} - - Nothing -> bmap - -get_navigator_path : Type -> (List Battlemap.Direction.Type) -get_navigator_path bmap = - case bmap.navigator of - (Just navigator) -> (Battlemap.Navigator.get_path navigator) - Nothing -> [] - -try_getting_navigator_location : Type -> (Maybe Battlemap.Location.Type) -try_getting_navigator_location bmap = - case bmap.navigator of - (Just navigator) -> - (Just (Battlemap.Navigator.get_current_location navigator)) - - Nothing -> Nothing - -get_navigator_remaining_points : Type -> Int -get_navigator_remaining_points bmap = - case bmap.navigator of - (Just navigator) -> (Battlemap.Navigator.get_remaining_points navigator) - Nothing -> -1 - -set_navigator : ( - Battlemap.Location.Type -> - Int -> - Int -> - (List Character.Type) -> - Type -> - Type - ) -set_navigator start_loc movement_points attack_range character_list bmap = - {bmap | - navigator = - (Just - (Battlemap.Navigator.new - start_loc - movement_points - attack_range - (tile_cost_function - bmap - start_loc - character_list - ) - ) - ) - } - -try_getting_tile_at : ( - Type -> - Battlemap.Location.Type -> - (Maybe Battlemap.Tile.Type) - ) -try_getting_tile_at bmap loc = - (Array.get (location_to_index bmap loc) bmap.content) - -try_adding_step_to_navigator : ( - Type -> - (List Character.Type) -> - Battlemap.Direction.Type -> - (Maybe Type) - ) -try_adding_step_to_navigator bmap character_list dir = - case bmap.navigator of - (Just navigator) -> - let - new_navigator = - (Battlemap.Navigator.try_adding_step - navigator - dir - (tile_cost_function - bmap - (Battlemap.Navigator.get_starting_location navigator) - character_list - ) - ) - in - case new_navigator of - (Just _) -> (Just {bmap | navigator = new_navigator}) - Nothing -> Nothing - - _ -> Nothing - -try_getting_navigator_summary : Type -> (Maybe Battlemap.Navigator.Summary) -try_getting_navigator_summary bmap = - case bmap.navigator of - (Just navigator) -> (Just (Battlemap.Navigator.get_summary navigator)) - Nothing -> Nothing - -try_getting_navigator_path_to : ( - Type -> - Battlemap.Location.Ref -> - (Maybe (List Battlemap.Direction.Type)) - ) -try_getting_navigator_path_to bmap loc_ref = - case bmap.navigator of - (Just navigator) -> - (Battlemap.Navigator.try_getting_path_to navigator loc_ref) - - Nothing -> Nothing - diff --git a/src/battlemap/src/Battlemap/Direction.elm b/src/battlemap/src/Battlemap/Direction.elm deleted file mode 100644 index cebe765..0000000 --- a/src/battlemap/src/Battlemap/Direction.elm +++ /dev/null @@ -1,27 +0,0 @@ -module Battlemap.Direction exposing (Type(..), opposite_of, to_string) - -type Type = - None - | Left - | Right - | Up - | Down - -opposite_of : Type -> Type -opposite_of d = - case d of - Left -> Right - Right -> Left - Up -> Down - Down -> Up - None -> None - -to_string : Type -> String -to_string dir = - case dir of - Right -> "R" - Left -> "L" - Up -> "U" - Down -> "D" - None -> "N" - diff --git a/src/battlemap/src/Battlemap/Location.elm b/src/battlemap/src/Battlemap/Location.elm deleted file mode 100644 index 8c23e9d..0000000 --- a/src/battlemap/src/Battlemap/Location.elm +++ /dev/null @@ -1,45 +0,0 @@ -module Battlemap.Location exposing (..) - -import Battlemap.Direction - -type alias Type = - { - x : Int, - y : Int - } - -type alias Ref = (Int, Int) - -neighbor : Type -> Battlemap.Direction.Type -> Type -neighbor loc dir = - case dir of - Battlemap.Direction.Right -> {loc | x = (loc.x + 1)} - Battlemap.Direction.Left -> {loc | x = (loc.x - 1)} - Battlemap.Direction.Up -> {loc | y = (loc.y - 1)} - Battlemap.Direction.Down -> {loc | y = (loc.y + 1)} - Battlemap.Direction.None -> loc - - -get_ref : Type -> Ref -get_ref l = - (l.x, l.y) - -from_ref : Ref -> Type -from_ref (x, y) = - {x = x, y = y} - -dist : Type -> Type -> Int -dist loc_a loc_b = - if (loc_a.x > loc_b.x) - then - if (loc_a.y > loc_b.y) - then - ((loc_a.x - loc_b.x) + (loc_a.y - loc_b.y)) - else - ((loc_a.x - loc_b.x) + (loc_b.y - loc_a.y)) - else - if (loc_a.y > loc_b.y) - then - ((loc_b.x - loc_a.x) + (loc_a.y - loc_b.y)) - else - ((loc_b.x - loc_a.x) + (loc_b.y - loc_a.y)) diff --git a/src/battlemap/src/Battlemap/Marker.elm b/src/battlemap/src/Battlemap/Marker.elm deleted file mode 100644 index ebefce6..0000000 --- a/src/battlemap/src/Battlemap/Marker.elm +++ /dev/null @@ -1,5 +0,0 @@ -module Battlemap.Marker exposing (Type(..)) - -type Type = - CanAttack - | CanGoTo diff --git a/src/battlemap/src/Init.elm b/src/battlemap/src/ElmModule/Init.elm index e8b797a..2b62933 100644 --- a/src/battlemap/src/Init.elm +++ b/src/battlemap/src/ElmModule/Init.elm @@ -1,8 +1,8 @@ -module Init exposing (init) +module ElmModule.Init exposing (init) -- Battlemap ------------------------------------------------------------------- -import Model -import Event +import Struct.Model +import Struct.Event import Shim.Model @@ -15,7 +15,7 @@ import Send.LoadBattlemap -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -init : (Model.Type, (Cmd Event.Type)) +init : (Struct.Model.Type, (Cmd Event.Type)) init = let model = (Shim.Model.generate) diff --git a/src/battlemap/src/ElmModule/Subscriptions.elm b/src/battlemap/src/ElmModule/Subscriptions.elm new file mode 100644 index 0000000..c8126b1 --- /dev/null +++ b/src/battlemap/src/ElmModule/Subscriptions.elm @@ -0,0 +1,7 @@ +module ElmModule.Subscriptions exposing (..) + +import Struct.Model +import Struct.Event + +subscriptions : Struct.Model.Type -> (Sub Struct.Event.Type) +subscriptions model = Sub.none diff --git a/src/battlemap/src/ElmModule/Update.elm b/src/battlemap/src/ElmModule/Update.elm new file mode 100644 index 0000000..947b232 --- /dev/null +++ b/src/battlemap/src/ElmModule/Update.elm @@ -0,0 +1,55 @@ +module ElmModule.Update exposing (update) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Event +import Struct.Error +import Struct.UI +import Struct.Model + +import Update.RequestDirection +import Update.SelectTile +import Update.SelectCharacter +import Update.EndTurn +import Update.HandleServerReply + +import Send.LoadBattlemap + +update : ( + Struct.Event.Type -> + Struct.Model.Type -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +update event model = + let + new_model = (Struct.Model.clear_error model) + in + case event of + (Struct.Event.DirectionRequested d) -> + (Update.RequestDirection.apply_to new_model d) + + (Struct.Event.TileSelected loc) -> + (Update.SelectTile.apply_to new_model loc) + + (Struct.Event.CharacterSelected char_id) -> + (Update.SelectCharacter.apply_to new_model char_id) + + Struct.Event.TurnEnded -> + (Update.EndTurn.apply_to new_model) + + (Struct.Event.ScaleChangeRequested mod) -> + (Update.ChangeScale.apply_to new_model mod) + + (Struct.Event.TabSelected tab) -> + (Update.SelectTab.apply_to new_model mod) + + Struct.Event.DebugTeamSwitchRequest -> + (Update.SwitchTeam.apply_to new_model) + + (Event.DebugLoadBattlemapRequest) -> + (Update.SendLoadBattlemapRequest.apply_to new_model) + + (Event.ServerReplied result) -> + (Model.HandleServerReply.apply_to model result) + diff --git a/src/battlemap/src/View.elm b/src/battlemap/src/ElmModule/View.elm index 9073d93..e6e0295 100644 --- a/src/battlemap/src/View.elm +++ b/src/battlemap/src/ElmModule/View.elm @@ -1,4 +1,4 @@ -module View exposing (view) +module ElmModule.View exposing (view) -- Elm ------------------------------------------------------------------------- import Dict @@ -7,19 +7,22 @@ import Html import Html.Attributes -- Battlemap ------------------------------------------------------------------- -import UI +import Struct.UI +import Struct.Event +import Struct.Model import View.Battlemap import View.SideBar import View.Footer -import Event -import Model +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -view : Model.Type -> (Html.Html Event.Type) +view : Struct.Model.Type -> (Html.Html Struct.Event.Type) view model = (Html.div [ @@ -38,7 +41,7 @@ view model = [ (View.Battlemap.get_html model.battlemap - (UI.get_zoom_level model.ui) + (Struct.UI.get_zoom_level model.ui) (Dict.values model.characters) ) ] diff --git a/src/battlemap/src/Error.elm b/src/battlemap/src/Error.elm deleted file mode 100644 index 206088e..0000000 --- a/src/battlemap/src/Error.elm +++ /dev/null @@ -1,33 +0,0 @@ -module Error exposing (Type, Mode(..), new, to_string) - -type Mode = - IllegalAction - | Programming - | Unimplemented - | Networking - -type alias Type = - { - mode: Mode, - message: String - } - -new : Mode -> String -> Type -new mode str = - { - mode = mode, - message = str - } - -to_string : Type -> String -to_string e = - ( - (case e.mode of - IllegalAction -> "Request discarded: " - Programming -> "Error in the program (please report): " - Unimplemented -> "Update discarded due to unimplemented feature: " - Networking -> "Error while conversing with the server: " - ) - ++ e.message - ) - diff --git a/src/battlemap/src/Event.elm b/src/battlemap/src/Event.elm deleted file mode 100644 index 1a6f2e5..0000000 --- a/src/battlemap/src/Event.elm +++ /dev/null @@ -1,21 +0,0 @@ -module Event exposing (Type(..)) - -import Http - -import Battlemap.Direction -import Battlemap.Location - -import Character - -import UI - -type Type = - DirectionRequested Battlemap.Direction.Type - | TileSelected Battlemap.Location.Ref - | CharacterSelected Character.Ref - | TurnEnded - | ScaleChangeRequested Float - | TabSelected UI.Tab - | ServerReplied (Result Http.Error (List (List String))) - | DebugTeamSwitchRequest - | DebugLoadBattlemapRequest diff --git a/src/battlemap/src/Model/SelectCharacter.elm b/src/battlemap/src/Model/SelectCharacter.elm deleted file mode 100644 index 619a729..0000000 --- a/src/battlemap/src/Model/SelectCharacter.elm +++ /dev/null @@ -1,110 +0,0 @@ -module Model.SelectCharacter exposing (apply_to) - --- Elm ------------------------------------------------------------------------- -import Dict - --- Battlemap ------------------------------------------------------------------- -import Battlemap -import Battlemap.Direction - -import Character - -import UI - -import Model -import Model.RequestDirection - -import Error - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type -autopilot dir model = - (Model.RequestDirection.apply_to model dir) - -attack_character : ( - Model.Type -> - Character.Ref -> - Character.Ref -> - Character.Type -> - Model.Type - ) -attack_character model main_char_id target_char_id target_char = - {model | - targets = [target_char_id], - ui = (UI.set_previous_action model.ui Nothing) - } - -select_character : ( - Model.Type -> - Character.Ref -> - Character.Type -> - Model.Type - ) -select_character model target_char_id target_char = - if ((Character.is_enabled target_char)) - then - {model | - state = Model.Default, - controlled_character = (Just target_char_id), - ui = (UI.set_previous_action model.ui Nothing), - battlemap = - (Battlemap.set_navigator - (Character.get_location target_char) - (Character.get_movement_points target_char) - (Character.get_attack_range target_char) - (Dict.values model.characters) - model.battlemap - ) - } - else - {model | - ui = - (UI.set_previous_action - model.ui - (Just (UI.SelectedCharacter target_char_id)) - ) - } - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -apply_to : Model.Type -> Character.Ref -> Model.Type -apply_to model target_char_id = - if - ( - (UI.get_previous_action model.ui) - == - (Just (UI.SelectedCharacter target_char_id)) - ) - then - case (Dict.get target_char_id model.characters) of - (Just target_char) -> - case model.controlled_character of - (Just main_char_id) -> - (attack_character - model - main_char_id - target_char_id - target_char - ) - - _ -> (select_character model target_char_id target_char) - - Nothing -> - (Model.invalidate - model - (Error.new - Error.Programming - "SelectCharacter: Unknown char selected." - ) - ) - else - {model | - ui = - (UI.set_previous_action - model.ui - (Just (UI.SelectedCharacter target_char_id)) - ) - } diff --git a/src/battlemap/src/Battlemap/Navigator/Move.elm b/src/battlemap/src/Move.elm index 9d7a17b..945d29f 100644 --- a/src/battlemap/src/Battlemap/Navigator/Move.elm +++ b/src/battlemap/src/Move.elm @@ -1,68 +1,71 @@ -module Battlemap.Navigator.Move exposing (to) +module ???.MoveNavigator exposing (to) + +-- TODO: This should not belong to the Struct.Navigator module, as it's actually +-- a module used to manipulate an existing navigator in a certain way. import Set import List -import Battlemap -import Battlemap.Direction -import Battlemap.Location -import Battlemap.Tile -import Battlemap.Navigator +import Struct.Battlemap +import Struct.Direction +import Struct.Location +import Struct.Tile +import Struct.Navigator import Character import Util.List can_move_to_new_tile : ( - Battlemap.Navigator.Type -> - Battlemap.Type -> - Battlemap.Location.Type -> + Struct.Navigator.Type -> + Struct.Battlemap.Type -> + Struct.Location.Type -> Bool ) can_move_to_new_tile nav battlemap next_location = ( (nav.remaining_points > 0) - && (Battlemap.has_location battlemap next_location) + && (Struct.Battlemap.has_location battlemap next_location) && (nav.current_location /= next_location) && (not (Set.member - (Battlemap.Location.get_ref next_location) + (Struct.Location.get_ref next_location) nav.visited_locations ) ) ) battlemap_move_to : ( - Battlemap.Type -> - Battlemap.Location.Type -> - Battlemap.Direction.Type -> - Battlemap.Location.Type -> - Battlemap.Type + Struct.Battlemap.Type -> + Struct.Location.Type -> + Struct.Direction.Type -> + Struct.Location.Type -> + Struct.Battlemap.Type ) battlemap_move_to battlemap current_loc dir next_loc = - (Battlemap.apply_to_tile_unsafe - (Battlemap.apply_to_tile_unsafe + (Struct.Battlemap.apply_to_tile_unsafe + (Struct.Battlemap.apply_to_tile_unsafe battlemap current_loc - (Battlemap.Tile.set_direction dir) + (Struct.Tile.set_direction dir) ) next_loc - (Battlemap.Tile.set_direction dir) + (Struct.Tile.set_direction dir) ) navigator_move_to : ( - Battlemap.Navigator.Type -> - Battlemap.Direction.Type -> - Battlemap.Location.Type -> - Battlemap.Navigator.Type + Struct.Navigator.Type -> + Struct.Direction.Type -> + Struct.Location.Type -> + Struct.Navigator.Type ) navigator_move_to nav dir next_loc = {nav | current_location = next_loc, visited_locations = (Set.insert - (Battlemap.Location.get_ref nav.current_location) + (Struct.Location.get_ref nav.current_location) nav.visited_locations ), previous_directions = (dir :: nav.previous_directions), @@ -70,31 +73,31 @@ navigator_move_to nav dir next_loc = } battlemap_backtrack : ( - Battlemap.Type -> - Battlemap.Location.Type -> - Battlemap.Type + Struct.Battlemap.Type -> + Struct.Location.Type -> + Struct.Battlemap.Type ) battlemap_backtrack battlemap current_loc = - (Battlemap.apply_to_tile_unsafe + (Struct.Battlemap.apply_to_tile_unsafe battlemap current_loc - (Battlemap.Tile.set_direction - Battlemap.Direction.None + (Struct.Tile.set_direction + Struct.Direction.None ) ) navigator_backtrack : ( - Battlemap.Navigator.Type -> - Battlemap.Location.Type -> - (List Battlemap.Direction.Type) -> - Battlemap.Navigator.Type + Struct.Navigator.Type -> + Struct.Location.Type -> + (List Struct.Direction.Type) -> + Struct.Navigator.Type ) navigator_backtrack nav next_loc prev_dir_tail = {nav | current_location = next_loc, visited_locations = (Set.remove - (Battlemap.Location.get_ref next_loc) + (Struct.Location.get_ref next_loc) nav.visited_locations ), previous_directions = prev_dir_tail, @@ -102,15 +105,15 @@ navigator_backtrack nav next_loc prev_dir_tail = } to : ( - Battlemap.Type -> - Battlemap.Navigator.Type -> - Battlemap.Direction.Type -> + Struct.Battlemap.Type -> + Struct.Navigator.Type -> + Struct.Direction.Type -> (List Character.Type) -> - (Battlemap.Type, Battlemap.Navigator.Type) + (Struct.Battlemap.Type, Struct.Navigator.Type) ) to battlemap nav dir char_list = let - next_location = (Battlemap.Location.neighbor nav.current_location dir) + next_location = (Struct.Location.neighbor nav.current_location dir) is_occupied = (List.any (\c -> ((Character.get_location c) == next_location)) @@ -138,7 +141,7 @@ to battlemap nav dir char_list = case (Util.List.pop nav.previous_directions) of Nothing -> (battlemap, nav) (Just (head, tail)) -> - if (head == (Battlemap.Direction.opposite_of dir)) + if (head == (Struct.Direction.opposite_of dir)) then ( (battlemap_backtrack diff --git a/src/battlemap/src/Query/CharacterTurn.elm b/src/battlemap/src/Send/Query/CharacterTurn.elm index ec7efa0..ec7efa0 100644 --- a/src/battlemap/src/Query/CharacterTurn.elm +++ b/src/battlemap/src/Send/Query/CharacterTurn.elm diff --git a/src/battlemap/src/Send.elm b/src/battlemap/src/Send/Send.elm index 3288050..3288050 100644 --- a/src/battlemap/src/Send.elm +++ b/src/battlemap/src/Send/Send.elm diff --git a/src/battlemap/src/Struct/Battlemap.elm b/src/battlemap/src/Struct/Battlemap.elm new file mode 100644 index 0000000..bd1f3b0 --- /dev/null +++ b/src/battlemap/src/Struct/Battlemap.elm @@ -0,0 +1,122 @@ +module Struct.Battlemap exposing + ( + Type, + empty, + new, + get_width, + get_height, + get_tiles, + try_getting_tile_at + ) + +-- Elm ------------------------------------------------------------------------- +import Array + +-- Battlemap ------------------------------------------------------------------- +import Struct.Character +import Struct.Navigator +import Struct.Tile +import Struct.Direction +import Struct.Location + +import Constants.Movement + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + width: Int, + height: Int, + content: (Array.Array Struct.Tile.Type) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +location_to_index : Type -> Struct.Location.Type -> Int +location_to_index bmap loc = + ((loc.y * bmap.width) + loc.x) + +has_location : Type -> Struct.Location.Type -> Bool +has_location bmap loc = + ( + (loc.x >= 0) + && (loc.y >= 0) + && (loc.x < bmap.width) + && (loc.y < bmap.height) + ) + +tile_cost_function : ( + Type -> + Struct.Location.Type -> + (List Struct.Character.Type) -> + Struct.Location.Type -> + Int + ) +tile_cost_function bmap start_loc char_list loc = + if + ( + (Struct.Location.get_ref start_loc) + == + (Struct.Location.get_ref loc) + ) + then + 0 + else + if (has_location bmap loc) + then + case + (Array.get (location_to_index bmap loc) bmap.content) + of + (Just tile) -> + if + (List.any + (\c -> ((Struct.Character.get_location c) == loc)) + char_list + ) + then + Constants.Movement.cost_when_occupied_tile + else + (Struct.Tile.get_cost tile) + + Nothing -> Constants.Movement.cost_when_out_of_bounds + else + Constants.Movement.cost_when_out_of_bounds + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_width : Type -> Int +get_width bmap = bmap.width + +get_height : Type -> Int +get_height bmap = bmap.height + +get_tiles : Type -> (Array.Array Struct.Tile.Type) +get_tiles bmap = bmap.content + +empty : Type +empty = + { + width = 0, + height = 0, + content = (Array.empty), + navigator = Nothing + } + +new : Int -> Int -> (List Struct.Tile.Type) -> Type +new width height tiles = + { + width = width, + height = height, + content = (Array.fromList tiles) + } + +try_getting_tile_at : ( + Type -> + Struct.Location.Type -> + (Maybe Struct.Tile.Type) + ) +try_getting_tile_at bmap loc = + (Array.get (location_to_index bmap loc) bmap.content) diff --git a/src/battlemap/src/Character.elm b/src/battlemap/src/Struct/Character.elm index 31337f7..1d5b269 100644 --- a/src/battlemap/src/Character.elm +++ b/src/battlemap/src/Struct/Character.elm @@ -1,4 +1,4 @@ -module Character exposing +module Struct.Character exposing ( Type, Ref, @@ -18,7 +18,7 @@ module Character exposing ) -- Battlemap ------------------------------------------------------------------- -import Battlemap.Location +import Struct.Location -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -29,7 +29,7 @@ type alias Type = name : String, icon : String, portrait : String, - location : Battlemap.Location.Type, + location : Struct.Location.Type, health : Int, max_health : Int, team : Int, @@ -54,7 +54,7 @@ new : ( String -> -- portrait Int -> -- health Int -> -- max_health - Battlemap.Location.Type -> -- location + Struct.Location.Type -> -- location Int -> -- team Int -> -- movement_points Int -> -- atk_dist @@ -99,10 +99,10 @@ get_current_health c = c.health get_max_health : Type -> Int get_max_health c = c.max_health -get_location : Type -> Battlemap.Location.Type +get_location : Type -> Struct.Location.Type get_location t = t.location -set_location : Battlemap.Location.Type -> Type -> Type +set_location : Struct.Location.Type -> Type -> Type set_location location char = {char | location = location} get_movement_points : Type -> Int diff --git a/src/battlemap/src/Struct/Direction.elm b/src/battlemap/src/Struct/Direction.elm new file mode 100644 index 0000000..c8eb28e --- /dev/null +++ b/src/battlemap/src/Struct/Direction.elm @@ -0,0 +1,37 @@ +module Struct.Direction exposing (Type(..), opposite_of, to_string) + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + None + | Left + | Right + | Up + | Down + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +opposite_of : Type -> Type +opposite_of d = + case d of + Left -> Right + Right -> Left + Up -> Down + Down -> Up + None -> None + +to_string : Type -> String +to_string dir = + case dir of + Right -> "R" + Left -> "L" + Up -> "U" + Down -> "D" + None -> "N" + diff --git a/src/battlemap/src/Struct/Error.elm b/src/battlemap/src/Struct/Error.elm new file mode 100644 index 0000000..3607d1d --- /dev/null +++ b/src/battlemap/src/Struct/Error.elm @@ -0,0 +1,43 @@ +module Struct.Error exposing (Type, Mode(..), new, to_string) + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Mode = + IllegalAction + | Programming + | Unimplemented + | Networking + +type alias Type = + { + mode: Mode, + message: String + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Mode -> String -> Type +new mode str = + { + mode = mode, + message = str + } + +to_string : Type -> String +to_string e = + ( + (case e.mode of + IllegalAction -> "Request discarded: " + Programming -> "Error in the program (please report): " + Unimplemented -> "Update discarded due to unimplemented feature: " + Networking -> "Error while conversing with the server: " + ) + ++ e.message + ) + diff --git a/src/battlemap/src/Struct/Event.elm b/src/battlemap/src/Struct/Event.elm new file mode 100644 index 0000000..dadc11d --- /dev/null +++ b/src/battlemap/src/Struct/Event.elm @@ -0,0 +1,24 @@ +module Struct.Event exposing (Type(..)) + +-- Elm ------------------------------------------------------------------------- +import Http + +-- Battlemap ------------------------------------------------------------------- +import Struct.Direction +import Struct.Location +import Struct.Character +import Struct.UI + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + DirectionRequested Struct.Direction.Type + | TileSelected Struct.Location.Ref + | CharacterSelected Struct.Character.Ref + | TurnEnded + | ScaleChangeRequested Float + | TabSelected Struct.UI.Tab + | ServerReplied (Result Http.Error (List (List String))) + | DebugTeamSwitchRequest + | DebugLoadBattlemapRequest diff --git a/src/battlemap/src/Struct/Location.elm b/src/battlemap/src/Struct/Location.elm new file mode 100644 index 0000000..ad9a811 --- /dev/null +++ b/src/battlemap/src/Struct/Location.elm @@ -0,0 +1,49 @@ +module Struct.Location exposing (..) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Direction + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + x : Int, + y : Int + } + +type alias Ref = (Int, Int) + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +neighbor : Type -> Struct.Direction.Type -> Type +neighbor loc dir = + case dir of + Struct.Direction.Right -> {loc | x = (loc.x + 1)} + Struct.Direction.Left -> {loc | x = (loc.x - 1)} + Struct.Direction.Up -> {loc | y = (loc.y - 1)} + Struct.Direction.Down -> {loc | y = (loc.y + 1)} + Struct.Direction.None -> loc + +get_ref : Type -> Ref +get_ref l = + (l.x, l.y) + +from_ref : Ref -> Type +from_ref (x, y) = + {x = x, y = y} + +dist : Type -> Type -> Int +dist loc_a loc_b = + ( + (abs (loc_a.x - loc_b.x)) + + + (abs (loc_a.y - loc_b.y)) + ) diff --git a/src/battlemap/src/Struct/Marker.elm b/src/battlemap/src/Struct/Marker.elm new file mode 100644 index 0000000..dd884e2 --- /dev/null +++ b/src/battlemap/src/Struct/Marker.elm @@ -0,0 +1,8 @@ +module Struct.Marker exposing (Type(..)) + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + CanAttack + | CanGoTo diff --git a/src/battlemap/src/Model.elm b/src/battlemap/src/Struct/Model.elm index 9798149..dc1a13d 100644 --- a/src/battlemap/src/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -1,4 +1,4 @@ -module Model exposing +module Struct.Model exposing ( Type, State(..), @@ -13,14 +13,14 @@ module Model exposing import Dict -- Battlemap ------------------------------------------------------------------- -import Battlemap -import Battlemap.Location +import Struct.Battlemap +import Struct.Location -import UI +import Struct.UI -import Error +import Struct.Error -import Character +import Struct.Character import Query.CharacterTurn -------------------------------------------------------------------------------- @@ -28,18 +28,18 @@ import Query.CharacterTurn -------------------------------------------------------------------------------- type State = Default - | InspectingTile Battlemap.Location.Ref - | InspectingCharacter Character.Ref + | InspectingTile Struct.Location.Ref + | InspectingCharacter Struct.Character.Ref type alias Type = { state: State, - battlemap: Battlemap.Type, - characters: (Dict.Dict Character.Ref Character.Type), - error: (Maybe Error.Type), + battlemap: Struct.Battlemap.Type, + characters: (Dict.Dict Struct.Character.Ref Struct.Character.Type), + error: (Maybe Struct.Error.Type), controlled_team: Int, player_id: String, - ui: UI.Type, + ui: Struct.UI.Type, char_turn: Query.CharacterTurn } @@ -50,12 +50,12 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -add_character : Type -> Character.Type -> Type +add_character : Type -> Struct.Character.Type -> Type add_character model char = {model | characters = (Dict.insert - (Character.get_ref char) + (Struct.Character.get_ref char) char model.characters ) @@ -64,22 +64,21 @@ add_character model char = get_state : Type -> State get_state model = model.state -reset : Type -> (Dict.Dict Character.Ref Character.Type) -> Type +reset : Type -> (Dict.Dict Struct.Character.Ref Struct.Character.Type) -> Type reset model characters = {model | state = Default, - battlemap = (Battlemap.reset model.battlemap), characters = characters, error = Nothing, - ui = (UI.set_previous_action model.ui Nothing), + ui = (Struct.UI.set_previous_action model.ui Nothing), char_turn = (Query.CharacterTurn.new) } -invalidate : Type -> Error.Type -> Type +invalidate : Type -> Struct.Error.Type -> Type invalidate model err = {model | error = (Just err), - ui = (UI.set_displayed_tab model.ui UI.StatusTab) + ui = (Struct.UI.set_displayed_tab model.ui Struct.UI.StatusTab) } clear_error : Type -> Type diff --git a/src/battlemap/src/Battlemap/Navigator.elm b/src/battlemap/src/Struct/Navigator.elm index b535dd6..56ef255 100644 --- a/src/battlemap/src/Battlemap/Navigator.elm +++ b/src/battlemap/src/Struct/Navigator.elm @@ -1,4 +1,4 @@ -module Battlemap.Navigator exposing +module Struct.Navigator exposing ( Type, Summary, @@ -13,52 +13,51 @@ module Battlemap.Navigator exposing try_adding_step, try_getting_path_to ) - +-- Elm ------------------------------------------------------------------------- import Dict -import Battlemap.Location -import Battlemap.Direction -import Battlemap.Marker - -import Battlemap.Navigator.Path -import Battlemap.Navigator.RangeIndicator +-- Battlemap ------------------------------------------------------------------- +import Struct.Location +import Struct.Direction +import Struct.Marker +import Struct.Path +import Struct.RangeIndicator -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type alias Type = { - starting_location: Battlemap.Location.Type, + starting_location: Struct.Location.Type, movement_dist: Int, attack_dist: Int, - path: Battlemap.Navigator.Path.Type, + path: Struct.Path.Type, range_indicators: (Dict.Dict - Battlemap.Location.Ref - Battlemap.Navigator.RangeIndicator.Type + Struct.Location.Ref + Struct.RangeIndicator.Type ) } type alias Summary = { - starting_location: Battlemap.Location.Type, - path: (List Battlemap.Direction.Type), - markers: (List (Battlemap.Location.Ref, Battlemap.Marker.Type)) + starting_location: Struct.Location.Type, + path: (List Struct.Direction.Type), + markers: (List (Struct.Location.Ref, Struct.Marker.Type)) } + -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- - new : ( - Battlemap.Location.Type -> + Struct.Location.Type -> Int -> Int -> - (Battlemap.Location.Type -> Int) -> + (Struct.Location.Type -> Int) -> Type ) new start_loc mov_dist atk_dist cost_fun = @@ -66,9 +65,9 @@ new start_loc mov_dist atk_dist cost_fun = starting_location = start_loc, movement_dist = mov_dist, attack_dist = atk_dist, - path = (Battlemap.Navigator.Path.new start_loc mov_dist), + path = (Struct.Path.new start_loc mov_dist), range_indicators = - (Battlemap.Navigator.RangeIndicator.generate + (Struct.RangeIndicator.generate start_loc mov_dist atk_dist @@ -76,39 +75,39 @@ new start_loc mov_dist atk_dist cost_fun = ) } -get_current_location : Type -> Battlemap.Location.Type +get_current_location : Type -> Struct.Location.Type get_current_location navigator = - (Battlemap.Navigator.Path.get_current_location navigator.path) + (Struct.Path.get_current_location navigator.path) -get_starting_location : Type -> Battlemap.Location.Type +get_starting_location : Type -> Struct.Location.Type get_starting_location navigator = navigator.starting_location get_remaining_points : Type -> Int get_remaining_points navigator = - (Battlemap.Navigator.Path.get_remaining_points navigator.path) + (Struct.Path.get_remaining_points navigator.path) get_range_markers : ( Type -> (List - (Battlemap.Location.Ref, Battlemap.Navigator.RangeIndicator.Type) + (Struct.Location.Ref, Struct.RangeIndicator.Type) ) ) get_range_markers navigator = (Dict.toList navigator.range_indicators) -get_path : Type -> (List Battlemap.Direction.Type) -get_path navigator = (Battlemap.Navigator.Path.get_summary navigator.path) +get_path : Type -> (List Struct.Direction.Type) +get_path navigator = (Struct.Path.get_summary navigator.path) get_summary : Type -> Summary get_summary navigator = { starting_location = navigator.starting_location, - path = (Battlemap.Navigator.Path.get_summary navigator.path), + path = (Struct.Path.get_summary navigator.path), markers = (List.map (\(loc, range_indicator) -> ( loc, - (Battlemap.Navigator.RangeIndicator.get_marker + (Struct.RangeIndicator.get_marker range_indicator ) ) @@ -123,7 +122,7 @@ clear_path : Type -> Type clear_path navigator = {navigator | path = - (Battlemap.Navigator.Path.new + (Struct.Path.new navigator.starting_location navigator.movement_dist ) @@ -131,13 +130,13 @@ clear_path navigator = try_adding_step : ( Type -> - Battlemap.Direction.Type -> - (Battlemap.Location.Type -> Int) -> + Struct.Direction.Type -> + (Struct.Location.Type -> Int) -> (Maybe Type) ) try_adding_step navigator dir cost_fun = case - (Battlemap.Navigator.Path.try_following_direction + (Struct.Path.try_following_direction cost_fun (Just navigator.path) dir @@ -148,12 +147,13 @@ try_adding_step navigator dir cost_fun = try_getting_path_to : ( Type -> - Battlemap.Location.Ref -> - (Maybe (List Battlemap.Direction.Type)) + Struct.Location.Ref -> + (Maybe (List Struct.Direction.Type)) ) try_getting_path_to navigator loc_ref = case (Dict.get loc_ref navigator.range_indicators) of (Just target) -> - (Just (Battlemap.Navigator.RangeIndicator.get_path target)) + (Just (Struct.RangeIndicator.get_path target)) + Nothing -> Nothing diff --git a/src/battlemap/src/Battlemap/Navigator/Path.elm b/src/battlemap/src/Struct/Path.elm index d0a430f..ba568c3 100644 --- a/src/battlemap/src/Battlemap/Navigator/Path.elm +++ b/src/battlemap/src/Struct/Path.elm @@ -1,4 +1,4 @@ -module Battlemap.Navigator.Path exposing +module Struct.Path exposing ( Type, new, @@ -8,12 +8,14 @@ module Battlemap.Navigator.Path exposing try_following_direction ) +-- Elm ------------------------------------------------------------------------- import Set -import Util.List +-- Battlemap ------------------------------------------------------------------- +import Struct.Direction +import Struct.Location -import Battlemap.Direction -import Battlemap.Location +import Util.List import Constants.Movement @@ -22,9 +24,9 @@ import Constants.Movement -------------------------------------------------------------------------------- type alias Type = { - current_location : Battlemap.Location.Type, - visited_locations : (Set.Set Battlemap.Location.Ref), - previous_directions : (List Battlemap.Direction.Type), + current_location : Struct.Location.Type, + visited_locations : (Set.Set Struct.Location.Ref), + previous_directions : (List Struct.Direction.Type), previous_points : (List Int), remaining_points : Int } @@ -34,7 +36,7 @@ type alias Type = -------------------------------------------------------------------------------- has_been_to : ( Type -> - Battlemap.Location.Type -> + Struct.Location.Type -> Bool ) has_been_to path location = @@ -42,15 +44,15 @@ has_been_to path location = (path.current_location == location) || (Set.member - (Battlemap.Location.get_ref location) + (Struct.Location.get_ref location) path.visited_locations ) ) try_moving_to : ( Type -> - Battlemap.Direction.Type -> - Battlemap.Location.Type -> + Struct.Direction.Type -> + Struct.Location.Type -> Int -> (Maybe Type) ) @@ -65,7 +67,7 @@ try_moving_to path dir next_loc cost = current_location = next_loc, visited_locations = (Set.insert - (Battlemap.Location.get_ref path.current_location) + (Struct.Location.get_ref path.current_location) path.visited_locations ), previous_directions = (dir :: path.previous_directions), @@ -79,8 +81,8 @@ try_moving_to path dir next_loc cost = try_backtracking_to : ( Type -> - Battlemap.Direction.Type -> - Battlemap.Location.Type -> + Struct.Direction.Type -> + Struct.Location.Type -> (Maybe Type) ) try_backtracking_to path dir location = @@ -94,14 +96,14 @@ try_backtracking_to path dir location = (Just (prev_dir_head, prev_dir_tail)), (Just (prev_pts_head, prev_pts_tail)) ) -> - if (prev_dir_head == (Battlemap.Direction.opposite_of dir)) + if (prev_dir_head == (Struct.Direction.opposite_of dir)) then (Just {path | current_location = location, visited_locations = (Set.remove - (Battlemap.Location.get_ref location) + (Struct.Location.get_ref location) path.visited_locations ), previous_directions = prev_dir_tail, @@ -118,7 +120,7 @@ try_backtracking_to path dir location = -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : Battlemap.Location.Type -> Int -> Type +new : Struct.Location.Type -> Int -> Type new start points = { current_location = start, @@ -128,19 +130,19 @@ new start points = remaining_points = points } -get_current_location : Type -> Battlemap.Location.Type +get_current_location : Type -> Struct.Location.Type get_current_location path = path.current_location get_remaining_points : Type -> Int get_remaining_points path = path.remaining_points -get_summary : Type -> (List Battlemap.Direction.Type) +get_summary : Type -> (List Struct.Direction.Type) get_summary path = path.previous_directions try_following_direction : ( - (Battlemap.Location.Type -> Int) -> + (Struct.Location.Type -> Int) -> (Maybe Type) -> - Battlemap.Direction.Type -> + Struct.Direction.Type -> (Maybe Type) ) try_following_direction cost_fun maybe_path dir = @@ -148,7 +150,7 @@ try_following_direction cost_fun maybe_path dir = (Just path) -> let next_location = - (Battlemap.Location.neighbor + (Struct.Location.neighbor path.current_location dir ) diff --git a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm b/src/battlemap/src/Struct/RangeIndicator.elm index b0283e0..90328a3 100644 --- a/src/battlemap/src/Battlemap/Navigator/RangeIndicator.elm +++ b/src/battlemap/src/Struct/RangeIndicator.elm @@ -1,4 +1,4 @@ -module Battlemap.Navigator.RangeIndicator exposing +module Struct.RangeIndicator exposing ( Type, generate, @@ -6,12 +6,14 @@ module Battlemap.Navigator.RangeIndicator exposing get_path ) +-- Elm ------------------------------------------------------------------------- import Dict import List -import Battlemap.Direction -import Battlemap.Location -import Battlemap.Marker +-- Battlemap ------------------------------------------------------------------- +import Struct.Direction +import Struct.Location +import Struct.Marker import Constants.Movement @@ -22,8 +24,8 @@ type alias Type = { distance: Int, range: Int, - path: (List Battlemap.Direction.Type), - marker: Battlemap.Marker.Type + path: (List Struct.Direction.Type), + marker: Struct.Marker.Type } -------------------------------------------------------------------------------- @@ -31,10 +33,10 @@ type alias Type = -------------------------------------------------------------------------------- get_closest : ( Int -> - Battlemap.Location.Ref -> + Struct.Location.Ref -> Type -> - (Battlemap.Location.Ref, Type) -> - (Battlemap.Location.Ref, Type) + (Struct.Location.Ref, Type) -> + (Struct.Location.Ref, Type) ) get_closest dist ref indicator (prev_ref, prev_indicator) = if @@ -66,20 +68,20 @@ is_closer new_dist new_range neighbor = handle_neighbors : ( Type -> - Battlemap.Location.Type -> + Struct.Location.Type -> Int -> Int -> - (Dict.Dict Battlemap.Location.Ref Type) -> - (Battlemap.Location.Type -> Int) -> - Battlemap.Direction.Type -> - (Dict.Dict Battlemap.Location.Ref Type) -> - (Dict.Dict Battlemap.Location.Ref Type) + (Dict.Dict Struct.Location.Ref Type) -> + (Struct.Location.Type -> Int) -> + Struct.Direction.Type -> + (Dict.Dict Struct.Location.Ref Type) -> + (Dict.Dict Struct.Location.Ref Type) ) handle_neighbors src_indicator src_loc dist range results cost_fun dir rem = let - neighbor_loc = (Battlemap.Location.neighbor src_loc dir) + neighbor_loc = (Struct.Location.neighbor src_loc dir) in - case (Dict.get (Battlemap.Location.get_ref neighbor_loc) results) of + case (Dict.get (Struct.Location.get_ref neighbor_loc) results) of (Just _) -> rem Nothing -> @@ -93,7 +95,7 @@ handle_neighbors src_indicator src_loc dist range results cost_fun dir rem = ( case (Dict.get - (Battlemap.Location.get_ref neighbor_loc) + (Struct.Location.get_ref neighbor_loc) rem ) of @@ -114,7 +116,7 @@ handle_neighbors src_indicator src_loc dist range results cost_fun dir rem = ) then (Dict.insert - (Battlemap.Location.get_ref neighbor_loc) + (Struct.Location.get_ref neighbor_loc) ( if (new_dist > dist) then @@ -122,14 +124,14 @@ handle_neighbors src_indicator src_loc dist range results cost_fun dir rem = distance = (dist + 1), range = new_range, path = (dir :: src_indicator.path), - marker = Battlemap.Marker.CanAttack + marker = Struct.Marker.CanAttack } else { distance = new_dist, range = 0, path = (dir :: src_indicator.path), - marker = Battlemap.Marker.CanGoTo + marker = Struct.Marker.CanGoTo } ) rem @@ -138,12 +140,12 @@ handle_neighbors src_indicator src_loc dist range results cost_fun dir rem = rem search : ( - (Dict.Dict Battlemap.Location.Ref Type) -> - (Dict.Dict Battlemap.Location.Ref Type) -> + (Dict.Dict Struct.Location.Ref Type) -> + (Dict.Dict Struct.Location.Ref Type) -> Int -> Int -> - (Battlemap.Location.Type -> Int) -> - (Dict.Dict Battlemap.Location.Ref Type) + (Struct.Location.Type -> Int) -> + (Dict.Dict Struct.Location.Ref Type) ) search result remaining dist range cost_fun = if (Dict.isEmpty remaining) @@ -160,7 +162,7 @@ search result remaining dist range cost_fun = distance = Constants.Movement.cost_when_out_of_bounds, path = [], range = Constants.Movement.cost_when_out_of_bounds, - marker = Battlemap.Marker.CanAttack + marker = Struct.Marker.CanAttack } ) remaining @@ -174,9 +176,9 @@ search result remaining dist range cost_fun = ( if (min.range > 0) then - Battlemap.Marker.CanAttack + Struct.Marker.CanAttack else - Battlemap.Marker.CanGoTo + Struct.Marker.CanGoTo ) } result @@ -184,7 +186,7 @@ search result remaining dist range cost_fun = (List.foldl (handle_neighbors min - (Battlemap.Location.from_ref min_loc_ref) + (Struct.Location.from_ref min_loc_ref) dist range result @@ -192,10 +194,10 @@ search result remaining dist range cost_fun = ) (Dict.remove min_loc_ref remaining) [ - Battlemap.Direction.Left, - Battlemap.Direction.Right, - Battlemap.Direction.Up, - Battlemap.Direction.Down + Struct.Direction.Left, + Struct.Direction.Right, + Struct.Direction.Up, + Struct.Direction.Down ] ) dist @@ -207,22 +209,22 @@ search result remaining dist range cost_fun = -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- generate : ( - Battlemap.Location.Type -> + Struct.Location.Type -> Int -> Int -> - (Battlemap.Location.Type -> Int) -> - (Dict.Dict Battlemap.Location.Ref Type) + (Struct.Location.Type -> Int) -> + (Dict.Dict Struct.Location.Ref Type) ) generate location dist range cost_fun = (search Dict.empty (Dict.insert - (Battlemap.Location.get_ref location) + (Struct.Location.get_ref location) { distance = 0, path = [], range = 0, - marker = Battlemap.Marker.CanGoTo + marker = Struct.Marker.CanGoTo } Dict.empty ) @@ -231,8 +233,8 @@ generate location dist range cost_fun = (cost_fun) ) -get_marker : Type -> Battlemap.Marker.Type +get_marker : Type -> Struct.Marker.Type get_marker indicator = indicator.marker -get_path : Type -> (List Battlemap.Direction.Type) +get_path : Type -> (List Struct.Direction.Type) get_path indicator = indicator.path diff --git a/src/battlemap/src/Battlemap/Tile.elm b/src/battlemap/src/Struct/Tile.elm index 23ee2a8..d75e74e 100644 --- a/src/battlemap/src/Battlemap/Tile.elm +++ b/src/battlemap/src/Struct/Tile.elm @@ -1,4 +1,4 @@ -module Battlemap.Tile exposing +module Struct.Tile exposing ( Type, new, @@ -9,14 +9,14 @@ module Battlemap.Tile exposing ) -- Battlemap ------------------------------------------------------------------- -import Battlemap.Location +import Struct.Location -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type alias Type = { - location : Battlemap.Location.Type, + location : Struct.Location.Type, icon_id : String, crossing_cost : Int } @@ -44,7 +44,7 @@ error_tile x y = crossing_cost = 1 } -get_location : Type -> Battlemap.Location.Type +get_location : Type -> Struct.Location.Type get_location tile = tile.location get_icon_id : Type -> String diff --git a/src/battlemap/src/UI.elm b/src/battlemap/src/Struct/UI.elm index 978ed00..3ef895d 100644 --- a/src/battlemap/src/UI.elm +++ b/src/battlemap/src/Struct/UI.elm @@ -1,4 +1,4 @@ -module UI exposing +module Struct.UI exposing ( Type, Tab(..), @@ -23,23 +23,23 @@ module UI exposing ) -- Battlemap ------------------------------------------------------------------- -import Battlemap.Location +import Struct.Location -import Character +import Struct.Character -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type Tab = StatusTab - | CharactersTab + | Struct.CharactersTab | SettingsTab type Action = UsedManualControls - | SelectedLocation Battlemap.Location.Ref - | SelectedCharacter Character.Ref - | AttackedCharacter Character.Ref + | SelectedLocation Struct.Location.Ref + | SelectedCharacter Struct.Character.Ref + | AttackedCharacter Struct.Character.Ref type alias Type = { @@ -89,12 +89,12 @@ to_string : Tab -> String to_string tab = case tab of StatusTab -> "Status" - CharactersTab -> "Characters" + Struct.CharactersTab -> "Characters" SettingsTab -> "Settings" get_all_tabs : (List Tab) get_all_tabs = - [StatusTab, CharactersTab, SettingsTab] + [StatusTab, Struct.CharactersTab, SettingsTab] -- ManualControls -------------------------------------------------------------- has_manual_controls_enabled : Type -> Bool diff --git a/src/battlemap/src/Subscriptions.elm b/src/battlemap/src/Subscriptions.elm deleted file mode 100644 index 83df587..0000000 --- a/src/battlemap/src/Subscriptions.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Subscriptions exposing (..) - -import Model -import Event - -subscriptions : Model.Type -> (Sub Event.Type) -subscriptions model = Sub.none diff --git a/src/battlemap/src/Update.elm b/src/battlemap/src/Update.elm deleted file mode 100644 index 787fc8e..0000000 --- a/src/battlemap/src/Update.elm +++ /dev/null @@ -1,90 +0,0 @@ -module Update exposing (update) - -import Event - -import Error - -import UI - -import Model -import Model.RequestDirection -import Model.SelectTile -import Model.SelectCharacter -import Model.EndTurn -import Model.HandleServerReply - -import Send.LoadBattlemap - -update : Event.Type -> Model.Type -> (Model.Type, (Cmd Event.Type)) -update event model = - let - new_model = (Model.clear_error model) - in - case event of - (Event.DirectionRequested d) -> - ((Model.RequestDirection.apply_to new_model d), Cmd.none) - - (Event.TileSelected loc) -> - (Model.SelectTile.apply_to new_model loc) - - (Event.CharacterSelected char_id) -> - ((Model.SelectCharacter.apply_to new_model char_id), Cmd.none) - - Event.TurnEnded -> - (Model.EndTurn.apply_to new_model) - - (Event.ScaleChangeRequested mod) -> - if (mod == 0.0) - then - ({model | ui = (UI.reset_zoom_level model.ui)}, Cmd.none) - else - ({model | ui = (UI.mod_zoom_level model.ui mod)}, Cmd.none) - - (Event.TabSelected tab) -> - ({model | ui = (UI.set_displayed_tab model.ui tab)}, Cmd.none) - - (Event.DebugTeamSwitchRequest) -> - if (model.controlled_team == 0) - then - ( - (Model.reset - {model | - controlled_team = 1, - player_id = "1" - } - model.characters - ), - Cmd.none - ) - else - ( - (Model.reset - {model | - controlled_team = 0, - player_id = "0" - } - model.characters - ), - Cmd.none - ) - - (Event.DebugLoadBattlemapRequest) -> - ( - model, - (case (Send.LoadBattlemap.try model) of - (Just cmd) -> cmd - Nothing -> Cmd.none - ) - ) - - (Event.ServerReplied (Result.Err error)) -> - ( - (Model.invalidate - model - (Error.new Error.Networking (toString error)) - ), - Cmd.none - ) - - (Event.ServerReplied (Result.Ok commands)) -> - (Model.HandleServerReply.apply_to model commands) diff --git a/src/battlemap/src/Update/ChangeScale.elm b/src/battlemap/src/Update/ChangeScale.elm new file mode 100644 index 0000000..139c662 --- /dev/null +++ b/src/battlemap/src/Update/ChangeScale.elm @@ -0,0 +1,26 @@ +module Update.ChangeScale exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Model +import Struct.Event +import Struct.UI + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Float -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model mod = + if (mod == 0.0) + then + ({model | ui = (Struct.UI.reset_zoom_level model.ui)}, Cmd.none) + else + ({model | ui = (Struct.UI.mod_zoom_level model.ui mod)}, Cmd.none) diff --git a/src/battlemap/src/Model/EndTurn.elm b/src/battlemap/src/Update/EndTurn.elm index fd0ec83..fd0ec83 100644 --- a/src/battlemap/src/Model/EndTurn.elm +++ b/src/battlemap/src/Update/EndTurn.elm diff --git a/src/battlemap/src/Model/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm index 572fa0c..13c493c 100644 --- a/src/battlemap/src/Model/HandleServerReply.elm +++ b/src/battlemap/src/Update/HandleServerReply.elm @@ -39,8 +39,19 @@ apply_command cmd model = -------------------------------------------------------------------------------- apply_to : ( Model.Type -> - (List (List String)) -> + (Result Http.Error (List (List String)) -> (Model.Type, (Cmd Event.Type)) ) -apply_to model serialized_commands = - ((List.foldl (apply_command) model serialized_commands), Cmd.none) +apply_to model query_result = + case query_result of + (Result.Err error) -> + ( + (Model.invalidate + model + (Error.new Error.Networking (toString error)) + ), + Cmd.none + ) + + (Result.Ok commands) -> + ((List.foldl (apply_command) model serialized_commands), Cmd.none) diff --git a/src/battlemap/src/Model/HandleServerReply/AddChar.elm b/src/battlemap/src/Update/HandleServerReply/AddChar.elm index f5f30ba..f5f30ba 100644 --- a/src/battlemap/src/Model/HandleServerReply/AddChar.elm +++ b/src/battlemap/src/Update/HandleServerReply/AddChar.elm diff --git a/src/battlemap/src/Model/HandleServerReply/SetMap.elm b/src/battlemap/src/Update/HandleServerReply/SetMap.elm index e815093..e815093 100644 --- a/src/battlemap/src/Model/HandleServerReply/SetMap.elm +++ b/src/battlemap/src/Update/HandleServerReply/SetMap.elm diff --git a/src/battlemap/src/Model/RequestDirection.elm b/src/battlemap/src/Update/RequestDirection.elm index 4e52897..3d6dfbe 100644 --- a/src/battlemap/src/Model/RequestDirection.elm +++ b/src/battlemap/src/Update/RequestDirection.elm @@ -1,32 +1,29 @@ -module Model.RequestDirection exposing (apply_to) +module Update.RequestDirection exposing (apply_to) -- Elm ------------------------------------------------------------------------- import Dict -- Battlemap ------------------------------------------------------------------- -import Battlemap -import Battlemap.Direction - -import Character - -import UI - -import Model -import Error +import Struct.Battlemap +import Struct.Direction +import Struct.Character +import Struct.UI +import Struct.Model +import Struct.Error -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- make_it_so : ( - Model.Type -> - Character.Ref -> - Battlemap.Direction.Type -> - Model.Type + Struct.Model.Type -> + Struct.Character.Ref -> + Struct.Direction.Type -> + Struct.Model.Type ) make_it_so model char_ref dir = let new_bmap = - (Battlemap.try_adding_step_to_navigator + (Struct.Battlemap.try_adding_step_to_navigator model.battlemap (Dict.values model.characters) dir @@ -37,17 +34,17 @@ make_it_so model char_ref dir = {model | battlemap = bmap, ui = - (UI.set_previous_action + (Struct.UI.set_previous_action model.ui - (Just UI.UsedManualControls) + (Just Struct.UI.UsedManualControls) ) } Nothing -> - (Model.invalidate + (Struct.Model.invalidate model - (Error.new - Error.IllegalAction + (Struct.Error.new + Struct.Error.IllegalAction "Unreachable/occupied tile." ) ) @@ -55,17 +52,27 @@ make_it_so model char_ref dir = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type +apply_to : ( + Struct.Model.Type -> + Struct.Direction.Type -> + Struct.Model.Type + ) apply_to model dir = case model.controlled_character of (Just char_ref) -> - (make_it_so model char_ref dir) + ( + (make_it_so model char_ref dir), + Cmd.none + ) _ -> - (Model.invalidate - model - (Error.new - Error.IllegalAction - "This can only be done while moving a character." - ) + ( + (Struct.Model.invalidate + model + (Struct.Error.new + Struct.Error.IllegalAction + "This can only be done while moving a character." + ) + ), + Cmd.none ) diff --git a/src/battlemap/src/Update/SelectCharacter.elm b/src/battlemap/src/Update/SelectCharacter.elm new file mode 100644 index 0000000..1535c8c --- /dev/null +++ b/src/battlemap/src/Update/SelectCharacter.elm @@ -0,0 +1,124 @@ +module Update.SelectCharacter exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Battlemap ------------------------------------------------------------------- +import Struct.Battlemap +import Struct.Character +import Struct.Direction +import Struct.Error +import Struct.UI +import Struct.Model + +import Update.RequestDirection + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +autopilot : Struct.Direction.Type -> Struct.Model.Type -> Struct.Model.Type +autopilot dir model = + (Model.RequestDirection.apply_to model dir) + +attack_character : ( + Struct.Model.Type -> + Struct.Character.Ref -> + Struct.Character.Ref -> + Struct.Character.Type -> + Struct.Model.Type + ) +attack_character model main_char_id target_char_id target_char = + {model | + targets = [target_char_id], + ui = (Struct.UI.set_previous_action model.ui Nothing) + } + +select_character : ( + Struct.Model.Type -> + Struct.Character.Ref -> + Struct.Character.Type -> + Struct.Model.Type + ) +select_character model target_char_id target_char = + if ((Struct.Character.is_enabled target_char)) + then + {model | + state = Struct.Model.Default, + controlled_character = (Just target_char_id), + ui = (Struct.UI.set_previous_action model.ui Nothing), + battlemap = + (Struct.Battlemap.set_navigator + (Struct.Character.get_location target_char) + (Struct.Character.get_movement_points target_char) + (Struct.Character.get_attack_range target_char) + (Dict.values model.characters) + model.battlemap + ) + } + else + {model | + ui = + (Struct.UI.set_previous_action + model.ui + (Just (Struct.UI.SelectedCharacter target_char_id)) + ) + } + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Character.Ref -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model target_char_id = + if + ( + (Struct.UI.get_previous_action model.ui) + == + (Just (Struct.UI.SelectedCharacter target_char_id)) + ) + then + case (Dict.get target_char_id model.characters) of + (Just target_char) -> + case model.controlled_character of + (Just main_char_id) -> + ( + (attack_character + model + main_char_id + target_char_id + target_char + ), + Cmd.none + ) + + _ -> + ( + (select_character model target_char_id target_char), + Cmd.none + ) + + Nothing -> + ( + (Struct.Model.invalidate + model + (Struct.Error.new + Struct.Error.Programming + "SelectCharacter: Unknown char selected." + ) + ), + Cmd.none + ) + else + ( + {model | + ui = + (Struct.UI.set_previous_action + model.ui + (Just (Struct.UI.SelectedCharacter target_char_id)) + ) + }, + Cmd.none + ) diff --git a/src/battlemap/src/Update/SelectTab.elm b/src/battlemap/src/Update/SelectTab.elm new file mode 100644 index 0000000..c48b0fc --- /dev/null +++ b/src/battlemap/src/Update/SelectTab.elm @@ -0,0 +1,25 @@ +module Update.SelectTab exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Model +import Struct.Event +import Struct.UI + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.UI.Tab -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model tab = + ( + {model | ui = (Struct.UI.set_displayed_tab model.ui tab)}, + Cmd.none + ) diff --git a/src/battlemap/src/Model/SelectTile.elm b/src/battlemap/src/Update/SelectTile.elm index 5ce3c3c..5ce3c3c 100644 --- a/src/battlemap/src/Model/SelectTile.elm +++ b/src/battlemap/src/Update/SelectTile.elm diff --git a/src/battlemap/src/Update/SendLoadBattlemapRequest.elm b/src/battlemap/src/Update/SendLoadBattlemapRequest.elm new file mode 100644 index 0000000..2ed248d --- /dev/null +++ b/src/battlemap/src/Update/SendLoadBattlemapRequest.elm @@ -0,0 +1,28 @@ +module Update.SendLoadBattlemapRequest exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Model +import Struct.Event +import Struct.UI + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model = + ( + model, + (case (Send.LoadBattlemap.try model) of + (Just cmd) -> cmd + Nothing -> Cmd.none + ) + ) + diff --git a/src/battlemap/src/Update/SwitchTeam.elm b/src/battlemap/src/Update/SwitchTeam.elm new file mode 100644 index 0000000..f85dd87 --- /dev/null +++ b/src/battlemap/src/Update/SwitchTeam.elm @@ -0,0 +1,42 @@ +module Update.SwitchTeam exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Model +import Struct.Event + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model = + if (model.controlled_team == 0) + then + ( + (Model.reset + {model | + controlled_team = 1, + player_id = "1" + } + model.characters + ), + Cmd.none + ) + else + ( + (Model.reset + {model | + controlled_team = 0, + player_id = "0" + } + model.characters + ), + Cmd.none + ) |