summaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/asset/www/data/tile_patterns.json.m4 | 2 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Model.elm | 42 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 6 | ||||
-rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 130 | ||||
-rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 6 | ||||
-rw-r--r-- | src/map-editor/src/Update/PrettifySelectedTiles.elm | 102 | ||||
-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 |
8 files changed, 135 insertions, 157 deletions
diff --git a/src/asset/www/data/tile_patterns.json.m4 b/src/asset/www/data/tile_patterns.json.m4 index 9d52da4..30bea4e 100644 --- a/src/asset/www/data/tile_patterns.json.m4 +++ b/src/asset/www/data/tile_patterns.json.m4 @@ -1,7 +1,7 @@ [ m4_include(__MAKEFILE_DATA_DIR/tile/pattern/global.m4.conf)m4_dnl __TILE_PATTERN_USE_JSON_STYLE -m4_include(__MAKEFILE_DATA_DIR/tile/pattern/grassland.m4d)m4_dnl +m4_include(__MAKEFILE_DATA_DIR/tile/pattern/frontier.m4d)m4_dnl { "msg": "okay" } diff --git a/src/map-editor/src/Struct/Model.elm b/src/map-editor/src/Struct/Model.elm index df7d5cc..b71cec3 100644 --- a/src/map-editor/src/Struct/Model.elm +++ b/src/map-editor/src/Struct/Model.elm @@ -2,11 +2,8 @@ module Struct.Model exposing ( Type, new, - add_tile, - add_tile_pattern, - get_tile_patterns_for, - get_wild_tile_patterns, invalidate, + add_tile, reset, clear_error ) @@ -36,8 +33,7 @@ type alias Type = toolbox: Struct.Toolbox.Type, help_request: Struct.HelpRequest.Type, map: Struct.Map.Type, - wild_tile_patterns: (List Struct.TilePattern.Type), - tile_patterns: (Dict.Dict Int (List Struct.TilePattern.Type)), + tile_patterns: (List Struct.TilePattern.Type), tiles: (Dict.Dict Struct.Tile.Ref Struct.Tile.Type), error: (Maybe Struct.Error.Type), player_id: String, @@ -63,8 +59,7 @@ new flags = help_request = Struct.HelpRequest.None, map = (Struct.Map.empty), tiles = (Dict.empty), - wild_tile_patterns = [], - tile_patterns = (Dict.empty), + tile_patterns = [], error = Nothing, map_id = "", player_id = @@ -100,37 +95,6 @@ add_tile tl model = ) } -add_tile_pattern : Struct.TilePattern.Type -> Type -> Type -add_tile_pattern tp model = - case (Struct.TilePattern.get_source_pattern tp) of - (Struct.TilePattern.Exactly i) -> - case (Dict.get i model.tile_patterns) of - Nothing -> - {model | - tile_patterns = - (Dict.insert i [tp] model.tile_patterns) - } - - (Just l) -> - {model | - tile_patterns = - (Dict.insert i (tp :: l) model.tile_patterns) - } - - _ -> - {model | - wild_tile_patterns = (tp :: model.wild_tile_patterns) - } - -get_tile_patterns_for : Int -> Type -> (List Struct.TilePattern.Type) -get_tile_patterns_for i model = - case (Dict.get i model.tile_patterns) of - Nothing -> [] - (Just r) -> r - -get_wild_tile_patterns : Type -> (List Struct.TilePattern.Type) -get_wild_tile_patterns model = model.wild_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 7583d51..7fa9260 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -15,6 +15,7 @@ module Struct.Tile exposing get_icon_id, get_type_id, get_variant_ix, + get_local_variant_ix, solve_tile_instance, decoder ) @@ -151,7 +152,10 @@ get_type_id : Instance -> Int get_type_id tile_inst = tile_inst.type_id get_variant_ix : Instance -> Int -get_variant_ix tile_inst = +get_variant_ix tile_inst = tile_inst.variant_ix + +get_local_variant_ix : Instance -> Int +get_local_variant_ix tile_inst = ( (noise_function tile_inst.location.x diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index 47747a0..5584d99 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -4,9 +4,7 @@ module Struct.TilePattern exposing Type, decoder, matches, - matches_pattern, - get_source_pattern, - get_target + matches_pattern ) -- Elm ------------------------------------------------------------------------- @@ -28,98 +26,120 @@ import Util.List -------------------------------------------------------------------------------- type PatternElement = Any - | Exactly Int - | Not Int + | Major + | Minor type alias Type = { - s : PatternElement, - t : (Int, Int, Int), + t : (PatternElement, PatternElement), + tv : Int, p : (List PatternElement) } -type alias PartialPatternElement = - { - c : String, - i : Int - } - -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- - -matches_internals : (List Int) -> (List PatternElement) -> Bool -matches_internals neighbors pattern = +matches_internals : ( + Int -> + (List Int) -> + (List PatternElement) -> + (Maybe Int) -> + (Bool, Int) + ) +matches_internals source neighbors pattern maybe_border = case ((Util.List.pop neighbors), (Util.List.pop pattern)) of - (Nothing, Nothing) -> True - ((Just (n, r_n)), (Just (p, r_p))) -> - ((matches_pattern n p) && (matches_internals r_n r_p)) - - (_, _) -> False - -finish_decoding_pattern : PartialPatternElement -> PatternElement -finish_decoding_pattern ppe = - case ppe.c of - "a" -> Any - "n" -> (Not ppe.i) - _ -> (Exactly ppe.i) + (Nothing, Nothing) -> + ( + True, + ( + case maybe_border of + Nothing -> source + (Just e) -> e + ) + ) -finish_decoding_target : (List Int) -> (Int, Int, Int) + ((Just (n, r_n)), (Just (p, r_p))) -> + if (matches_pattern source n p) + then + if + ( + (maybe_border == (Just source)) + || (maybe_border == Nothing) + ) + then + (matches_internals source r_n r_p (Just n)) + else + (matches_internals source r_n r_p maybe_border) + else + (False, source) + + (_, _) -> (False, source) + +finish_decoding_pattern : String -> PatternElement +finish_decoding_pattern str = + case str of + "any" -> Any + "A" -> Minor + "B" -> Major + _ -> Major + +finish_decoding_target : ( + (List String) -> + (PatternElement, PatternElement) + ) finish_decoding_target t = case t of - [m] -> (m, m, 0) - [m, b, v] -> (m, b, v) - _ -> (0, 0, 0) + ["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.Pipeline.decode - PartialPatternElement - |> (Json.Decode.Pipeline.required "c" Json.Decode.string) - |> (Json.Decode.Pipeline.required "i" Json.Decode.int) - ) + (Json.Decode.string) ) -target_decoder : (Json.Decode.Decoder (Int, Int, Int)) +target_decoder : ( + (Json.Decode.Decoder (PatternElement, PatternElement)) + ) target_decoder = (Json.Decode.map (finish_decoding_target) - (Json.Decode.list (Json.Decode.int)) + (Json.Decode.list (Json.Decode.string)) ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -matches_pattern : Int -> PatternElement -> Bool -matches_pattern n p = +matches_pattern : Int -> Int -> PatternElement -> Bool +matches_pattern source n p = case p of - (Exactly v) -> (v == n) - (Not v) -> (v /= n) Any -> True + Major -> (source < n) + Minor -> (source >= n) -matches : (List Int) -> Int -> Type -> Bool +matches : (List Int) -> Int -> Type -> (Bool, Int, Int, Int) matches neighbors source tile_pattern = - ( - (matches_pattern source tile_pattern.s) - && (matches_internals neighbors tile_pattern.p) - ) + case (matches_internals source neighbors tile_pattern.p Nothing) of + (False, _) -> (False, 0, 0, 0) + (True, border) -> + case tile_pattern.t of + (Minor, Major) -> (True, source, border, tile_pattern.tv) + (Minor, Minor) -> (True, source, source, tile_pattern.tv) + (Major, Minor) -> (True, border, source, tile_pattern.tv) + (_, _) -> (True, border, border, tile_pattern.tv) decoder : (Json.Decode.Decoder Type) decoder = (Json.Decode.Pipeline.decode Type - |> (Json.Decode.Pipeline.required "s" (pattern_decoder)) |> (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)) ) ) - -get_target : Type -> (Int, Int, Int) -get_target tile_pattern = tile_pattern.t - -get_source_pattern : Type -> PatternElement -get_source_pattern tile_pattern = tile_pattern.s diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index 2f07ca9..24d7b2d 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -39,7 +39,11 @@ add_tile_pattern : ( add_tile_pattern tp current_state = case current_state of (_, (Just _)) -> current_state - (model, _) -> ((Struct.Model.add_tile_pattern tp model), Nothing) + (model, _) -> + ( + {model | tile_patterns = (tp :: model.tile_patterns)}, + Nothing + ) set_map : ( Struct.Map.Type -> diff --git a/src/map-editor/src/Update/PrettifySelectedTiles.elm b/src/map-editor/src/Update/PrettifySelectedTiles.elm index fe2c343..5e0e5d5 100644 --- a/src/map-editor/src/Update/PrettifySelectedTiles.elm +++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm @@ -26,27 +26,51 @@ set_tile_to : ( Struct.Map.Type ) set_tile_to loc main_class border_class variant_ix map = - (Struct.Map.set_tile_to - loc - (Struct.Tile.new_instance - 0 - 0 - main_class - border_class - variant_ix - -1 + 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 + (Struct.Tile.new_instance + loc.x + loc.y + main_class + border_class + true_variant_ix + -1 + ) + map ) - map + +find_matching_pattern : ( + Int -> + (List Int) -> + (List Struct.TilePattern.Type) -> + (Maybe (Int, Int, Int)) ) +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) + + Nothing -> Nothing apply_to_location : ( - (List Struct.TilePattern.Type) -> Struct.Model.Type -> Struct.Location.Type -> Struct.Map.Type -> Struct.Map.Type ) -apply_to_location wild_patterns model loc map = +apply_to_location model loc map = case (Struct.Map.try_getting_tile_at loc map) of Nothing -> map (Just base) -> @@ -63,51 +87,16 @@ apply_to_location wild_patterns model loc map = ) in case - (Util.List.get_first - (Struct.TilePattern.matches - full_neighborhood_class_ids - base_id - ) - (Struct.Model.get_tile_patterns_for base_id model) + (find_matching_pattern + base_id + full_neighborhood_class_ids + model.tile_patterns ) of - (Just pattern) -> -- TODO - let - (main, border, variant) = - (Struct.TilePattern.get_target pattern) - in - (set_tile_to - loc - main - border - variant - map - ) + (Just (main, border, variant)) -> + (set_tile_to loc main border variant map) - Nothing -> - case - (Util.List.get_first - (Struct.TilePattern.matches - full_neighborhood_class_ids - base_id - ) - wild_patterns - ) - of - (Just pattern) -> -- TODO - let - (main, border, variant) = - (Struct.TilePattern.get_target pattern) - in - (set_tile_to - loc - main - border - variant - map - ) - - Nothing -> map + Nothing -> map -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -121,10 +110,7 @@ apply_to model = {model | map = (List.foldl - (apply_to_location - (Struct.Model.get_wild_tile_patterns model) - model - ) + (apply_to_location model) model.map (Struct.Toolbox.get_selection model.toolbox) ) diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index 077889e..798896e 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_ix tile)) + ++ (toString (Struct.Tile.get_local_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 eeb51a8..1e5acac 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_ix tile)) + ++ (toString (Struct.Tile.get_local_variant_ix tile)) ) ), (Html.Attributes.style |