| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-02 16:42:17 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-02 16:42:17 +0200 | 
| commit | 0ea2e3879cda3166851f58ca0a342d5bfb5e5742 (patch) | |
| tree | afaaa36ac91406f0efc3a4919fa98880d5141129 /src/battle | |
| parent | b43d3bdca8e53517ee4f1027f410c0f6478f54f0 (diff) | |
Moves to the new tile format.
Diffstat (limited to 'src/battle')
| -rw-r--r-- | src/battle/src/Comm/SetMap.elm | 39 | ||||
| -rw-r--r-- | src/battle/src/Constants/UI.elm | 4 | ||||
| -rw-r--r-- | src/battle/src/Struct/Map.elm | 4 | ||||
| -rw-r--r-- | src/battle/src/Struct/Tile.elm | 121 | ||||
| -rw-r--r-- | src/battle/src/Update/HandleServerReply.elm | 2 | ||||
| -rw-r--r-- | src/battle/src/View/Map/Tile.elm | 2 | ||||
| -rw-r--r-- | src/battle/src/View/SubMenu/Status/TileInfo.elm | 2 | ||||
| -rw-r--r-- | src/battle/www/style.css | 2 | 
8 files changed, 79 insertions, 97 deletions
| diff --git a/src/battle/src/Comm/SetMap.elm b/src/battle/src/Comm/SetMap.elm index 7bfd56f..8c58ab3 100644 --- a/src/battle/src/Comm/SetMap.elm +++ b/src/battle/src/Comm/SetMap.elm @@ -3,7 +3,9 @@ module Comm.SetMap exposing (decode)  -- Elm -------------------------------------------------------------------------  import Json.Decode --- Map ------------------------------------------------------------------- +-- Map ------------------------------------------------------------------------- +import Constants.Movement +  import Struct.Map  import Struct.ServerReply  import Struct.Tile @@ -15,21 +17,34 @@ type alias MapData =     {        w : Int,        h : Int, -      t : (List Int) +      t : (List (List Int))     }  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -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) -      id -      -1 -      -1 -   ) +deserialize_tile_instance : Int -> Int -> (List Int) -> Struct.Tile.Instance +deserialize_tile_instance map_width index t = +   case t of +      [type_id, border_id, variant_ix] -> +         (Struct.Tile.new_instance +            (index % map_width) +            (index // map_width) +            type_id +            border_id +            variant_ix +            Constants.Movement.cost_when_out_of_bounds +         ) + +      _ -> +         (Struct.Tile.new_instance +            (index % map_width) +            (index // map_width) +            0 +            0 +            0 +            Constants.Movement.cost_when_out_of_bounds +         )  internal_decoder : MapData -> Struct.ServerReply.Type  internal_decoder map_data = @@ -56,7 +71,7 @@ decode =           (Json.Decode.field "h" Json.Decode.int)           (Json.Decode.field              "t" -            (Json.Decode.list Json.Decode.int) +            (Json.Decode.list (Json.Decode.list Json.Decode.int))           )        )     ) diff --git a/src/battle/src/Constants/UI.elm b/src/battle/src/Constants/UI.elm index 642d94c..6a0b948 100644 --- a/src/battle/src/Constants/UI.elm +++ b/src/battle/src/Constants/UI.elm @@ -3,8 +3,8 @@ module Constants.UI exposing (..)  tile_size : Int  tile_size = 32 -variants_per_tile : Int -variants_per_tile = 16 +local_variants_per_tile : Int +local_variants_per_tile = 16  viewer_html_id : String  viewer_html_id = "map_viewer" diff --git a/src/battle/src/Struct/Map.elm b/src/battle/src/Struct/Map.elm index 9944b72..a2ddeb3 100644 --- a/src/battle/src/Struct/Map.elm +++ b/src/battle/src/Struct/Map.elm @@ -14,6 +14,8 @@ module Struct.Map exposing  -- Elm -------------------------------------------------------------------------  import Array +import Dict +  -- Map -------------------------------------------------------------------  import Struct.Character  import Struct.Tile @@ -116,7 +118,7 @@ get_movement_cost_function bmap start_loc char_list loc =     else        Constants.Movement.cost_when_out_of_bounds -solve_tiles : (List Struct.Tile.Type) -> Type -> Type +solve_tiles : (Dict.Dict Int 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/battle/src/Struct/Tile.elm b/src/battle/src/Struct/Tile.elm index 550169b..0077e7f 100644 --- a/src/battle/src/Struct/Tile.elm +++ b/src/battle/src/Struct/Tile.elm @@ -8,20 +8,18 @@ module Struct.Tile exposing        error_tile_instance,        get_id,        get_name, -      get_range_minimum, -      get_range_maximum,        get_cost,        get_instance_cost,        get_location,        get_icon_id,        get_type_id, -      get_variant_id, +      get_local_variant_ix,        solve_tile_instance,        decoder     )  -- Elm ------------------------------------------------------------------------- -import List +import Dict  import Json.Decode  import Json.Decode.Pipeline @@ -41,26 +39,23 @@ type alias PartiallyDecoded =     {        id : Int,        nam : String, -      ct : Int, -      rmi : Int, -      rma : Int +      ct : Int     }  type alias Type =     {        id : Int,        name : String, -      crossing_cost : Int, -      range_minimum : Int, -      range_maximum : Int +      crossing_cost : Int     }  type alias Instance =     {        location : Struct.Location.Type, -      icon_id : Int, -      crossing_cost : Int, -      type_id : Int +      type_id : Int, +      border_id : Int, +      variant_ix : Int, +      crossing_cost : Int     }  -------------------------------------------------------------------------------- @@ -75,62 +70,40 @@ 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 +      crossing_cost = add_tile.ct     } -seek_tile_instance_type : Instance -> Type -> (Maybe Type) -> (Maybe Type) -seek_tile_instance_type instance candidate current_sol = -   if (current_sol == Nothing) -   then -      let -         icon_id = instance.icon_id -      in -         if -         ( -            (icon_id >= candidate.range_minimum) -            && (icon_id <= candidate.range_maximum) -         ) -         then -            (Just candidate) -         else -            current_sol -   else -      current_sol -  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- -new : Int -> String -> Int -> Int -> Int -> Type -new id name crossing_cost range_minimum range_maximum = +new : Int -> String -> Int -> Type +new id name crossing_cost =     {        id = id,        name = name, -      crossing_cost = crossing_cost, -      range_minimum = range_minimum, -      range_maximum = range_maximum +      crossing_cost = crossing_cost     } -new_instance : Int -> Int -> Int -> Int -> Int -> Instance -new_instance x y icon_id crossing_cost type_id = +new_instance : Int -> Int -> Int -> Int -> Int -> Int -> Instance +new_instance x y type_id border_id variant_ix crossing_cost =     {        location = {x = x, y = y}, -      icon_id = icon_id, -      crossing_cost = crossing_cost, -      type_id = type_id +      type_id = type_id, +      border_id = border_id, +      variant_ix = variant_ix, +      crossing_cost = crossing_cost     }  error_tile_instance : Int -> Int -> Instance  error_tile_instance x y =     {        location = {x = x, y = y}, -      icon_id = -1, -      type_id = -1, +      type_id = 0, +      border_id = 0, +      variant_ix = 0,        crossing_cost = Constants.Movement.cost_when_out_of_bounds     } -  get_id : Type -> Int  get_id tile = tile.id @@ -143,50 +116,44 @@ 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 = (toString tile_inst.icon_id) +get_icon_id tile_inst = +   ( +      (toString tile_inst.type_id) +      ++ "-" +      ++ (toString tile_inst.border_id) +      ++ "-" +      ++ (toString tile_inst.variant_ix) +   ) -get_type_id: Instance -> Int +get_type_id : Instance -> Int  get_type_id tile_inst = tile_inst.type_id -get_variant_id : Instance -> Int -get_variant_id tile_inst = +get_local_variant_ix : Instance -> Int +get_local_variant_ix tile_inst =     (        (noise_function           tile_inst.location.x           tile_inst.location.y           tile_inst.crossing_cost        ) -      % Constants.UI.variants_per_tile +      % Constants.UI.local_variants_per_tile     ) -solve_tile_instance : (List Type) -> Instance -> Instance +solve_tile_instance : (Dict.Dict Int Type) -> Instance -> Instance  solve_tile_instance tiles tile_instance = -   let -      maybe_type = -         (List.foldr (seek_tile_instance_type tile_instance) Nothing tiles) -   in -      case maybe_type 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 -            ) +   case (Dict.get tile_instance.type_id tiles) of +      (Just tile) -> +         {tile_instance | crossing_cost = tile.crossing_cost} + +      Nothing -> +         (error_tile_instance +            tile_instance.location.x +            tile_instance.location.y +         )  decoder : (Json.Decode.Decoder Type)  decoder = @@ -197,7 +164,5 @@ decoder =           |> (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/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm index 2352f67..ff6cc67 100644 --- a/src/battle/src/Update/HandleServerReply.elm +++ b/src/battle/src/Update/HandleServerReply.elm @@ -111,7 +111,7 @@ set_map map current_state =           (              {model |                 map = -                  (Struct.Map.solve_tiles (Dict.values model.tiles) map) +                  (Struct.Map.solve_tiles model.tiles map)              },              Nothing           ) diff --git a/src/battle/src/View/Map/Tile.elm b/src/battle/src/View/Map/Tile.elm index 600e26d..844a277 100644 --- a/src/battle/src/View/Map/Tile.elm +++ b/src/battle/src/View/Map/Tile.elm @@ -35,7 +35,7 @@ get_html tile =              (Html.Attributes.class                 (                    "battle-tile-variant-" -                  ++ (toString (Struct.Tile.get_variant_id tile)) +                  ++ (toString (Struct.Tile.get_local_variant_ix tile))                 )              ),              (Html.Attributes.class "clickable"), diff --git a/src/battle/src/View/SubMenu/Status/TileInfo.elm b/src/battle/src/View/SubMenu/Status/TileInfo.elm index 7448247..2cd0a6f 100644 --- a/src/battle/src/View/SubMenu/Status/TileInfo.elm +++ b/src/battle/src/View/SubMenu/Status/TileInfo.elm @@ -28,7 +28,7 @@ get_icon tile =           (Html.Attributes.class              (                 "battle-tile-variant-" -               ++ (toString (Struct.Tile.get_variant_id tile)) +               ++ (toString (Struct.Tile.get_local_variant_ix tile))              )           ),           (Html.Attributes.style diff --git a/src/battle/www/style.css b/src/battle/www/style.css index 1e537b3..2a2147a 100644 --- a/src/battle/www/style.css +++ b/src/battle/www/style.css @@ -606,7 +606,7 @@  .battle-tile-variant-14 {background-position: 200% 300%;}  .battle-tile-variant-15 {background-position: 300% 300%;} -.battle-tile-icon       {z-index: 0; position: absolute; background-size: 300%;} +.battle-tile-icon       {z-index: 0; position: absolute; background-size: 400%;}  .battle-path-icon-below-markers {z-index: 1;}  .battle-marker-icon     {z-index: 2;}  .battle-path-icon-above-markers {z-index: 3;} | 


