| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/battlemap')
| -rw-r--r-- | src/battlemap/src/Battlemap.elm | 10 | ||||
| -rw-r--r-- | src/battlemap/src/Battlemap/Tile.elm | 29 | ||||
| -rw-r--r-- | src/battlemap/src/Model.elm | 12 | ||||
| -rw-r--r-- | src/battlemap/src/Model/HandleServerReply.elm | 4 | ||||
| -rw-r--r-- | src/battlemap/src/Model/HandleServerReply/SetMap.elm | 79 | ||||
| -rw-r--r-- | src/battlemap/src/Model/SetMap.elm | 76 | ||||
| -rw-r--r-- | src/battlemap/src/UI.elm | 1 | 
7 files changed, 133 insertions, 78 deletions
| diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm index f0e2b04..5649861 100644 --- a/src/battlemap/src/Battlemap.elm +++ b/src/battlemap/src/Battlemap.elm @@ -1,6 +1,7 @@  module Battlemap exposing     (        Type, +      new,        reset,        get_navigator_remaining_points,        get_tiles, @@ -95,6 +96,15 @@ tile_cost_function bmap start_loc char_list loc =  get_tiles : Type -> (Array.Array Battlemap.Tile.Type)  get_tiles bmap = bmap.content +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 | diff --git a/src/battlemap/src/Battlemap/Tile.elm b/src/battlemap/src/Battlemap/Tile.elm index 255310a..23ee2a8 100644 --- a/src/battlemap/src/Battlemap/Tile.elm +++ b/src/battlemap/src/Battlemap/Tile.elm @@ -1,13 +1,19 @@  module Battlemap.Tile exposing     (        Type, +      new, +      error_tile,        get_location,        get_icon_id,        get_cost     ) +-- Battlemap -------------------------------------------------------------------  import Battlemap.Location +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +--------------------------------------------------------------------------------  type alias Type =     {        location : Battlemap.Location.Type, @@ -15,6 +21,29 @@ type alias Type =        crossing_cost : Int     } +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Int -> Int -> String -> Int -> Type +new x y icon_id crossing_cost = +   { +      location = {x = x, y = y}, +      icon_id = icon_id, +      crossing_cost = crossing_cost +   } + +error_tile : Int -> Int -> Type +error_tile x y = +   { +      location = {x = x, y = y}, +      icon_id = "error", +      crossing_cost = 1 +   } +  get_location : Type -> Battlemap.Location.Type  get_location tile = tile.location diff --git a/src/battlemap/src/Model.elm b/src/battlemap/src/Model.elm index f85eb34..082737f 100644 --- a/src/battlemap/src/Model.elm +++ b/src/battlemap/src/Model.elm @@ -8,8 +8,10 @@ module Model exposing        clear_error     ) +-- Elm -------------------------------------------------------------------------  import Dict +-- Battlemap -------------------------------------------------------------------  import Battlemap  import Battlemap.Location @@ -19,6 +21,9 @@ import Error  import Character +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +--------------------------------------------------------------------------------  type State =     Default     | ControllingCharacter Character.Ref @@ -35,6 +40,13 @@ type alias Type =        ui: UI.Type     } +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +--------------------------------------------------------------------------------  get_state : Type -> State  get_state model = model.state diff --git a/src/battlemap/src/Model/HandleServerReply.elm b/src/battlemap/src/Model/HandleServerReply.elm index 59b614c..22b222b 100644 --- a/src/battlemap/src/Model/HandleServerReply.elm +++ b/src/battlemap/src/Model/HandleServerReply.elm @@ -8,7 +8,7 @@ import Model  import Error  import Event -import Model.SetMap +import Model.HandleServerReply.SetMap  --------------------------------------------------------------------------------  -- LOCAL ----------------------------------------------------------------------- @@ -19,7 +19,7 @@ apply_command cmd model =        cmd     of        ["set_map", data] -> -         (Model.SetMap.apply_to model data) +         (Model.HandleServerReply.SetMap.apply_to model data)        ["add_char", data] -> model diff --git a/src/battlemap/src/Model/HandleServerReply/SetMap.elm b/src/battlemap/src/Model/HandleServerReply/SetMap.elm new file mode 100644 index 0000000..ab21075 --- /dev/null +++ b/src/battlemap/src/Model/HandleServerReply/SetMap.elm @@ -0,0 +1,79 @@ +module Model.HandleServerReply.SetMap exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Array +import Json.Decode + +-- Battlemap ------------------------------------------------------------------- +import Battlemap +import Battlemap.Tile + +import Model + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias MapData = +   { +      width : Int, +      height : Int, +      content : (List (List Int)) +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +deserialize_tile : Int -> Int -> (List Int) -> Battlemap.Tile.Type +deserialize_tile map_width index data = +   case data of +      [icon_id, cost] -> +         (Battlemap.Tile.new +            (index % map_width) +            (index // map_width) +            (toString icon_id) +            cost +         ) + +      _ -> +         (Battlemap.Tile.error_tile +            (index % map_width) +            (index // map_width) +         ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : Model.Type -> String -> Model.Type +apply_to model serialized_map = +   case +      (Json.Decode.decodeString +         (Json.Decode.map3 MapData +            (Json.Decode.field "width" Json.Decode.int) +            (Json.Decode.field "height" Json.Decode.int) +            (Json.Decode.field +               "content" +               (Json.Decode.list +                  (Json.Decode.list Json.Decode.int) +               ) +            ) +         ) +         serialized_map +      ) +   of +      (Result.Ok map_data) -> +         (Model.reset +            {model | +               battlemap = +                  (Battlemap.new +                     map_data.width +                     map_data.height +                     (List.indexedMap +                        (deserialize_tile map_data.width) +                        map_data.content +                     ) +                  ) +            } +            model.characters +         ) + +      _ -> model diff --git a/src/battlemap/src/Model/SetMap.elm b/src/battlemap/src/Model/SetMap.elm deleted file mode 100644 index eb6dc5b..0000000 --- a/src/battlemap/src/Model/SetMap.elm +++ /dev/null @@ -1,76 +0,0 @@ -module Model.SetMap exposing (apply_to) -import Array -import Json.Decode - - - -import Battlemap.Tile - -import Model - -type alias MapData = -   { -      width : Int, -      height : Int, -      content : (List (List Int)) -   } - -from_int : Int -> Int -> (List Int) -> Battlemap.Tile.Type -from_int map_width index data = -   case data of -      [icon_id, cost] -> -         { -            location = -               { -                  x = (index % map_width), -                  y = (index // map_width) -               }, -            icon_id = (toString icon_id), -            crossing_cost = cost -         } -      _ -> -         { -            location = -               { -                  x = (index % map_width), -                  y = (index // map_width) -               }, -            icon_id = "0", -            crossing_cost = 1 -         } - -apply_to : Model.Type -> String -> Model.Type -apply_to model serialized_map = -   case -      (Json.Decode.decodeString -         (Json.Decode.map3 MapData -            (Json.Decode.field "width" Json.Decode.int) -            (Json.Decode.field "height" Json.Decode.int) -            (Json.Decode.field -               "content" -               (Json.Decode.list -                  (Json.Decode.list Json.Decode.int) -               ) -            ) -         ) -         serialized_map -      ) -   of -      (Result.Ok map_data) -> -         {model | -            battlemap = -               { -                  width = map_data.width, -                  height = map_data.height, -                  content = -                     (Array.fromList -                        (List.indexedMap -                           (from_int map_data.width) -                           map_data.content -                        ) -                     ), -                  navigator = Nothing -               } -         } - -      _ -> model diff --git a/src/battlemap/src/UI.elm b/src/battlemap/src/UI.elm index 9f432e8..f30a0fc 100644 --- a/src/battlemap/src/UI.elm +++ b/src/battlemap/src/UI.elm @@ -94,6 +94,7 @@ to_string tab =  get_all_tabs : (List Tab)  get_all_tabs =     [StatusTab, CharactersTab, SettingsTab] +  -- ManualControls --------------------------------------------------------------  has_manual_controls_enabled : Type -> Bool  has_manual_controls_enabled ui = ui.show_manual_controls | 


