summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/map-editor')
-rw-r--r-- | src/map-editor/src/Comm/SendMapUpdate.elm | 8 | ||||
-rw-r--r-- | src/map-editor/src/Comm/SetMap.elm | 21 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Event.elm | 3 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Map.elm | 2 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Model.elm | 8 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 78 | ||||
-rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 23 | ||||
-rw-r--r-- | src/map-editor/src/Update/PrettifySelectedTiles.elm | 12 | ||||
-rw-r--r-- | src/map-editor/src/Update/SetToolboxTemplate.elm | 12 | ||||
-rw-r--r-- | src/map-editor/src/View/Map/Tile.elm | 10 | ||||
-rw-r--r-- | src/map-editor/src/View/SubMenu/Tiles.elm | 42 |
11 files changed, 120 insertions, 99 deletions
diff --git a/src/map-editor/src/Comm/SendMapUpdate.elm b/src/map-editor/src/Comm/SendMapUpdate.elm index d47cee2..0a2b7da 100644 --- a/src/map-editor/src/Comm/SendMapUpdate.elm +++ b/src/map-editor/src/Comm/SendMapUpdate.elm @@ -25,8 +25,8 @@ import Struct.Tile encode_tile_border_values : Struct.Tile.Border -> (List Json.Encode.Value) encode_tile_border_values border = [ - (Json.Encode.int (Struct.Tile.get_border_type_id border)), - (Json.Encode.int (Struct.Tile.get_border_variant_ix border)) + (Json.Encode.string (Struct.Tile.get_border_type_id border)), + (Json.Encode.string (Struct.Tile.get_border_variant_id border)) ] encode_tile_instance : Struct.Tile.Instance -> Json.Encode.Value @@ -34,8 +34,8 @@ encode_tile_instance tile_inst = (Json.Encode.list ( [ - (Json.Encode.int (Struct.Tile.get_type_id tile_inst)), - (Json.Encode.int (Struct.Tile.get_variant_ix tile_inst)) + (Json.Encode.string (Struct.Tile.get_type_id tile_inst)), + (Json.Encode.string (Struct.Tile.get_variant_id tile_inst)) ] ++ (List.concatMap diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm index 36ddade..171ed34 100644 --- a/src/map-editor/src/Comm/SetMap.elm +++ b/src/map-editor/src/Comm/SetMap.elm @@ -17,14 +17,14 @@ type alias MapData = { w : Int, h : Int, - t : (List (List Int)) + t : (List (List String)) } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- deserialize_tile_borders : ( - (List Int) -> + (List String) -> (List Struct.Tile.Border) -> (List Struct.Tile.Border) ) @@ -39,7 +39,12 @@ deserialize_tile_borders rem_ints current_borders = _ -> [] -deserialize_tile_instance : Int -> Int -> (List Int) -> Struct.Tile.Instance +deserialize_tile_instance : ( + Int -> + Int -> + (List String) -> + Struct.Tile.Instance + ) deserialize_tile_instance map_width index t = case t of (a :: (b :: c)) -> @@ -51,7 +56,7 @@ deserialize_tile_instance map_width index t = a b Constants.Movement.cost_when_out_of_bounds - -1 + "-1" (deserialize_tile_borders c []) ) @@ -61,10 +66,10 @@ deserialize_tile_instance map_width index t = x = (index % map_width), y = (index // map_width) } - 0 - 0 + "0" + "0" Constants.Movement.cost_when_out_of_bounds - -1 + "-1" [] ) @@ -93,7 +98,7 @@ decode = (Json.Decode.field "h" Json.Decode.int) (Json.Decode.field "t" - (Json.Decode.list (Json.Decode.list Json.Decode.int)) + (Json.Decode.list (Json.Decode.list Json.Decode.string)) ) ) ) diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index 449f590..6d22666 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -8,6 +8,7 @@ import Struct.Error import Struct.HelpRequest import Struct.Location import Struct.ServerReply +import Struct.Tile import Struct.Toolbox import Struct.UI @@ -25,7 +26,7 @@ type Type = | ModeRequested Struct.Toolbox.Mode | ShapeRequested Struct.Toolbox.Shape | ClearSelectionRequested - | TemplateRequested (Int, Int) + | TemplateRequested (Struct.Tile.Ref, Struct.Tile.VariantID) | PrettifySelectionRequested | SendMapUpdateRequested | GoToMainMenu diff --git a/src/map-editor/src/Struct/Map.elm b/src/map-editor/src/Struct/Map.elm index ca16a4c..a00bba2 100644 --- a/src/map-editor/src/Struct/Map.elm +++ b/src/map-editor/src/Struct/Map.elm @@ -90,7 +90,7 @@ try_getting_tile_at loc map = then (Array.get (location_to_index loc map) map.content) else Nothing -solve_tiles : (Dict.Dict Int Struct.Tile.Type) -> Type -> Type +solve_tiles : (Dict.Dict Struct.Tile.Ref 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/Model.elm b/src/map-editor/src/Struct/Model.elm index a7ec964..7b04aa8 100644 --- a/src/map-editor/src/Struct/Model.elm +++ b/src/map-editor/src/Struct/Model.elm @@ -33,7 +33,11 @@ type alias Type = toolbox: Struct.Toolbox.Type, help_request: Struct.HelpRequest.Type, map: Struct.Map.Type, - tile_patterns: (Dict.Dict String Int), + tile_patterns: + (Dict.Dict + Struct.TilePattern.Actual + Struct.Tile.VariantID + ), wild_tile_patterns: (List Struct.TilePattern.Type), tiles: (Dict.Dict Struct.Tile.Ref Struct.Tile.Type), error: (Maybe Struct.Error.Type), @@ -107,7 +111,7 @@ add_tile_pattern tp model = tile_patterns = (Dict.insert (Struct.TilePattern.get_pattern tp) - (Struct.TilePattern.get_variant tp) + (Struct.TilePattern.get_variant_id tp) model.tile_patterns ) } diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm index 1534d26..2b33ed0 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -1,6 +1,8 @@ module Struct.Tile exposing ( Ref, + VariantID, + FamilyID, Type, Instance, Border, @@ -14,14 +16,14 @@ module Struct.Tile exposing set_borders, get_borders, get_border_type_id, - get_border_variant_ix, + get_border_variant_id, get_cost, get_instance_cost, get_location, get_type_id, get_family, get_instance_family, - get_variant_ix, + get_variant_id, get_local_variant_ix, solve_tile_instance, decoder @@ -42,39 +44,41 @@ import Struct.Location -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -type alias Ref = Int +type alias Ref = String +type alias VariantID = String +type alias FamilyID = String type alias PartiallyDecoded = { - id : Int, + id : Ref, nam : String, ct : Int, - fa : Int, + fa : FamilyID, de : Int } type alias Type = { - id : Int, + id : Ref, name : String, crossing_cost : Int, - family : Int, + family : FamilyID, depth : Int } type alias Border = { - type_id : Int, - variant_ix : Int + type_id : Ref, + variant_id : VariantID } type alias Instance = { location : Struct.Location.Type, crossing_cost : Int, - family : Int, - type_id : Int, - variant_ix : Int, + family : FamilyID, + type_id : Ref, + variant_id : VariantID, borders : (List Border) } @@ -112,7 +116,7 @@ finish_decoding add_tile = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : Int -> String -> Int -> Int -> Int -> Type +new : Ref -> String -> Int -> FamilyID -> Int -> Type new id name crossing_cost family depth = { id = id, @@ -125,27 +129,27 @@ new id name crossing_cost family depth = clone_instance : Struct.Location.Type -> Instance -> Instance clone_instance loc inst = {inst | location = loc} -new_border : Int -> Int -> Border -new_border type_id variant_ix = +new_border : Ref -> VariantID -> Border +new_border type_id variant_id = { type_id = type_id, - variant_ix = variant_ix + variant_id = variant_id } new_instance : ( Struct.Location.Type -> + Ref -> + VariantID -> Int -> - Int -> - Int -> - Int -> + FamilyID -> (List Border) -> Instance ) -new_instance location type_id variant_ix crossing_cost family borders = +new_instance location type_id variant_id crossing_cost family borders = { location = location, type_id = type_id, - variant_ix = variant_ix, + variant_id = variant_id, crossing_cost = crossing_cost, family = family, borders = borders @@ -155,14 +159,14 @@ error_tile_instance : Int -> Int -> Instance error_tile_instance x y = { location = {x = x, y = y}, - type_id = 0, - variant_ix = 0, - family = 0, + type_id = "0", + variant_id = "0", + family = "0", crossing_cost = Constants.Movement.cost_when_out_of_bounds, borders = [] } -get_id : Type -> Int +get_id : Type -> Ref get_id tile = tile.id get_cost : Type -> Int @@ -177,13 +181,13 @@ get_name tile = tile.name get_location : Instance -> Struct.Location.Type get_location tile_inst = tile_inst.location -get_type_id : Instance -> Int +get_type_id : Instance -> Ref get_type_id tile_inst = tile_inst.type_id -get_border_type_id : Border -> Int +get_border_type_id : Border -> Ref get_border_type_id tile_border = tile_border.type_id -get_family : Type -> Int +get_family : Type -> FamilyID get_family tile = tile.family set_borders : (List Border) -> Instance -> Instance @@ -192,14 +196,14 @@ 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 : Instance -> FamilyID get_instance_family tile_inst = tile_inst.family -get_variant_ix : Instance -> Int -get_variant_ix tile_inst = tile_inst.variant_ix +get_variant_id : Instance -> VariantID +get_variant_id tile_inst = tile_inst.variant_id -get_border_variant_ix : Border -> Int -get_border_variant_ix tile_border = tile_border.variant_ix +get_border_variant_id : Border -> VariantID +get_border_variant_id tile_border = tile_border.variant_id get_local_variant_ix : Instance -> Int get_local_variant_ix tile_inst = @@ -212,7 +216,7 @@ get_local_variant_ix tile_inst = % Constants.UI.local_variants_per_tile ) -solve_tile_instance : (Dict.Dict Int Type) -> Instance -> Instance +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) -> @@ -224,7 +228,7 @@ solve_tile_instance tiles tile_instance = Nothing -> {tile_instance | crossing_cost = -1, - family = -1 + family = "-1" } decoder : (Json.Decode.Decoder Type) @@ -233,10 +237,10 @@ decoder = (finish_decoding) (Json.Decode.Pipeline.decode PartiallyDecoded - |> (Json.Decode.Pipeline.required "id" Json.Decode.int) + |> (Json.Decode.Pipeline.required "id" Json.Decode.string) |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) |> (Json.Decode.Pipeline.required "ct" Json.Decode.int) - |> (Json.Decode.Pipeline.required "fa" Json.Decode.int) + |> (Json.Decode.Pipeline.required "fa" Json.Decode.string) |> (Json.Decode.Pipeline.required "de" Json.Decode.int) ) ) diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index 7c9279e..6e2e202 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -1,11 +1,12 @@ module Struct.TilePattern exposing ( Type, + Actual, decoder, get_pattern_for, patterns_match, get_pattern, - get_variant, + get_variant_id, is_wild ) @@ -21,11 +22,13 @@ import Struct.Tile -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +type alias Actual = String + type alias Type = { - v : Int, + v : Struct.Tile.VariantID, w : Bool, - p : String + p : Actual } -------------------------------------------------------------------------------- @@ -35,14 +38,14 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_pattern_for : Int -> (List Struct.Tile.Instance) -> String +get_pattern_for : Struct.Tile.FamilyID -> (List Struct.Tile.Instance) -> Actual get_pattern_for source_fa neighborhood = (List.foldl (\t -> \acc -> let t_fa = (Struct.Tile.get_instance_family t) in - if ((t_fa == -1) || (t_fa == source_fa)) + if ((t_fa == "-1") || (t_fa == source_fa)) then (acc ++ "1") else (acc ++ "0") ) @@ -50,7 +53,7 @@ get_pattern_for source_fa neighborhood = neighborhood ) -patterns_match : String -> String -> Bool +patterns_match : Actual -> Actual -> Bool patterns_match a b = case ((String.uncons a), (String.uncons b)) of (Nothing, _) -> True @@ -61,11 +64,11 @@ patterns_match a b = (_, _) -> False -get_pattern : Type -> String +get_pattern : Type -> Actual get_pattern tp = tp.p -get_variant : Type -> Int -get_variant tp = tp.v +get_variant_id : Type -> Struct.Tile.VariantID +get_variant_id tp = tp.v is_wild : Type -> Bool is_wild tp = tp.w @@ -74,7 +77,7 @@ decoder : (Json.Decode.Decoder Type) decoder = (Json.Decode.Pipeline.decode Type - |> (Json.Decode.Pipeline.required "v" (Json.Decode.int)) + |> (Json.Decode.Pipeline.required "v" (Json.Decode.string)) |> (Json.Decode.Pipeline.required "w" (Json.Decode.bool)) |> (Json.Decode.Pipeline.required "p" (Json.Decode.string)) ) diff --git a/src/map-editor/src/Update/PrettifySelectedTiles.elm b/src/map-editor/src/Update/PrettifySelectedTiles.elm index dd89ea1..ef62479 100644 --- a/src/map-editor/src/Update/PrettifySelectedTiles.elm +++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm @@ -34,7 +34,11 @@ neighborhood_tile_instances loc map = (Struct.Location.get_full_neighborhood loc) ) -get_nigh_patterns : Int -> (List Struct.Tile.Instance) -> (List (Int, Int)) +get_nigh_patterns : ( + Struct.Tile.FamilyID -> + (List Struct.Tile.Instance) -> + (List (Struct.Tile.FamilyID, Struct.Tile.Ref)) + ) get_nigh_patterns source_fm full_neighborhood = (Set.toList (List.foldl @@ -61,7 +65,7 @@ get_nigh_patterns source_fm full_neighborhood = nigh_pattern_to_border : ( Struct.Model.Type -> (List Struct.Tile.Instance) -> - (Int, Int) -> + (Struct.Tile.FamilyID, Struct.Tile.Ref) -> (Struct.Tile.Border) ) nigh_pattern_to_border model full_neighborhood nigh_pattern = @@ -82,11 +86,11 @@ nigh_pattern_to_border model full_neighborhood nigh_pattern = model.wild_tile_patterns ) of - Nothing -> (Struct.Tile.new_border 0 0) + Nothing -> (Struct.Tile.new_border "0" "0") (Just tp) -> (Struct.Tile.new_border tid - (Struct.TilePattern.get_variant tp) + (Struct.TilePattern.get_variant_id tp) ) (Just v) -> (Struct.Tile.new_border tid v) diff --git a/src/map-editor/src/Update/SetToolboxTemplate.elm b/src/map-editor/src/Update/SetToolboxTemplate.elm index cb7b783..4a0593d 100644 --- a/src/map-editor/src/Update/SetToolboxTemplate.elm +++ b/src/map-editor/src/Update/SetToolboxTemplate.elm @@ -16,11 +16,11 @@ import Struct.Model -------------------------------------------------------------------------------- apply_to : ( Struct.Model.Type -> - Int -> - Int -> + String -> + String -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) -apply_to model main_class variant_ix = +apply_to model main_class_id variant_id = ( {model | toolbox = @@ -29,10 +29,10 @@ apply_to model main_class variant_ix = model.tiles (Struct.Tile.new_instance {x = 0, y = 0} - main_class - variant_ix - 0 + main_class_id + variant_id 0 + "0" [] ) ) diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index bd3bc81..32f536c 100644 --- a/src/map-editor/src/View/Map/Tile.elm +++ b/src/map-editor/src/View/Map/Tile.elm @@ -33,9 +33,9 @@ get_layer_html index border = ( "url(" ++ Constants.IO.tile_assets_url - ++ (toString (Struct.Tile.get_border_type_id border)) + ++ (Struct.Tile.get_border_type_id border) ++ "-f-" - ++ (toString (Struct.Tile.get_border_variant_ix border)) + ++ (Struct.Tile.get_border_variant_id border) ++ ".svg)" ) ) @@ -61,7 +61,7 @@ get_content_html tile = ( "url(" ++ Constants.IO.tile_assets_url - ++ (toString (Struct.Tile.get_type_id tile)) + ++ (Struct.Tile.get_type_id tile) ++ "-bg.svg)" ) ) @@ -82,9 +82,9 @@ get_content_html tile = ( "url(" ++ Constants.IO.tile_assets_url - ++ (toString (Struct.Tile.get_type_id tile)) + ++ (Struct.Tile.get_type_id tile) ++ "-v-" - ++ (toString (Struct.Tile.get_variant_ix tile)) + ++ (Struct.Tile.get_variant_id tile) ++ ".svg)" ) ) diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm b/src/map-editor/src/View/SubMenu/Tiles.elm index c2bb171..591b312 100644 --- a/src/map-editor/src/View/SubMenu/Tiles.elm +++ b/src/map-editor/src/View/SubMenu/Tiles.elm @@ -14,30 +14,30 @@ import View.Map.Tile -------------------------------------------------------------------------------- -- 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 - [ - (Html.Attributes.class "map-tile"), - (Html.Attributes.class "map-tiled"), - (Html.Attributes.class "clickable"), - (Html.Attributes.class "map-tile-variant-0"), - (Html.Events.onClick - (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 - [] +get_icon_html index = + let tile_id = (toString index) in + (Html.div + [ + (Html.Attributes.class "map-tile"), + (Html.Attributes.class "map-tiled"), + (Html.Attributes.class "clickable"), + (Html.Attributes.class "map-tile-variant-0"), + (Html.Events.onClick + (Struct.Event.TemplateRequested (tile_id, "0")) + ) + ] + (View.Map.Tile.get_content_html + (Struct.Tile.new_instance + {x = 0, y = 0} + tile_id + "0" + 0 + "0" + [] + ) ) ) - ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- |