summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/map-editor')
-rw-r--r--src/map-editor/src/Struct/Location.elm9
-rw-r--r--src/map-editor/src/Struct/Map.elm4
-rw-r--r--src/map-editor/src/Struct/Toolbox.elm76
-rw-r--r--src/map-editor/src/View/SubMenu/Tiles.elm57
4 files changed, 83 insertions, 63 deletions
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)
- )
- )