| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-03 18:00:24 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-03 18:00:24 +0200 | 
| commit | aee23306060ba664e32e6c8463fdf5fb911881a7 (patch) | |
| tree | 3e28312f96c07e8f6a369b35dd374af5690b1d93 /src/map-editor | |
| parent | ec01963f1f42e7712ee245e8d1acd49ea95fab0c (diff) | |
Got it to work and look okay. Only for map-editor
Diffstat (limited to 'src/map-editor')
| -rw-r--r-- | src/map-editor/src/Comm/SetMap.elm | 49 | ||||
| -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/Model.elm | 21 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 68 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 193 | ||||
| -rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 9 | ||||
| -rw-r--r-- | src/map-editor/src/Update/PrettifySelectedTiles.elm | 147 | ||||
| -rw-r--r-- | src/map-editor/src/Update/SetToolboxTemplate.elm | 21 | ||||
| -rw-r--r-- | src/map-editor/src/View/Map/Tile.elm | 95 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Status/TileInfo.elm | 19 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Tiles.elm | 39 | ||||
| -rw-r--r-- | src/map-editor/src/View/Toolbox.elm | 20 | ||||
| -rw-r--r-- | src/map-editor/www/style.css | 61 | 
14 files changed, 380 insertions, 368 deletions
| diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm index 452ab92..7a83320 100644 --- a/src/map-editor/src/Comm/SetMap.elm +++ b/src/map-editor/src/Comm/SetMap.elm @@ -23,40 +23,49 @@ type alias MapData =  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +deserialize_tile_borders : ( +      (List Int) -> +      (List Struct.Tile.Border) -> +      (List Struct.Tile.Border) +   ) +deserialize_tile_borders rem_ints current_borders = +   case rem_ints of +      [] -> current_borders +      (a :: (b :: c)) -> +         (deserialize_tile_borders +            c +            ((Struct.Tile.new_border a b) :: current_borders) +         ) + +      _ -> [] +  deserialize_tile_instance : Int -> Int -> (List Int) -> Struct.Tile.Instance  deserialize_tile_instance map_width index t =     case t of -      [type_id] -> +      (a :: (b :: c)) ->           (Struct.Tile.new_instance -            (index % map_width) -            (index // map_width) -            type_id -            type_id -            0 -            Constants.Movement.cost_when_out_of_bounds -            -1 -         ) - -      [type_id, border_id, variant_ix] -> -         (Struct.Tile.new_instance -            (index % map_width) -            (index // map_width) -            type_id -            border_id -            variant_ix +            { +               x = (index % map_width), +               y = (index // map_width) +            } +            a +            b              Constants.Movement.cost_when_out_of_bounds              -1 +            (deserialize_tile_borders c [])           )        _ ->           (Struct.Tile.new_instance -            (index % map_width) -            (index // map_width) -            0 +            { +               x = (index % map_width), +               y = (index // map_width) +            }              0              0              Constants.Movement.cost_when_out_of_bounds              -1 +            []           )  internal_decoder : MapData -> Struct.ServerReply.Type diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm index b69173a..b6c35ba 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 (main, border, variant)) -> -         (Update.SetToolboxTemplate.apply_to new_model main border variant) +      (Struct.Event.TemplateRequested (main, variant)) -> +         (Update.SetToolboxTemplate.apply_to new_model main 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 7ded5ba..93e6bfd 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, Int, Int) +   | TemplateRequested (Int, Int)     | PrettifySelectionRequested  attempted : (Result.Result err val) -> Type diff --git a/src/map-editor/src/Struct/Model.elm b/src/map-editor/src/Struct/Model.elm index b71cec3..e8135f1 100644 --- a/src/map-editor/src/Struct/Model.elm +++ b/src/map-editor/src/Struct/Model.elm @@ -4,6 +4,7 @@ module Struct.Model exposing        new,        invalidate,        add_tile, +      add_tile_pattern,        reset,        clear_error     ) @@ -33,7 +34,8 @@ type alias Type =        toolbox: Struct.Toolbox.Type,        help_request: Struct.HelpRequest.Type,        map: Struct.Map.Type, -      tile_patterns: (List Struct.TilePattern.Type), +      tile_patterns: (Dict.Dict String Int), +      wild_tile_patterns: (List Struct.TilePattern.Type),        tiles: (Dict.Dict Struct.Tile.Ref Struct.Tile.Type),        error: (Maybe Struct.Error.Type),        player_id: String, @@ -59,7 +61,8 @@ new flags =              help_request = Struct.HelpRequest.None,              map = (Struct.Map.empty),              tiles = (Dict.empty), -            tile_patterns = [], +            tile_patterns = (Dict.empty), +            wild_tile_patterns = [],              error = Nothing,              map_id = "",              player_id = @@ -95,6 +98,20 @@ add_tile tl model =           )     } +add_tile_pattern : Struct.TilePattern.Type -> Type -> Type +add_tile_pattern tp model = +   if (Struct.TilePattern.is_wild tp) +   then {model | wild_tile_patterns = (tp :: model.wild_tile_patterns)} +   else +      {model | +         tile_patterns = +            (Dict.insert +               (Struct.TilePattern.get_pattern tp) +               (Struct.TilePattern.get_variant tp) +               model.tile_patterns +            ) +      } +  reset : Type -> Type  reset model =     {model | diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm index 254dd78..1534d26 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -3,16 +3,21 @@ module Struct.Tile exposing        Ref,        Type,        Instance, +      Border,        new,        clone_instance,        new_instance, +      new_border,        error_tile_instance,        get_id,        get_name, +      set_borders, +      get_borders, +      get_border_type_id, +      get_border_variant_ix,        get_cost,        get_instance_cost,        get_location, -      get_icon_id,        get_type_id,        get_family,        get_instance_family, @@ -57,14 +62,20 @@ type alias Type =        depth : Int     } +type alias Border = +   { +      type_id : Int, +      variant_ix : Int +   } +  type alias Instance =     {        location : Struct.Location.Type,        crossing_cost : Int,        family : Int,        type_id : Int, -      border_id : Int, -      variant_ix : Int +      variant_ix : Int, +      borders : (List Border)     }  -------------------------------------------------------------------------------- @@ -114,15 +125,30 @@ new id name crossing_cost family depth =  clone_instance : Struct.Location.Type -> Instance -> Instance  clone_instance loc inst = {inst | location = loc} -new_instance : Int -> Int -> Int -> Int -> Int -> Int -> Int -> Instance -new_instance x y type_id border_id variant_ix crossing_cost family = +new_border : Int -> Int -> Border +new_border type_id variant_ix =     { -      location = {x = x, y = y},        type_id = type_id, -      border_id = border_id, +      variant_ix = variant_ix +   } + +new_instance : ( +      Struct.Location.Type -> +      Int -> +      Int -> +      Int -> +      Int -> +      (List Border) -> +      Instance +   ) +new_instance location type_id variant_ix crossing_cost family borders = +   { +      location = location, +      type_id = type_id,        variant_ix = variant_ix,        crossing_cost = crossing_cost, -      family = family +      family = family, +      borders = borders     }  error_tile_instance : Int -> Int -> Instance @@ -130,10 +156,10 @@ error_tile_instance x y =     {        location = {x = x, y = y},        type_id = 0, -      border_id = 0,        variant_ix = 0,        family = 0, -      crossing_cost = Constants.Movement.cost_when_out_of_bounds +      crossing_cost = Constants.Movement.cost_when_out_of_bounds, +      borders = []     }  get_id : Type -> Int @@ -151,28 +177,30 @@ get_name tile = tile.name  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.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_border_type_id : Border -> Int +get_border_type_id tile_border = tile_border.type_id +  get_family : Type -> Int  get_family tile = tile.family +set_borders : (List Border) -> Instance -> Instance +set_borders borders tile_inst = {tile_inst | borders = borders} + +get_borders : Instance -> (List Border) +get_borders tile_inst = tile_inst.borders +  get_instance_family : Instance -> Int  get_instance_family tile_inst = tile_inst.family  get_variant_ix : Instance -> Int  get_variant_ix tile_inst = tile_inst.variant_ix +get_border_variant_ix : Border -> Int +get_border_variant_ix tile_border = tile_border.variant_ix +  get_local_variant_ix : Instance -> Int  get_local_variant_ix tile_inst =     ( diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index b54dbb1..7c9279e 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -1,10 +1,12 @@  module Struct.TilePattern exposing     ( -      PatternElement(..),        Type,        decoder, -      matches, -      matches_pattern +      get_pattern_for, +      patterns_match, +      get_pattern, +      get_variant, +      is_wild     )  -- Elm ------------------------------------------------------------------------- @@ -14,174 +16,65 @@ import Json.Decode  import Json.Decode.Pipeline  -- Battlemap ------------------------------------------------------------------- -import Constants.UI -import Constants.Movement - -import Struct.Location  import Struct.Tile -import Util.List -  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -type PatternElement = -   Any -   | Major -   | Minor -  type alias Type =     { -      t : (PatternElement, PatternElement), -      tv : Int, -      p : (List PatternElement) +      v : Int, +      w : Bool, +      p : String     }  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -matches_internals : ( -      Struct.Tile.Instance -> -      (List Struct.Tile.Instance) -> -      (List PatternElement) -> -      (Maybe Int) -> -      (Maybe Int) -> -      (Bool, Int) -   ) -matches_internals source neighbors pattern maybe_border_fa maybe_border_mc = -   case ((Util.List.pop neighbors), (Util.List.pop pattern)) of -      (Nothing, Nothing) -> -         ( -            True, -            ( -               case maybe_border_mc of -                  Nothing -> (Struct.Tile.get_type_id source) -                  (Just e) -> e -            ) -         ) - -      ((Just (n, r_n)), (Just (p, r_p))) -> -         if (matches_pattern source n p) -         then -            let -               source_mc = (Struct.Tile.get_type_id source) -               source_fa = (Struct.Tile.get_instance_family source) -               n_mc = (Struct.Tile.get_type_id n) -               n_fa = (Struct.Tile.get_instance_family n) -            in -               if -               ( -                  (maybe_border_fa == (Just source_fa)) -                  || (maybe_border_fa == Nothing) -                  || (maybe_border_fa == (Just n_fa)) -                  || (maybe_border_fa == (Just -1)) -               ) -               then -                  (matches_internals -                     source -                     r_n -                     r_p -                     (Just n_fa) -                     (Just n_mc) -                  ) -               else -                  if ((n_fa == -1) || (n_fa == source_fa)) -                  then -                     (matches_internals -                        source -                        r_n -                        r_p -                        maybe_border_fa -                        maybe_border_mc -                     ) -                  else (False, source_mc) -         else -            (False, (Struct.Tile.get_type_id source)) - -      (_, _) -> (False, (Struct.Tile.get_type_id source)) - -finish_decoding_pattern : String -> PatternElement -finish_decoding_pattern str = -   case str of -      "any" -> Any -      "A" -> Minor -      "B" -> Major -      _ -> Minor - -finish_decoding_target : ( -      (List String) -> -      (PatternElement, PatternElement) -   ) -finish_decoding_target t = -   case t of -      ["A", "B"] -> (Minor, Major) -      ["A", "A"] -> (Minor, Minor) -      ["B", "A"] -> (Major, Minor) -      ["B", "B"] -> (Major, Major) -      _ -> (Minor, Minor) - -pattern_decoder : (Json.Decode.Decoder PatternElement) -pattern_decoder = -   (Json.Decode.map -      (finish_decoding_pattern) -      (Json.Decode.string) -   ) - -target_decoder : ( -      (Json.Decode.Decoder (PatternElement, PatternElement)) -   ) -target_decoder = -   (Json.Decode.map -      (finish_decoding_target) -      (Json.Decode.list (Json.Decode.string)) -   )  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- -matches_pattern : ( -      Struct.Tile.Instance -> -      Struct.Tile.Instance -> -      PatternElement -> -      Bool -   ) -matches_pattern source n p = -   let -      source_fa = (Struct.Tile.get_instance_family source) -      n_fa = (Struct.Tile.get_instance_family n) -   in -   case p of -      Any -> True -      Major -> (source_fa < n_fa) -      Minor -> ((source_fa == n_fa) || (n_fa == -1)) - -matches : ( -      (List Struct.Tile.Instance) -> -      Struct.Tile.Instance -> -      Type -> -      (Bool, Int, Int, Int) -   ) -matches neighbors source tile_pattern = -   case (matches_internals source neighbors tile_pattern.p Nothing Nothing) of -      (False, _) -> (False, 0, 0, 0) -      (True, border_mc) -> +get_pattern_for : Int -> (List Struct.Tile.Instance) -> String +get_pattern_for source_fa neighborhood = +   (List.foldl +      (\t -> \acc ->           let -            source_mc = (Struct.Tile.get_type_id source) +            t_fa = (Struct.Tile.get_instance_family t)           in -            case tile_pattern.t of -               (Minor, Major) -> (True, source_mc, border_mc, tile_pattern.tv) -               (Minor, Minor) -> (True, source_mc, source_mc, tile_pattern.tv) -               (Major, Minor) -> (True, border_mc, source_mc, tile_pattern.tv) -               (_, _) -> (True, border_mc, border_mc, tile_pattern.tv) +            if ((t_fa == -1) || (t_fa == source_fa)) +            then (acc ++ "1") +            else (acc ++ "0") +      ) +      "" +      neighborhood +   ) + +patterns_match : String -> String -> Bool +patterns_match a b = +   case ((String.uncons a), (String.uncons b)) of +      (Nothing, _) -> True +      ((Just (a_h, a_r)), (Just (b_h, b_r))) -> +         if ((b_h == '2') || (a_h == b_h)) +         then (patterns_match a_r b_r) +         else False + +      (_, _) -> False + +get_pattern : Type -> String +get_pattern tp = tp.p + +get_variant : Type -> Int +get_variant tp = tp.v + +is_wild : Type -> Bool +is_wild tp = tp.w  decoder : (Json.Decode.Decoder Type)  decoder =     (Json.Decode.Pipeline.decode        Type -      |> (Json.Decode.Pipeline.required "t" (target_decoder)) -      |> (Json.Decode.Pipeline.required "tv" (Json.Decode.int)) -      |> (Json.Decode.Pipeline.required -            "p" -            (Json.Decode.list (pattern_decoder)) -         ) +      |> (Json.Decode.Pipeline.required "v" (Json.Decode.int)) +      |> (Json.Decode.Pipeline.required "w" (Json.Decode.bool)) +      |> (Json.Decode.Pipeline.required "p" (Json.Decode.string))     ) diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index 24d7b2d..5c8d74b 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -41,7 +41,7 @@ add_tile_pattern tp current_state =        (_, (Just _)) -> current_state        (model, _) ->           ( -            {model | tile_patterns = (tp :: model.tile_patterns)}, +            (Struct.Model.add_tile_pattern tp model),              Nothing           ) @@ -54,7 +54,7 @@ set_map map current_state =     case current_state of        (_, (Just _)) -> current_state        (model, _) -> -         ( {model | map = map}, Nothing) +         ( {model | map = (Struct.Map.solve_tiles model.tiles map)}, Nothing)  refresh_map : (        (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -65,10 +65,7 @@ refresh_map current_state =        (_, (Just _)) -> current_state        (model, _) ->           ( -            {model | -               map = -                  (Struct.Map.solve_tiles model.tiles model.map) -            }, +            {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 5f63e48..dd89ea1 100644 --- a/src/map-editor/src/Update/PrettifySelectedTiles.elm +++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm @@ -3,6 +3,8 @@ module Update.PrettifySelectedTiles exposing (apply_to)  -- Elm -------------------------------------------------------------------------  import Dict +import Set +  -- Battlemap -------------------------------------------------------------------  import Struct.Event  import Struct.Location @@ -17,68 +19,77 @@ import Util.List  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -set_tile_to : ( -      (Dict.Dict Int Struct.Tile.Type) -> +neighborhood_tile_instances : (        Struct.Location.Type -> -      Int -> -      Int -> -      Int ->        Struct.Map.Type -> -      Struct.Map.Type +      (List Struct.Tile.Instance) +   ) +neighborhood_tile_instances loc map = +   (List.map +      (\e -> +         case (Struct.Map.try_getting_tile_at e map) of +            Nothing -> (Struct.Tile.error_tile_instance -1 -1) +            (Just t) -> t +      ) +      (Struct.Location.get_full_neighborhood loc)     ) -set_tile_to tiles loc main_class border_class variant_ix map = -   let -      true_variant_ix = -         if (variant_ix >= 0) -         then variant_ix -         else -            case (Struct.Map.try_getting_tile_at loc map) of -               Nothing -> 0 -               (Just t) -> (Struct.Tile.get_variant_ix t) -   in -      (Struct.Map.set_tile_to -         loc -         (case (Dict.get main_class tiles) of -            Nothing -> -               (Struct.Tile.new_instance -                  loc.x -                  loc.y -                  main_class -                  border_class -                  true_variant_ix -                  -1 -                  -1 -               ) -            (Just t) -> -               (Struct.Tile.new_instance -                  loc.x -                  loc.y -                  main_class -                  border_class -                  true_variant_ix -                  (Struct.Tile.get_cost t) -                  (Struct.Tile.get_family t) -               ) +get_nigh_patterns : Int -> (List Struct.Tile.Instance) -> (List (Int, Int)) +get_nigh_patterns source_fm full_neighborhood = +   (Set.toList +      (List.foldl +         (\e -> \acc -> +            let +               e_fm = (Struct.Tile.get_instance_family e) +            in +               if (e_fm <= source_fm) +               then acc +               else +                  (Set.insert +                     ( +                        (Struct.Tile.get_instance_family e), +                        (Struct.Tile.get_type_id e) +                     ) +                     acc +                  )           ) -         map +         (Set.empty) +         full_neighborhood        ) +   ) -find_matching_pattern : ( -      Struct.Tile.Instance -> +nigh_pattern_to_border : ( +      Struct.Model.Type ->        (List Struct.Tile.Instance) -> -      (List Struct.TilePattern.Type) -> -      (Maybe (Int, Int, Int)) +      (Int, Int) -> +      (Struct.Tile.Border)     ) -find_matching_pattern source full_neighborhood candidates = -   case (Util.List.pop candidates) of -      (Just (c, rc)) -> -         case (Struct.TilePattern.matches full_neighborhood source c) of -            (True, main, border, variant) -> (Just (main, border, variant)) -            (False, _, _, _) -> -               (find_matching_pattern source full_neighborhood rc) +nigh_pattern_to_border model full_neighborhood nigh_pattern = +   let +      (fm, tid) = nigh_pattern +      pattern = (Struct.TilePattern.get_pattern_for fm full_neighborhood) +   in +      case (Dict.get pattern model.tile_patterns) of +         Nothing -> +            case +               (Util.List.get_first +                  (\e -> +                     (Struct.TilePattern.patterns_match +                        pattern +                        (Struct.TilePattern.get_pattern e) +                     ) +                  ) +                  model.wild_tile_patterns +               ) +            of +               Nothing -> (Struct.Tile.new_border 0 0) +               (Just tp) -> +                  (Struct.Tile.new_border +                     tid +                     (Struct.TilePattern.get_variant tp) +                  ) -      Nothing -> Nothing +         (Just v) -> (Struct.Tile.new_border tid v)  apply_to_location : (        Struct.Model.Type -> @@ -91,28 +102,22 @@ apply_to_location model loc map =        Nothing -> map        (Just base) ->           let -            oob_tile = (Struct.Tile.new_instance -1 -1 -1 -1 -1 -1 -1) -            full_neighborhood = -               (List.map -                  (\e -> -                     case (Struct.Map.try_getting_tile_at e map) of -                        Nothing -> oob_tile -                        (Just t) -> t -                  ) -                  (Struct.Location.get_full_neighborhood loc) -               ) +            full_neighborhood = (neighborhood_tile_instances loc map)           in -            case -               (find_matching_pattern +            (Struct.Map.set_tile_to +               loc +               (Struct.Tile.set_borders +                  (List.map +                     (nigh_pattern_to_border model full_neighborhood) +                     (get_nigh_patterns +                        (Struct.Tile.get_instance_family base) +                        full_neighborhood +                     ) +                  )                    base -                  full_neighborhood -                  model.tile_patterns                 ) -            of -               (Just (main, border, variant)) -> -                  (set_tile_to model.tiles loc main border variant map) - -               Nothing -> map +               map +            )  --------------------------------------------------------------------------------  -- EXPORTED -------------------------------------------------------------------- diff --git a/src/map-editor/src/Update/SetToolboxTemplate.elm b/src/map-editor/src/Update/SetToolboxTemplate.elm index e140e26..cb7b783 100644 --- a/src/map-editor/src/Update/SetToolboxTemplate.elm +++ b/src/map-editor/src/Update/SetToolboxTemplate.elm @@ -18,22 +18,23 @@ apply_to : (        Struct.Model.Type ->        Int ->        Int -> -      Int ->        (Struct.Model.Type, (Cmd Struct.Event.Type))     ) -apply_to model main_class border_class variant_ix = +apply_to model main_class variant_ix =     (        {model |           toolbox =              (Struct.Toolbox.set_template -               (Struct.Tile.new_instance -                  0 -                  0 -                  main_class -                  border_class -                  variant_ix -                  -1 -                  -1 +               (Struct.Tile.solve_tile_instance +                  model.tiles +                  (Struct.Tile.new_instance +                     {x = 0, y = 0} +                     main_class +                     variant_ix +                     0 +                     0 +                     [] +                  )                 )                 model.toolbox              ) diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index 798896e..89b6300 100644 --- a/src/map-editor/src/View/Map/Tile.elm +++ b/src/map-editor/src/View/Map/Tile.elm @@ -1,4 +1,4 @@ -module View.Map.Tile exposing (get_html) +module View.Map.Tile exposing (get_html, get_content_html)  -- Elm -------------------------------------------------------------------------  import Html @@ -18,9 +18,90 @@ import Struct.Toolbox  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- +get_layer_html : ( +      Int -> +      Struct.Tile.Border -> +      (Html.Html Struct.Event.Type) +   ) +get_layer_html index border = +   (Html.div +      [ +         (Html.Attributes.class ("map-tile-icon-f-" ++ (toString index))), +         (Html.Attributes.style +            [ +               ( +                  "background-image", +                  ( +                     "url(" +                     ++ Constants.IO.tile_assets_url +                     ++ (toString (Struct.Tile.get_border_type_id border)) +                     ++ "-f-" +                     ++ (toString (Struct.Tile.get_border_variant_ix border)) +                     ++ ".svg)" +                  ) +               ) +            ] +         ) +      ] +      [] +   ) +  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- +get_content_html : Struct.Tile.Instance -> (List (Html.Html Struct.Event.Type)) +get_content_html tile = +   ( +      (Html.div +         [ +            (Html.Attributes.class "map-tile-icon-bg"), +            (Html.Attributes.style +               [ +                  ( +                     "background-image", +                     ( +                        "url(" +                        ++ Constants.IO.tile_assets_url +                        ++ (toString (Struct.Tile.get_type_id tile)) +                        ++ "-bg.svg)" +                     ) +                  ) +               ] +            ) +         ] +         [] +      ) +      :: +      ( +         (Html.div +            [ +               (Html.Attributes.class "map-tile-icon-dt"), +               (Html.Attributes.style +                  [ +                     ( +                        "background-image", +                        ( +                           "url(" +                           ++ Constants.IO.tile_assets_url +                           ++ (toString (Struct.Tile.get_type_id tile)) +                           ++ "-v-" +                           ++ (toString (Struct.Tile.get_variant_ix tile)) +                           ++ ".svg)" +                        ) +                     ) +                  ] +               ) +            ] +            [] +         ) +         :: +         (List.indexedMap +            (get_layer_html) +            (Struct.Tile.get_borders tile) +         ) +      ) +   ) +  get_html : (        Struct.Toolbox.Type ->        Struct.Tile.Instance -> @@ -63,19 +144,9 @@ get_html tb tile =                    (                       "left",                       ((toString (tile_loc.x * Constants.UI.tile_size)) ++ "px") -                  ), -                  ( -                     "background-image", -                     ( -                        "url(" -                        ++ Constants.IO.tile_assets_url -                        ++ (Struct.Tile.get_icon_id tile) -                        ++".svg)" -                     )                    )                 ]              )           ] -         [ -         ] +         (get_content_html tile)        ) diff --git a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm index 1e5acac..194f858 100644 --- a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm +++ b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm @@ -17,6 +17,9 @@ import Struct.Model  import Struct.Tile  import Util.Html + +import View.Map.Tile +  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -30,23 +33,9 @@ get_icon tile =                 "map-tile-variant-"                 ++ (toString (Struct.Tile.get_local_variant_ix tile))              ) -         ), -         (Html.Attributes.style -            [ -               ( -                  "background-image", -                  ( -                     "url(" -                     ++ Constants.IO.tile_assets_url -                     ++ (Struct.Tile.get_icon_id tile) -                     ++".svg)" -                  ) -               ) -            ]           )        ] -      [ -      ] +      (View.Map.Tile.get_content_html tile)     )  get_name : ( diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm b/src/map-editor/src/View/SubMenu/Tiles.elm index 64cd633..67a1f50 100644 --- a/src/map-editor/src/View/SubMenu/Tiles.elm +++ b/src/map-editor/src/View/SubMenu/Tiles.elm @@ -9,6 +9,9 @@ import Html.Events  import Constants.IO  import Struct.Event +import Struct.Tile + +import View.Map.Tile  --------------------------------------------------------------------------------  -- LOCAL ----------------------------------------------------------------------- @@ -22,32 +25,20 @@ get_icon_html icon_id =           (Html.Attributes.class "map-tiled"),           (Html.Attributes.class "clickable"),           (Html.Attributes.class "map-tile-variant-0"), -         (Html.Attributes.style -            [ -               ( -                  "background-image", -                  ( -                     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, icon_id, 0)) +            (Struct.Event.TemplateRequested (icon_id, 0))           )        ] -      [ -      ] +      (View.Map.Tile.get_content_html +         (Struct.Tile.new_instance +            {x = 0, y = 0} +            icon_id +            0 +            0 +            0 +            [] +         ) +      )     )  -------------------------------------------------------------------------------- @@ -62,6 +53,6 @@ get_html =        ]        (List.map           (get_icon_html) -         (List.range 0 3) +         (List.range 0 5)        )     ) diff --git a/src/map-editor/src/View/Toolbox.elm b/src/map-editor/src/View/Toolbox.elm index 4054c4d..17ca0fd 100644 --- a/src/map-editor/src/View/Toolbox.elm +++ b/src/map-editor/src/View/Toolbox.elm @@ -14,6 +14,8 @@ import Struct.Toolbox  import Util.Html +import View.Map.Tile +  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -24,23 +26,9 @@ get_template_icon_html template =           (Html.Attributes.class "map-toolbox-template"),           (Html.Attributes.class "map-tiled"),           (Html.Attributes.class "map-tile"), -         (Html.Attributes.class "map-tile-variant-0"), -         (Html.Attributes.style -            [ -               ( -                  "background-image", -                  ( -                     "url(" -                     ++ Constants.IO.tile_assets_url -                     ++ (Struct.Tile.get_icon_id template) -                     ++".svg)" -                  ) -               ) -            ] -         ) -      ] -      [ +         (Html.Attributes.class "map-tile-variant-0")        ] +      (View.Map.Tile.get_content_html template)     )  get_mode_button : ( diff --git a/src/map-editor/www/style.css b/src/map-editor/www/style.css index b286a10..8e758fe 100644 --- a/src/map-editor/www/style.css +++ b/src/map-editor/www/style.css @@ -334,7 +334,8 @@     background-color: #917C6F;  } -.map-tiled +.map-tiled, +.map-tiled *  {     height: 32px;     width: 32px; @@ -343,29 +344,51 @@     /* max-width: 32px; */  } -.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: 300% 0;} +.map-tile-variant-0, .map-tile-variant-0 *  {background-position: 0    0;} +.map-tile-variant-1, .map-tile-variant-1 *  {background-position: 100% 0;} +.map-tile-variant-2, .map-tile-variant-2 *  {background-position: 200% 0;} +.map-tile-variant-3, .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-4, .map-tile-variant-4 *  {background-position: 0    100%;} +.map-tile-variant-5, .map-tile-variant-5 *  {background-position: 100% 100%;} +.map-tile-variant-6, .map-tile-variant-6 *  {background-position: 200% 100%;} +.map-tile-variant-7, .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-8, .map-tile-variant-8 *  {background-position: 0    200%;} +.map-tile-variant-9, .map-tile-variant-9 *  {background-position: 100% 200%;} +.map-tile-variant-10, .map-tile-variant-10 * {background-position: 200% 200%;} +.map-tile-variant-11, .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-variant-12, .map-tile-variant-12 * {background-position: 0    300%;} +.map-tile-variant-13, .map-tile-variant-13 * {background-position: 100% 300%;} +.map-tile-variant-14, .map-tile-variant-14 * {background-position: 200% 300%;} +.map-tile-variant-15, .map-tile-variant-15 * {background-position: 300% 300%;} -.map-tile-icon       {z-index: 0; position: absolute; background-size: 400%;} +.map-tile-icon, .map-tile-icon * { +   z-index: 0; +   position: absolute; +   background-size: 400%; +} + +.map-tile-icon-bg { +   z-index: 0; +} + +.map-tile-icon-f-0 { z-index: 1; } +.map-tile-icon-f-1 { z-index: 2; } +.map-tile-icon-f-2 { z-index: 3; } +.map-tile-icon-f-3 { z-index: 4; } +.map-tile-icon-f-4 { z-index: 5; } +.map-tile-icon-f-5 { z-index: 6; } +.map-tile-icon-f-6 { z-index: 7; } +.map-tile-icon-f-7 { z-index: 8; } + +.map-tile-icon-dt { +   z-index: 9; +} -.map-tile {background-size: 400%;} +.map-tile, .map-tile * {background-size: 400%;} +.map-tile * {position: absolute;}  .map-tabmenu-tiles-tab  { | 


