| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-06-18 21:45:38 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-06-18 21:45:38 +0200 | 
| commit | 80f5afd5641eec8cb442e4d61510c946f01e12ac (patch) | |
| tree | f6adbd89e9e47422ffb0a78440aa34abf621c8dd /src | |
| parent | 5c8422c9a14ccb6b50ccbbbcea6d1f1110bdb0cd (diff) | |
Maybe adds support for the new Tile system.
I can't test until I fix the server, which is missing a file.
Diffstat (limited to 'src')
20 files changed, 184 insertions, 86 deletions
| diff --git a/src/battlemap/src/Comm/SetMap.elm b/src/battlemap/src/Comm/SetMap.elm index 9a9668a..84e4b5f 100644 --- a/src/battlemap/src/Comm/SetMap.elm +++ b/src/battlemap/src/Comm/SetMap.elm @@ -4,8 +4,6 @@ module Comm.SetMap exposing (decode)  import Json.Decode  -- Battlemap ------------------------------------------------------------------- -import Data.Tiles -  import Struct.Battlemap  import Struct.Model  import Struct.ServerReply @@ -24,13 +22,14 @@ type alias MapData =  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -deserialize_tile : Int -> Int -> Int -> Struct.Tile.Type -deserialize_tile map_width index id = -   (Struct.Tile.new +deserialize_tile_instance : Int -> Int -> Int -> Struct.Tile.Instance +deserialize_tile_instance map_width index id = +   (Struct.Tile.new_instance        (index % map_width)        (index // map_width) -      (Data.Tiles.get_icon id) -      (Data.Tiles.get_cost id) +      (toString id) +      -1 +      -1     )  internal_decoder : MapData -> Struct.ServerReply.Type @@ -40,7 +39,7 @@ internal_decoder map_data =           map_data.w           map_data.h           (List.indexedMap -            (deserialize_tile map_data.w) +            (deserialize_tile_instance map_data.w)              map_data.t           )        ) diff --git a/src/battlemap/src/Constants/UI.elm b/src/battlemap/src/Constants/UI.elm index 701caac..4c70388 100644 --- a/src/battlemap/src/Constants/UI.elm +++ b/src/battlemap/src/Constants/UI.elm @@ -3,6 +3,9 @@ module Constants.UI exposing (..)  tile_size : Int  tile_size = 32 +variants_per_tile : Int +variants_per_tile = 9 +  viewer_html_id : String  viewer_html_id = "battlemap_viewer" diff --git a/src/battlemap/src/Data/Tiles.elm b/src/battlemap/src/Data/Tiles.elm deleted file mode 100644 index 2b6a582..0000000 --- a/src/battlemap/src/Data/Tiles.elm +++ /dev/null @@ -1,17 +0,0 @@ -module Data.Tiles exposing (..) - --- TODO: should be given by the server, as all other Data. - -import Constants.Movement - -get_icon : Int -> String -get_icon i = -   toString(i) - -get_cost : Int -> Int -get_cost i = -   case i of -      0 -> 6 -      1 -> 12 -      2 -> 24 -      _ -> Constants.Movement.cost_when_occupied_tile diff --git a/src/battlemap/src/Struct/Armor.elm b/src/battlemap/src/Struct/Armor.elm index 8374179..3fb4738 100644 --- a/src/battlemap/src/Struct/Armor.elm +++ b/src/battlemap/src/Struct/Armor.elm @@ -52,6 +52,21 @@ type Category =  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +finish_decoding : PartiallyDecoded -> Type +finish_decoding add_armor = +   { +      id = add_armor.id, +      name = add_armor.nam, +      category = +         ( +            case add_armor.ct of +               "k" -> Kinetic +               "c" -> Chain +               "p" -> Plate +               _   -> Leather +         ), +      coef = add_armor.cf +   }  --------------------------------------------------------------------------------  -- EXPORTED -------------------------------------------------------------------- @@ -124,22 +139,6 @@ apply_to_attributes ar atts =                 )              ) -finish_decoding : PartiallyDecoded -> Type -finish_decoding add_armor = -   { -      id = add_armor.id, -      name = add_armor.nam, -      category = -         ( -            case add_armor.ct of -               "k" -> Kinetic -               "c" -> Chain -               "p" -> Plate -               _   -> Leather -         ), -      coef = add_armor.cf -   } -  decoder : (Json.Decode.Decoder Type)  decoder =     (Json.Decode.map diff --git a/src/battlemap/src/Struct/Battlemap.elm b/src/battlemap/src/Struct/Battlemap.elm index 700c46d..5387039 100644 --- a/src/battlemap/src/Struct/Battlemap.elm +++ b/src/battlemap/src/Struct/Battlemap.elm @@ -7,12 +7,15 @@ module Struct.Battlemap exposing        get_height,        get_tiles,        get_movement_cost_function, +      solve_tiles,        try_getting_tile_at     )  -- Elm -------------------------------------------------------------------------  import Array +import Dict +  -- Battlemap -------------------------------------------------------------------  import Struct.Character  import Struct.Tile @@ -27,7 +30,7 @@ type alias Type =     {        width: Int,        height: Int, -      content: (Array.Array Struct.Tile.Type) +      content: (Array.Array Struct.Tile.Instance)     }  -------------------------------------------------------------------------------- @@ -46,7 +49,6 @@ has_location loc bmap =        && (loc.y < bmap.height)     ) -  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -56,7 +58,7 @@ get_width bmap = bmap.width  get_height : Type -> Int  get_height bmap = bmap.height -get_tiles : Type -> (Array.Array Struct.Tile.Type) +get_tiles : Type -> (Array.Array Struct.Tile.Instance)  get_tiles bmap = bmap.content  empty : Type @@ -67,7 +69,7 @@ empty =        content = (Array.empty)     } -new : Int -> Int -> (List Struct.Tile.Type) -> Type +new : Int -> Int -> (List Struct.Tile.Instance) -> Type  new width height tiles =     {        width = width, @@ -78,7 +80,7 @@ new width height tiles =  try_getting_tile_at : (        Struct.Location.Type ->        Type -> -      (Maybe Struct.Tile.Type) +      (Maybe Struct.Tile.Instance)     )  try_getting_tile_at loc bmap =     (Array.get (location_to_index loc bmap) bmap.content) @@ -109,8 +111,15 @@ get_movement_cost_function bmap start_loc char_list loc =              then                 Constants.Movement.cost_when_occupied_tile              else -               (Struct.Tile.get_cost tile) +               (Struct.Tile.get_instance_cost tile)           Nothing -> Constants.Movement.cost_when_out_of_bounds     else        Constants.Movement.cost_when_out_of_bounds + +solve_tiles : (Dict.Dict Struct.Tile.Ref Struct.Tile.Type) -> Type -> Type +solve_tiles tiles bmap = +   {bmap | +      content = +         (Array.map (Struct.Tile.solve_tile_instance tiles) bmap.content) +   } diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index 63474d2..7a331f6 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -22,8 +22,9 @@ import Struct.Armor  import Struct.Battlemap  import Struct.Character  import Struct.CharacterTurn -import Struct.TurnResult  import Struct.Error +import Struct.Tile +import Struct.TurnResult  import Struct.UI  import Struct.Weapon diff --git a/src/battlemap/src/Struct/ServerReply.elm b/src/battlemap/src/Struct/ServerReply.elm index 64eade1..5b88933 100644 --- a/src/battlemap/src/Struct/ServerReply.elm +++ b/src/battlemap/src/Struct/ServerReply.elm @@ -6,6 +6,7 @@ module Struct.ServerReply exposing (Type(..))  import Struct.Armor  import Struct.Battlemap  import Struct.Character +import Struct.Tile  import Struct.TurnResult  import Struct.Weapon diff --git a/src/battlemap/src/Struct/Tile.elm b/src/battlemap/src/Struct/Tile.elm index cf23339..3bd2336 100644 --- a/src/battlemap/src/Struct/Tile.elm +++ b/src/battlemap/src/Struct/Tile.elm @@ -1,26 +1,65 @@  module Struct.Tile exposing     ( +      Ref,        Type, +      Instance,        new, -      error_tile, +      new_instance, +      error_tile_instance, +      get_id, +      get_name, +      get_range_minimum, +      get_range_maximum, +      get_cost, +      get_instance_cost,        get_location,        get_icon_id, -      get_cost,        get_variant_id, +      solve_tile_instance,        decoder     ) +-- Elm ------------------------------------------------------------------------- +import Dict + +import Json.Decode +import Json.Decode.Pipeline +  -- Battlemap ------------------------------------------------------------------- +import Constants.UI +import Constants.Movement +  import Struct.Location  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +type alias Ref = Int + +type alias PartiallyDecoded = +   { +      id : Int, +      nam : String, +      ct : Int, +      rmi : Int, +      rma : Int +   } +  type alias Type =     { +      id : Int, +      name : String, +      crossing_cost : Int, +      range_minimum : Int, +      range_maximum : Int +   } + +type alias Instance = +   {        location : Struct.Location.Type,        icon_id : String, -      crossing_cost : Int +      crossing_cost : Int, +      type_id : Int     }  -------------------------------------------------------------------------------- @@ -28,40 +67,110 @@ type alias Type =  --------------------------------------------------------------------------------  noise_function : Int -> Int -> Int -> Int  noise_function a b c = -   (round -         (radians (toFloat ((a + 1) * 2 + (b + 1) * 3 + c))) -   ) +   (round (radians (toFloat ((a + 1) * 2 + (b + 1) * 3 + c)))) + +finish_decoding : PartiallyDecoded -> Type +finish_decoding add_tile = +   { +      id = add_tile.id, +      name = add_tile.nam, +      crossing_cost = add_tile.ct, +      range_minimum = add_tile.rmi, +      range_maximum = add_tile.rma +   }  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- -new : Int -> Int -> String -> Int -> Type -new x y icon_id crossing_cost = +new : Int -> String -> Int -> Int -> Int -> Type +new id name crossing_cost range_minimum range_maximum = +   { +      id = id, +      name = name, +      crossing_cost = crossing_cost, +      range_minimum = range_minimum, +      range_maximum = range_maximum +   } + +new_instance : Int -> Int -> String -> Int -> Int -> Instance +new_instance x y icon_id crossing_cost type_id =     {        location = {x = x, y = y},        icon_id = icon_id, -      crossing_cost = crossing_cost +      crossing_cost = crossing_cost, +      type_id = type_id     } -error_tile : Int -> Int -> Type -error_tile x y = +error_tile_instance : Int -> Int -> Instance +error_tile_instance x y =     {        location = {x = x, y = y},        icon_id = "error", -      crossing_cost = 1 +      type_id = -1, +      crossing_cost = Constants.Movement.cost_when_out_of_bounds     } -get_location : Type -> Struct.Location.Type -get_location tile = tile.location -get_icon_id : Type -> String -get_icon_id tile = tile.icon_id -   -- Just to see how it looks with SVG -   -- (toString (rem tile.crossing_cost 4)) +get_id : Type -> Int +get_id tile = tile.id  get_cost : Type -> Int  get_cost tile = tile.crossing_cost -get_variant_id : Type -> Int -get_variant_id tile = -   ((noise_function tile.location.x tile.location.y tile.crossing_cost) % 9) +get_instance_cost : Instance -> Int +get_instance_cost tile_inst = tile_inst.crossing_cost + +get_name : Type -> String +get_name tile = tile.name + +get_range_minimum : Type -> Int +get_range_minimum tile = tile.range_minimum + +get_range_maximum : Type -> Int +get_range_maximum tile = tile.range_maximum + +get_location : Instance -> Struct.Location.Type +get_location tile_inst = tile_inst.location + +get_icon_id : Instance -> String +get_icon_id tile_inst = tile_inst.icon_id + +get_variant_id : Instance -> Int +get_variant_id tile_inst = +   ( +      (noise_function +         tile_inst.location.x +         tile_inst.location.y +         tile_inst.crossing_cost +      ) +      % Constants.UI.variants_per_tile +   ) + +solve_tile_instance : (Dict.Dict Ref Type) -> Instance -> Instance +solve_tile_instance tiles tile_instance = +   case (Dict.get tile_instance.type_id tiles) of +      (Just tile) -> +         {tile_instance | +            type_id = tile.id, +            crossing_cost = tile.crossing_cost +         } + +      Nothing -> +         (error_tile_instance +            tile_instance.location.x +            tile_instance.location.y +         ) + +decoder : (Json.Decode.Decoder Type) +decoder = +   (Json.Decode.map +      (finish_decoding) +      (Json.Decode.Pipeline.decode +         PartiallyDecoded +         |> (Json.Decode.Pipeline.required "id" Json.Decode.int) +         |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) +         |> (Json.Decode.Pipeline.required "ct" Json.Decode.int) +         |> (Json.Decode.Pipeline.required "rmi" Json.Decode.int) +         |> (Json.Decode.Pipeline.required "rma" Json.Decode.int) +      ) +   ) diff --git a/src/battlemap/src/Update/EndTurn.elm b/src/battlemap/src/Update/EndTurn.elm index 4acbc94..457d788 100644 --- a/src/battlemap/src/Update/EndTurn.elm +++ b/src/battlemap/src/Update/EndTurn.elm @@ -1,7 +1,6 @@  module Update.EndTurn exposing (apply_to)  -- Elm ------------------------------------------------------------------------- -import Dict  -- Struct.Battlemap -------------------------------------------------------------------  import Comm.CharacterTurn diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm index 8f5a066..5296f91 100644 --- a/src/battlemap/src/Update/HandleServerReply.elm +++ b/src/battlemap/src/Update/HandleServerReply.elm @@ -15,6 +15,7 @@ import Struct.Error  import Struct.Event  import Struct.Model  import Struct.ServerReply +import Struct.Tile  import Struct.TurnResult  import Struct.UI  import Struct.Weapon @@ -103,7 +104,9 @@ set_map map current_state =        (_, (Just _)) -> current_state        (model, _) ->           ( -            {model | battlemap = map}, +            {model | +               battlemap = (Struct.Battlemap.solve_tiles model.tiles map) +            },              Nothing           ) diff --git a/src/battlemap/src/View/Battlemap.elm b/src/battlemap/src/View/Battlemap.elm index abf0744..c185486 100644 --- a/src/battlemap/src/View/Battlemap.elm +++ b/src/battlemap/src/View/Battlemap.elm @@ -14,7 +14,6 @@ import Constants.UI  import Struct.Battlemap  import Struct.Character -import Struct.CharacterTurn  import Struct.Event  import Struct.Model  import Struct.Navigator diff --git a/src/battlemap/src/View/Battlemap/Tile.elm b/src/battlemap/src/View/Battlemap/Tile.elm index 5ac0701..a049acf 100644 --- a/src/battlemap/src/View/Battlemap/Tile.elm +++ b/src/battlemap/src/View/Battlemap/Tile.elm @@ -21,7 +21,7 @@ import Struct.Tile  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  get_html : ( -      Struct.Tile.Type -> +      Struct.Tile.Instance ->        (Html.Html Struct.Event.Type)     )  get_html tile = diff --git a/src/battlemap/src/View/Controlled.elm b/src/battlemap/src/View/Controlled.elm index 2ad4876..c7c4c49 100644 --- a/src/battlemap/src/View/Controlled.elm +++ b/src/battlemap/src/View/Controlled.elm @@ -8,7 +8,6 @@ import Html.Events  -- Struct.Battlemap -------------------------------------------------------------------  import Struct.CharacterTurn  import Struct.Event -import Struct.Model  import Struct.Navigator  import Util.Html diff --git a/src/battlemap/src/View/Controlled/CharacterCard.elm b/src/battlemap/src/View/Controlled/CharacterCard.elm index 36b8546..7079fc9 100644 --- a/src/battlemap/src/View/Controlled/CharacterCard.elm +++ b/src/battlemap/src/View/Controlled/CharacterCard.elm @@ -15,7 +15,6 @@ import Struct.Armor  import Struct.Character  import Struct.CharacterTurn  import Struct.Event -import Struct.Model  import Struct.Navigator  import Struct.Statistics  import Struct.Weapon diff --git a/src/battlemap/src/View/MainMenu.elm b/src/battlemap/src/View/MainMenu.elm index f92f73a..f301ea6 100644 --- a/src/battlemap/src/View/MainMenu.elm +++ b/src/battlemap/src/View/MainMenu.elm @@ -7,7 +7,6 @@ import Html.Events  -- Battlemap -------------------------------------------------------------------  import Struct.Event -import Struct.Model  import Struct.UI  -------------------------------------------------------------------------------- diff --git a/src/battlemap/src/View/SubMenu/Characters.elm b/src/battlemap/src/View/SubMenu/Characters.elm index 2f24b82..31819e5 100644 --- a/src/battlemap/src/View/SubMenu/Characters.elm +++ b/src/battlemap/src/View/SubMenu/Characters.elm @@ -10,7 +10,6 @@ import Html.Events  -- Battlemap -------------------------------------------------------------------  import Struct.Character  import Struct.Event -import Struct.Model  import View.Controlled.CharacterCard diff --git a/src/battlemap/src/View/SubMenu/Status/TileInfo.elm b/src/battlemap/src/View/SubMenu/Status/TileInfo.elm index 75953f8..a478231 100644 --- a/src/battlemap/src/View/SubMenu/Status/TileInfo.elm +++ b/src/battlemap/src/View/SubMenu/Status/TileInfo.elm @@ -17,7 +17,7 @@ import Struct.Tile  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -get_icon : (Struct.Tile.Type -> (Html.Html Struct.Event.Type)) +get_icon : (Struct.Tile.Instance -> (Html.Html Struct.Event.Type))  get_icon tile =     (Html.div        [ @@ -46,7 +46,7 @@ get_icon tile =        ]     ) -get_name : (Struct.Tile.Type -> (Html.Html Struct.Event.Type)) +get_name : (Struct.Tile.Instance -> (Html.Html Struct.Event.Type))  get_name tile =     (Html.div        [ @@ -55,17 +55,17 @@ get_name tile =        [           (Html.text              ( -               "Tile Type " +               "Tile.Instance "                 ++ (Struct.Tile.get_icon_id tile)              )           )        ]     ) -get_cost : (Struct.Tile.Type -> (Html.Html Struct.Event.Type)) +get_cost : (Struct.Tile.Instance -> (Html.Html Struct.Event.Type))  get_cost tile =     let -      cost = (Struct.Tile.get_cost tile) +      cost = (Struct.Tile.get_instance_cost tile)        text =           if (cost > Constants.Movement.max_points)           then @@ -82,7 +82,7 @@ get_cost tile =           ]        ) -get_location : (Struct.Tile.Type -> (Html.Html Struct.Event.Type)) +get_location : (Struct.Tile.Instance -> (Html.Html Struct.Event.Type))  get_location tile =     let        tile_location = (Struct.Tile.get_location tile) diff --git a/src/battlemap/src/View/SubMenu/Timeline/Attack.elm b/src/battlemap/src/View/SubMenu/Timeline/Attack.elm index 974867e..f41598b 100644 --- a/src/battlemap/src/View/SubMenu/Timeline/Attack.elm +++ b/src/battlemap/src/View/SubMenu/Timeline/Attack.elm @@ -12,7 +12,6 @@ import Struct.Attack  import Struct.Event  import Struct.TurnResult  import Struct.Character -import Struct.Model  import View.Character diff --git a/src/battlemap/src/View/SubMenu/Timeline/Movement.elm b/src/battlemap/src/View/SubMenu/Timeline/Movement.elm index afc4055..36b0410 100644 --- a/src/battlemap/src/View/SubMenu/Timeline/Movement.elm +++ b/src/battlemap/src/View/SubMenu/Timeline/Movement.elm @@ -11,7 +11,6 @@ import Html.Attributes  import Struct.Event  import Struct.TurnResult  import Struct.Character -import Struct.Model  import View.Character diff --git a/src/battlemap/src/View/SubMenu/Timeline/WeaponSwitch.elm b/src/battlemap/src/View/SubMenu/Timeline/WeaponSwitch.elm index 21d07e6..31d1a19 100644 --- a/src/battlemap/src/View/SubMenu/Timeline/WeaponSwitch.elm +++ b/src/battlemap/src/View/SubMenu/Timeline/WeaponSwitch.elm @@ -11,7 +11,6 @@ import Html.Attributes  import Struct.Event  import Struct.TurnResult  import Struct.Character -import Struct.Model  import View.Character | 


