| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/map-editor')
| -rw-r--r-- | src/map-editor/src/Comm/SetMap.elm | 47 | ||||
| -rw-r--r-- | src/map-editor/src/Constants/UI.elm | 4 | ||||
| -rw-r--r-- | src/map-editor/src/ElmModule/Update.elm | 4 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Event.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Map.elm | 4 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 122 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 20 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Toolbox.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 16 | ||||
| -rw-r--r-- | src/map-editor/src/Update/PrettifySelectedTiles.elm | 49 | ||||
| -rw-r--r-- | src/map-editor/src/Update/SetToolboxTemplate.elm | 15 | ||||
| -rw-r--r-- | src/map-editor/src/View/Map/Tile.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Status/TileInfo.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Tiles.elm (renamed from src/map-editor/src/View/SubMenu/Tiles.elm.m4) | 23 | ||||
| -rw-r--r-- | src/map-editor/www/style.css | 26 | 
15 files changed, 185 insertions, 153 deletions
| diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm index 754c82b..e74471d 100644 --- a/src/map-editor/src/Comm/SetMap.elm +++ b/src/map-editor/src/Comm/SetMap.elm @@ -4,6 +4,8 @@ module Comm.SetMap exposing (decode)  import Json.Decode  -- Map ------------------------------------------------------------------------- +import Constants.Movement +  import Struct.Map  import Struct.ServerReply  import Struct.Tile @@ -15,21 +17,44 @@ 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] -> +         (Struct.Tile.new_instance +            (index % map_width) +            (index // map_width) +            type_id +            type_id +            0 +            Constants.Movement.cost_when_out_of_bounds +         ) + +      [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 +81,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/map-editor/src/Constants/UI.elm b/src/map-editor/src/Constants/UI.elm index 642d94c..6a0b948 100644 --- a/src/map-editor/src/Constants/UI.elm +++ b/src/map-editor/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/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm index 8ae27f4..b69173a 100644 --- a/src/map-editor/src/ElmModule/Update.elm +++ b/src/map-editor/src/ElmModule/Update.elm @@ -63,8 +63,8 @@ update event model =        (Struct.Event.ModeRequested mode) ->           (Update.SetToolboxMode.apply_to new_model mode) -      (Struct.Event.TemplateRequested id) -> -         (Update.SetToolboxTemplate.apply_to new_model id) +      (Struct.Event.TemplateRequested (main, border, variant)) -> +         (Update.SetToolboxTemplate.apply_to new_model main border variant)        Struct.Event.ClearSelectionRequested ->           (Update.ClearToolboxSelection.apply_to new_model) diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index b8fac70..7ded5ba 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -26,7 +26,7 @@ type Type =     | ModeRequested Struct.Toolbox.Mode     | ShapeRequested Struct.Toolbox.Shape     | ClearSelectionRequested -   | TemplateRequested Int +   | TemplateRequested (Int, Int, Int)     | PrettifySelectionRequested  attempted : (Result.Result err val) -> Type diff --git a/src/map-editor/src/Struct/Map.elm b/src/map-editor/src/Struct/Map.elm index b2f3087..ca16a4c 100644 --- a/src/map-editor/src/Struct/Map.elm +++ b/src/map-editor/src/Struct/Map.elm @@ -14,6 +14,8 @@ module Struct.Map exposing  -- Elm -------------------------------------------------------------------------  import Array +import Dict +  -- Map -------------------------------------------------------------------  import Struct.Tile  import Struct.Location @@ -88,7 +90,7 @@ try_getting_tile_at loc map =     then (Array.get (location_to_index loc map) map.content)     else Nothing -solve_tiles : (List Struct.Tile.Type) -> Type -> Type +solve_tiles : (Dict.Dict Int Struct.Tile.Type) -> Type -> Type  solve_tiles tiles map =     {map |        content = (Array.map (Struct.Tile.solve_tile_instance tiles) map.content) diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm index 9ad944e..7583d51 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -9,20 +9,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_variant_ix,        solve_tile_instance,        decoder     )  -- Elm ------------------------------------------------------------------------- -import List +import Dict  import Json.Decode  import Json.Decode.Pipeline @@ -42,26 +40,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     }  -------------------------------------------------------------------------------- @@ -90,65 +85,43 @@ 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     }  clone_instance : Struct.Location.Type -> Instance -> Instance  clone_instance loc inst = {inst | location = loc} -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 -> Int -> Instance -error_tile_instance icon_id x y = +error_tile_instance : Int -> Int -> Instance +error_tile_instance x y =     {        location = {x = x, y = y}, -      icon_id = icon_id, -      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 @@ -161,51 +134,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 tile_inst = tile_inst.type_id -get_variant_id : Instance -> Int -get_variant_id tile_inst = +get_variant_ix : Instance -> Int +get_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.icon_id -               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 = @@ -216,7 +182,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/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index ea3a6d1..47747a0 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -34,7 +34,7 @@ type PatternElement =  type alias Type =     {        s : PatternElement, -      t : Int, +      t : (Int, Int, Int),        p : (List PatternElement)     } @@ -64,6 +64,13 @@ finish_decoding_pattern ppe =        "n" -> (Not ppe.i)        _ -> (Exactly ppe.i) +finish_decoding_target : (List Int) -> (Int, Int, Int) +finish_decoding_target t = +   case t of +      [m] -> (m, m, 0) +      [m, b, v] -> (m, b, v) +      _ -> (0, 0, 0) +  pattern_decoder : (Json.Decode.Decoder PatternElement)  pattern_decoder =     (Json.Decode.map @@ -75,6 +82,13 @@ pattern_decoder =        )     ) +target_decoder : (Json.Decode.Decoder (Int, Int, Int)) +target_decoder = +   (Json.Decode.map +      (finish_decoding_target) +      (Json.Decode.list (Json.Decode.int)) +   ) +  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -97,14 +111,14 @@ decoder =     (Json.Decode.Pipeline.decode        Type        |> (Json.Decode.Pipeline.required "s" (pattern_decoder)) -      |> (Json.Decode.Pipeline.required "t" Json.Decode.int) +      |> (Json.Decode.Pipeline.required "t" (target_decoder))        |> (Json.Decode.Pipeline.required              "p"              (Json.Decode.list (pattern_decoder))           )     ) -get_target : Type -> Int +get_target : Type -> (Int, Int, Int)  get_target tile_pattern = tile_pattern.t  get_source_pattern : Type -> PatternElement diff --git a/src/map-editor/src/Struct/Toolbox.elm b/src/map-editor/src/Struct/Toolbox.elm index b038d27..2363225 100644 --- a/src/map-editor/src/Struct/Toolbox.elm +++ b/src/map-editor/src/Struct/Toolbox.elm @@ -185,7 +185,7 @@ get_square_tiles corner map new_loc =  default : Type  default =     { -      template = (Struct.Tile.error_tile_instance 0 0 0), +      template = (Struct.Tile.error_tile_instance 0 0),        mode = Draw,        shape = Simple,        selection = [], diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index e4a178b..2f07ca9 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -1,16 +1,10 @@  module Update.HandleServerReply exposing (apply_to)  -- Elm ------------------------------------------------------------------------- -import Array - -import Delay -  import Dict  import Http -import Time -  -- Map -------------------------------------------------------------------  import Struct.Map  import Struct.Error @@ -19,7 +13,6 @@ import Struct.Model  import Struct.ServerReply  import Struct.Tile  import Struct.TilePattern -import Struct.UI  --------------------------------------------------------------------------------  -- TYPES ----------------------------------------------------------------------- @@ -57,12 +50,7 @@ set_map map current_state =     case current_state of        (_, (Just _)) -> current_state        (model, _) -> -         ( -            {model | -               map = (Struct.Map.solve_tiles (Dict.values model.tiles) map) -            }, -            Nothing -         ) +         ( {model | map = map}, Nothing)  refresh_map : (        (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -75,7 +63,7 @@ refresh_map current_state =           (              {model |                 map = -                  (Struct.Map.solve_tiles (Dict.values model.tiles) model.map) +                  (Struct.Map.solve_tiles model.tiles model.map)              },              Nothing           ) diff --git a/src/map-editor/src/Update/PrettifySelectedTiles.elm b/src/map-editor/src/Update/PrettifySelectedTiles.elm index caee831..fe2c343 100644 --- a/src/map-editor/src/Update/PrettifySelectedTiles.elm +++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm @@ -18,18 +18,23 @@ import Util.List  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  set_tile_to : ( -      Struct.Model.Type ->        Struct.Location.Type ->        Int -> +      Int -> +      Int ->        Struct.Map.Type ->        Struct.Map.Type     ) -set_tile_to model loc id map = +set_tile_to loc main_class border_class variant_ix map =     (Struct.Map.set_tile_to        loc -      (Struct.Tile.solve_tile_instance -         (Dict.values model.tiles) -         (Struct.Tile.error_tile_instance id loc.x loc.y) +      (Struct.Tile.new_instance +         0 +         0 +         main_class +         border_class +         variant_ix +         -1        )        map     ) @@ -67,12 +72,17 @@ apply_to_location wild_patterns model loc map =                 )              of                 (Just pattern) -> -- TODO -                  (set_tile_to -                     model -                     loc -                     (Struct.TilePattern.get_target pattern) -                     map -                  ) +                  let +                     (main, border, variant) = +                        (Struct.TilePattern.get_target pattern) +                  in +                     (set_tile_to +                        loc +                        main +                        border +                        variant +                        map +                     )                 Nothing ->                    case @@ -85,12 +95,17 @@ apply_to_location wild_patterns model loc map =                       )                    of                       (Just pattern) -> -- TODO -                        (set_tile_to -                           model -                           loc -                           (Struct.TilePattern.get_target pattern) -                           map -                        ) +                        let +                           (main, border, variant) = +                              (Struct.TilePattern.get_target pattern) +                        in +                           (set_tile_to +                              loc +                              main +                              border +                              variant +                              map +                           )                       Nothing -> map diff --git a/src/map-editor/src/Update/SetToolboxTemplate.elm b/src/map-editor/src/Update/SetToolboxTemplate.elm index 319bd53..eefc622 100644 --- a/src/map-editor/src/Update/SetToolboxTemplate.elm +++ b/src/map-editor/src/Update/SetToolboxTemplate.elm @@ -1,6 +1,5 @@  module Update.SetToolboxTemplate exposing (apply_to)  -- Elm ------------------------------------------------------------------------- -import Dict  -- Battlemap -------------------------------------------------------------------  import Struct.Event @@ -18,16 +17,22 @@ import Struct.Model  apply_to : (        Struct.Model.Type ->        Int -> +      Int -> +      Int ->        (Struct.Model.Type, (Cmd Struct.Event.Type))     ) -apply_to model id = +apply_to model main_class border_class variant_ix =     (        {model |           toolbox =              (Struct.Toolbox.set_template -               (Struct.Tile.solve_tile_instance -                  (Dict.values model.tiles) -                  (Struct.Tile.error_tile_instance id 0 0) +               (Struct.Tile.new_instance +                  0 +                  0 +                  main_class +                  border_class +                  variant_ix +                  -1                 )                 model.toolbox              ) diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index 3431663..077889e 100644 --- a/src/map-editor/src/View/Map/Tile.elm +++ b/src/map-editor/src/View/Map/Tile.elm @@ -47,7 +47,7 @@ get_html tb tile =              (Html.Attributes.class                 (                    "map-tile-variant-" -                  ++ (toString (Struct.Tile.get_variant_id tile)) +                  ++ (toString (Struct.Tile.get_variant_ix tile))                 )              ),              (Html.Attributes.class "clickable"), diff --git a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm index 0ac727e..eeb51a8 100644 --- a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm +++ b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm @@ -28,7 +28,7 @@ get_icon tile =           (Html.Attributes.class              (                 "map-tile-variant-" -               ++ (toString (Struct.Tile.get_variant_id tile)) +               ++ (toString (Struct.Tile.get_variant_ix tile))              )           ),           (Html.Attributes.style diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm.m4 b/src/map-editor/src/View/SubMenu/Tiles.elm index bbfafd7..64cd633 100644 --- a/src/map-editor/src/View/SubMenu/Tiles.elm.m4 +++ b/src/map-editor/src/View/SubMenu/Tiles.elm @@ -13,6 +13,7 @@ import Struct.Event  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +-- TODO: display and allow selection of all variations.  get_icon_html : Int -> (Html.Html Struct.Event.Type)  get_icon_html icon_id =     (Html.div @@ -26,21 +27,29 @@ get_icon_html icon_id =                 (                    "background-image",                    ( -                     "url(" -                     ++ Constants.IO.tile_assets_url -                     ++ (toString icon_id) -                     ++".svg)" +                     let +                        icon_id_str = (toString icon_id) +                     in +                        ( +                           "url(" +                           ++ Constants.IO.tile_assets_url +                           ++ icon_id_str +                           ++ "-" +                           ++ icon_id_str +                           ++"-0.svg)" +                        )                    )                 )              ]           ), -         (Html.Events.onClick (Struct.Event.TemplateRequested icon_id)) +         (Html.Events.onClick +            (Struct.Event.TemplateRequested (icon_id, icon_id, 0)) +         )        ]        [        ]     ) -m4_include(__MAKEFILE_DATA_DIR/tile/global.m4.conf)m4_dnl  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -53,6 +62,6 @@ get_html =        ]        (List.map           (get_icon_html) -         (List.range 0 __TILE_CLASS_MAX_ID) +         (List.range 0 3)        )     ) diff --git a/src/map-editor/www/style.css b/src/map-editor/www/style.css index ea9b8ea..2d4d958 100644 --- a/src/map-editor/www/style.css +++ b/src/map-editor/www/style.css @@ -346,14 +346,24 @@  .map-tile-variant-0  {background-position: 0    0;}  .map-tile-variant-1  {background-position: 100% 0;}  .map-tile-variant-2  {background-position: 200% 0;} -.map-tile-variant-3  {background-position: 0    100%;} -.map-tile-variant-4  {background-position: 100% 100%;} -.map-tile-variant-5  {background-position: 200% 100%;} -.map-tile-variant-6  {background-position: 0    200%;} -.map-tile-variant-7  {background-position: 100% 200%;} -.map-tile-variant-8  {background-position: 200% 200%;} - -.map-tile-icon       {z-index: 0; position: absolute; background-size: 300%;} +.map-tile-variant-3  {background-position: 300% 0;} + +.map-tile-variant-4  {background-position: 0    100%;} +.map-tile-variant-5  {background-position: 100% 100%;} +.map-tile-variant-6  {background-position: 200% 100%;} +.map-tile-variant-7  {background-position: 300% 100%;} + +.map-tile-variant-8  {background-position: 0    200%;} +.map-tile-variant-9  {background-position: 100% 200%;} +.map-tile-variant-10 {background-position: 200% 200%;} +.map-tile-variant-11 {background-position: 300% 200%;} + +.map-tile-variant-12 {background-position: 0    300%;} +.map-tile-variant-13 {background-position: 100% 300%;} +.map-tile-variant-14 {background-position: 200% 300%;} +.map-tile-variant-15 {background-position: 300% 300%;} + +.map-tile-icon       {z-index: 0; position: absolute; background-size: 400%;}  .map-tile {background-size: 300%;} | 


