From f4ab4fd16c5bb4fa905b15cc9c86daf8d75cd0bc Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 17 Jul 2018 17:54:20 +0200 Subject: Adds fill function, removes obsolete files. --- src/asset/www/data/tiles.json | 38 ---------------- src/map-editor/src/Struct/Location.elm | 9 ++++ src/map-editor/src/Struct/Map.elm | 4 +- src/map-editor/src/Struct/Toolbox.elm | 76 +++++++++++++++++++++++++++++-- src/map-editor/src/View/SubMenu/Tiles.elm | 57 ----------------------- 5 files changed, 83 insertions(+), 101 deletions(-) delete mode 100644 src/asset/www/data/tiles.json delete mode 100644 src/map-editor/src/View/SubMenu/Tiles.elm (limited to 'src') diff --git a/src/asset/www/data/tiles.json b/src/asset/www/data/tiles.json deleted file mode 100644 index 0c8f9fc..0000000 --- a/src/asset/www/data/tiles.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - - { - "msg": "add_tile", - "id": 0, - "nam": "[Grassland] Grass", - "ct": 6, - "rmi": 0, - "rma": 0 - }, - { - "msg": "add_tile", - "id": 1, - "nam": "[Grassland] Mushroom Infestation", - "ct": 12, - "rmi": 1, - "rma": 1 - }, - { - "msg": "add_tile", - "id": 2, - "nam": "[Grassland] Tree Remains", - "ct": 24, - "rmi": 2, - "rma": 2 - }, - { - "msg": "add_tile", - "id": 3, - "nam": "[Grassland] Clear Water", - "ct": 201, - "rmi": 3, - "rma": 17 - }, - { - "msg": "okay" - } -] diff --git a/src/map-editor/src/Struct/Location.elm b/src/map-editor/src/Struct/Location.elm index 94cfe11..d107bdd 100644 --- a/src/map-editor/src/Struct/Location.elm +++ b/src/map-editor/src/Struct/Location.elm @@ -41,6 +41,15 @@ neighbor dir loc = Struct.Direction.Down -> {loc | y = (loc.y + 1)} Struct.Direction.None -> loc +neighbors : Type -> (List Type) +neighbors loc = + [ + {loc | x = (loc.x + 1)}, + {loc | x = (loc.x - 1)}, + {loc | y = (loc.y - 1)}, + {loc | y = (loc.y + 1)} + ] + get_ref : Type -> Ref get_ref l = (l.x, l.y) diff --git a/src/map-editor/src/Struct/Map.elm b/src/map-editor/src/Struct/Map.elm index d6a9cea..b2f3087 100644 --- a/src/map-editor/src/Struct/Map.elm +++ b/src/map-editor/src/Struct/Map.elm @@ -84,7 +84,9 @@ try_getting_tile_at : ( (Maybe Struct.Tile.Instance) ) try_getting_tile_at loc map = - (Array.get (location_to_index loc map) map.content) + if (has_location loc map) + then (Array.get (location_to_index loc map) map.content) + else Nothing solve_tiles : (List Struct.Tile.Type) -> Type -> Type solve_tiles tiles map = diff --git a/src/map-editor/src/Struct/Toolbox.elm b/src/map-editor/src/Struct/Toolbox.elm index 7a53258..b038d27 100644 --- a/src/map-editor/src/Struct/Toolbox.elm +++ b/src/map-editor/src/Struct/Toolbox.elm @@ -93,15 +93,72 @@ apply_mode_to loc (tb, map) = ), map ) +get_filled_tiles_internals : ( + (Struct.Location.Type -> Bool) -> + (List Struct.Location.Type) -> + (List Struct.Location.Type) -> + (List Struct.Location.Type) + ) +get_filled_tiles_internals match_fun candidates result = + case (Util.List.pop candidates) of + Nothing -> result + (Just (loc, remaining_candidates)) -> + if (match_fun loc) + then + (get_filled_tiles_internals + match_fun + ( + (List.filter + (\e -> + (not + ( + (List.member e remaining_candidates) + || (List.member e result) + ) + ) + ) + (Struct.Location.neighbors loc) + ) + ++ remaining_candidates + ) + (loc :: result) + ) + else + (get_filled_tiles_internals match_fun remaining_candidates result) get_filled_tiles : ( + (List Struct.Location.Type) -> Struct.Map.Type -> Struct.Location.Type -> (List Struct.Location.Type) ) -get_filled_tiles map loc = - -- TODO: unimplemented - [] +get_filled_tiles selection map loc = + case (Struct.Map.try_getting_tile_at loc map) of + Nothing -> [] + (Just target) -> + let + target_class_id = (Struct.Tile.get_type_id target) + map_match_fun = + (\e -> + (case (Struct.Map.try_getting_tile_at e map) of + Nothing -> False + (Just t) -> + ( + (Struct.Tile.get_type_id t) + == target_class_id + ) + ) + ) + match_fun = + if (selection == []) + then map_match_fun + else (\e -> ((map_match_fun e) && (List.member e selection))) + in + (get_filled_tiles_internals + match_fun + [loc] + [] + ) get_square_tiles : ( Struct.Location.Type -> @@ -166,7 +223,8 @@ get_selection tb = tb.selection set_template : Struct.Tile.Instance -> Type -> Type set_template template tb = {tb | - template = template + template = template, + mode = Draw } set_mode : Mode -> Type -> Type @@ -211,7 +269,15 @@ apply_to loc tb map = (List.foldl (apply_mode_to) (tb, map) - (get_filled_tiles map loc) + (get_filled_tiles + ( + if (tb.mode == Draw) + then tb.selection + else [] + ) + map + loc + ) ) Square -> diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm b/src/map-editor/src/View/SubMenu/Tiles.elm deleted file mode 100644 index 2255824..0000000 --- a/src/map-editor/src/View/SubMenu/Tiles.elm +++ /dev/null @@ -1,57 +0,0 @@ -module View.SubMenu.Tiles exposing (get_html) - --- Elm ------------------------------------------------------------------------- -import Html -import Html.Attributes -import Html.Events - --- Battlemap ------------------------------------------------------------------- -import Constants.IO - -import Struct.Event - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -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.Attributes.style - [ - ( - "background-image", - ( - "url(" - ++ Constants.IO.tile_assets_url - ++ (toString icon_id) - ++".svg)" - ) - ) - ] - ), - (Html.Events.onClick (Struct.Event.TemplateRequested icon_id)) - ] - [ - ] - ) - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -get_html : (Html.Html Struct.Event.Type) -get_html = - (Html.div - [ - (Html.Attributes.class "map-tabmenu-content"), - (Html.Attributes.class "map-tabmenu-tiles-tab") - ] - (List.map - (get_icon_html) - (List.range 0 17) - ) - ) -- cgit v1.2.3-70-g09d2