summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-07-13 17:57:01 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-07-13 17:57:01 +0200 |
commit | 9a86bc7064fed626ecd1d3f03c7af30a5ef246c8 (patch) | |
tree | 01048538f5745065f603e14d089499e3ce0dc37f /src | |
parent | bb65777eca64d868a578d6abdbf054fb05d5d99f (diff) |
Got the rectangle mode to work.
Diffstat (limited to 'src')
-rw-r--r-- | src/map-editor/src/ElmModule/Update.elm | 9 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Event.elm | 5 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Location.elm | 7 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 7 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Toolbox.elm | 75 | ||||
-rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 19 | ||||
-rw-r--r-- | src/map-editor/src/Update/SelectTile.elm | 29 | ||||
-rw-r--r-- | src/map-editor/src/Update/SetToolboxMode.elm | 25 | ||||
-rw-r--r-- | src/map-editor/src/Update/SetToolboxShape.elm | 25 | ||||
-rw-r--r-- | src/map-editor/src/Util/List.elm | 20 | ||||
-rw-r--r-- | src/map-editor/src/View/Map.elm | 15 | ||||
-rw-r--r-- | src/map-editor/src/View/Map/Tile.elm | 14 | ||||
-rw-r--r-- | src/map-editor/src/View/Toolbox.elm | 77 | ||||
-rw-r--r-- | src/map-editor/www/style.css | 18 |
14 files changed, 301 insertions, 44 deletions
diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm index 01ff72b..e7bd797 100644 --- a/src/map-editor/src/ElmModule/Update.elm +++ b/src/map-editor/src/ElmModule/Update.elm @@ -11,7 +11,8 @@ import Update.HandleServerReply import Update.SelectTab import Update.SelectTile import Update.SetRequestedHelp - +import Update.SetToolboxMode +import Update.SetToolboxShape -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -52,3 +53,9 @@ update event model = (Struct.Event.RequestedHelp help_request) -> (Update.SetRequestedHelp.apply_to new_model help_request) + + (Struct.Event.ShapeRequested shape) -> + (Update.SetToolboxShape.apply_to new_model shape) + + (Struct.Event.ModeRequested mode) -> + (Update.SetToolboxMode.apply_to new_model mode) diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index 2edd09b..0f9cdae 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -6,9 +6,10 @@ import Http -- Battlemap ------------------------------------------------------------------- import Struct.Direction import Struct.Error +import Struct.HelpRequest import Struct.Location import Struct.ServerReply -import Struct.HelpRequest +import Struct.Toolbox import Struct.UI -------------------------------------------------------------------------------- @@ -22,6 +23,8 @@ type Type = | TabSelected Struct.UI.Tab | TileSelected Struct.Location.Ref | RequestedHelp Struct.HelpRequest.Type + | ModeRequested Struct.Toolbox.Mode + | ShapeRequested Struct.Toolbox.Shape attempted : (Result.Result err val) -> Type attempted act = diff --git a/src/map-editor/src/Struct/Location.elm b/src/map-editor/src/Struct/Location.elm index d284d05..94cfe11 100644 --- a/src/map-editor/src/Struct/Location.elm +++ b/src/map-editor/src/Struct/Location.elm @@ -25,6 +25,13 @@ type alias Ref = (Int, Int) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- +new : Int -> Int -> Type +new x y = + { + x = x, + y = y + } + neighbor : Struct.Direction.Type -> Type -> Type neighbor dir loc = case dir of diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm index d1ba4cf..00cb12e 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -125,11 +125,11 @@ new_instance x y icon_id crossing_cost type_id = type_id = type_id } -error_tile_instance : Int -> Int -> Instance -error_tile_instance x y = +error_tile_instance : Int -> Int -> Int -> Instance +error_tile_instance icon_id x y = { location = {x = x, y = y}, - icon_id = -1, + icon_id = icon_id, type_id = -1, crossing_cost = Constants.Movement.cost_when_out_of_bounds } @@ -188,6 +188,7 @@ solve_tile_instance tiles tile_instance = Nothing -> (error_tile_instance + tile_instance.icon_id tile_instance.location.x tile_instance.location.y ) diff --git a/src/map-editor/src/Struct/Toolbox.elm b/src/map-editor/src/Struct/Toolbox.elm index 9b95948..7a53258 100644 --- a/src/map-editor/src/Struct/Toolbox.elm +++ b/src/map-editor/src/Struct/Toolbox.elm @@ -5,13 +5,16 @@ module Struct.Toolbox exposing Shape(..), apply_to, is_selected, + is_square_corner, clear_selection, set_template, set_mode, set_shape, get_template, get_mode, + get_modes, get_shape, + get_shapes, get_selection, default ) @@ -23,6 +26,8 @@ import Struct.Location import Struct.Map import Struct.Tile +import Util.List + -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -56,14 +61,17 @@ apply_mode_to : ( apply_mode_to loc (tb, map) = case tb.mode of Draw -> - ( - tb, - (Struct.Map.set_tile_to - loc - (Struct.Tile.clone_instance loc tb.template) - map + if ((tb.selection == []) || (List.member loc tb.selection)) + then + ( + tb, + (Struct.Map.set_tile_to + loc + (Struct.Tile.clone_instance loc tb.template) + map + ) ) - ) + else (tb, map) RemoveSelection -> ( @@ -87,23 +95,32 @@ apply_mode_to loc (tb, map) = ) get_filled_tiles : ( - Struct.Location.Type -> Struct.Map.Type -> + Struct.Location.Type -> (List Struct.Location.Type) ) -get_filled_tiles loc map = +get_filled_tiles map loc = -- TODO: unimplemented [] get_square_tiles : ( Struct.Location.Type -> - Struct.Location.Type -> Struct.Map.Type -> + Struct.Location.Type -> (List Struct.Location.Type) ) -get_square_tiles new_loc corner map = - -- TODO: unimplemented - [] +get_square_tiles corner map new_loc = + let + x_range = + if (corner.x < new_loc.x) + then (List.range corner.x new_loc.x) + else (List.range new_loc.x corner.x) + y_range = + if (corner.y < new_loc.y) + then (List.range corner.y new_loc.y) + else (List.range new_loc.y corner.y) + in + (Util.List.product_map (Struct.Location.new) x_range y_range) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -111,7 +128,7 @@ get_square_tiles new_loc corner map = default : Type default = { - template = (Struct.Tile.error_tile_instance 0 0), + template = (Struct.Tile.error_tile_instance 0 0 0), mode = Draw, shape = Simple, selection = [], @@ -124,9 +141,25 @@ get_template tb = tb.template get_mode : Type -> Mode get_mode tb = tb.mode +get_modes : (List Mode) +get_modes = + [ + Draw, + AddSelection, + RemoveSelection + ] + get_shape : Type -> Shape get_shape tb = tb.shape +get_shapes : (List Shape) +get_shapes = + [ + Simple, + Fill, + Square + ] + get_selection : Type -> (List Struct.Location.Type) get_selection tb = tb.selection @@ -157,10 +190,14 @@ clear_selection tb = square_corner = Nothing } -is_selected : Type -> Struct.Location.Type -> Bool -is_selected tb loc = +is_selected : Struct.Location.Type -> Type -> Bool +is_selected loc tb = (List.member loc tb.selection) +is_square_corner : Struct.Location.Type -> Type -> Bool +is_square_corner loc tb = + (tb.square_corner == (Just loc)) + apply_to : ( Struct.Location.Type -> Type -> @@ -174,7 +211,7 @@ apply_to loc tb map = (List.foldl (apply_mode_to) (tb, map) - (get_filled_tiles loc map) + (get_filled_tiles map loc) ) Square -> @@ -183,6 +220,6 @@ apply_to loc tb map = (Just corner) -> (List.foldl (apply_mode_to) - (tb, map) - (get_square_tiles loc corner map) + ({tb | square_corner = Nothing}, map) + (get_square_tiles corner map loc) ) diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index 2622cf2..e110603 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -53,6 +53,22 @@ set_map map current_state = Nothing ) +refresh_map : ( + (Struct.Model.Type, (Maybe Struct.Error.Type)) -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) + ) +refresh_map current_state = + case current_state of + (_, (Just _)) -> current_state + (model, _) -> + ( + {model | + map = + (Struct.Map.solve_tiles (Dict.values model.tiles) model.map) + }, + Nothing + ) + apply_command : ( Struct.ServerReply.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -66,7 +82,8 @@ apply_command command current_state = (Struct.ServerReply.SetMap map) -> (set_map map current_state) - Struct.ServerReply.Okay -> current_state + Struct.ServerReply.Okay -> + (refresh_map current_state) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- diff --git a/src/map-editor/src/Update/SelectTile.elm b/src/map-editor/src/Update/SelectTile.elm index f1c0e07..8d5edd2 100644 --- a/src/map-editor/src/Update/SelectTile.elm +++ b/src/map-editor/src/Update/SelectTile.elm @@ -7,6 +7,7 @@ import Struct.Error import Struct.Event import Struct.Location import Struct.Model +import Struct.Toolbox import Struct.UI -------------------------------------------------------------------------------- @@ -22,16 +23,18 @@ apply_to : ( (Struct.Model.Type, (Cmd Struct.Event.Type)) ) apply_to model loc_ref = - ( - {model | - ui = - (Struct.UI.set_displayed_tab - Struct.UI.StatusTab - (Struct.UI.set_previous_action - (Just (Struct.UI.SelectedLocation loc_ref)) - model.ui - ) - ) - }, - Cmd.none - ) + let + (toolbox, map) = + (Struct.Toolbox.apply_to + (Struct.Location.from_ref loc_ref) + model.toolbox + model.map + ) + in + ( + {model | + toolbox = toolbox, + map = map + }, + Cmd.none + ) diff --git a/src/map-editor/src/Update/SetToolboxMode.elm b/src/map-editor/src/Update/SetToolboxMode.elm new file mode 100644 index 0000000..3444329 --- /dev/null +++ b/src/map-editor/src/Update/SetToolboxMode.elm @@ -0,0 +1,25 @@ +module Update.SetToolboxMode exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Event +import Struct.Toolbox +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Toolbox.Mode -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model mode = + ( + {model | toolbox = (Struct.Toolbox.set_mode mode model.toolbox)}, + Cmd.none + ) diff --git a/src/map-editor/src/Update/SetToolboxShape.elm b/src/map-editor/src/Update/SetToolboxShape.elm new file mode 100644 index 0000000..c0bd273 --- /dev/null +++ b/src/map-editor/src/Update/SetToolboxShape.elm @@ -0,0 +1,25 @@ +module Update.SetToolboxShape exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Event +import Struct.Toolbox +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Toolbox.Shape -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model shape = + ( + {model | toolbox = (Struct.Toolbox.set_shape shape model.toolbox)}, + Cmd.none + ) diff --git a/src/map-editor/src/Util/List.elm b/src/map-editor/src/Util/List.elm index 2bc5217..1f914b1 100644 --- a/src/map-editor/src/Util/List.elm +++ b/src/map-editor/src/Util/List.elm @@ -14,3 +14,23 @@ pop l = get_first : (a -> Bool) -> (List a) -> (Maybe a) get_first fun list = (List.head (List.filter fun list)) + +product_map : (a -> b -> c) -> (List a) -> (List b) -> (List c) +product_map product_fun list_a list_b = + (product_map_rec (product_fun) list_a list_b []) + +product_map_rec : (a -> b -> c) -> (List a) -> (List b) -> (List c) -> (List c) +product_map_rec product_fun list_a list_b result = + case (pop list_a) of + Nothing -> result + (Just (head, tail)) -> + (product_map_rec + (product_fun) + tail + list_b + (List.append + (List.map (product_fun head) list_b) + result + ) + ) + diff --git a/src/map-editor/src/View/Map.elm b/src/map-editor/src/View/Map.elm index f3caa95..0f75ad4 100644 --- a/src/map-editor/src/View/Map.elm +++ b/src/map-editor/src/View/Map.elm @@ -12,9 +12,10 @@ import List -- Map ------------------------------------------------------------------------- import Constants.UI -import Struct.Map import Struct.Event +import Struct.Map import Struct.Model +import Struct.Toolbox import Struct.UI import Util.Html @@ -24,8 +25,12 @@ import View.Map.Tile -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_tiles_html : Struct.Map.Type -> (Html.Html Struct.Event.Type) -get_tiles_html map = +get_tiles_html : ( + Struct.Toolbox.Type -> + Struct.Map.Type -> + (Html.Html Struct.Event.Type) + ) +get_tiles_html tb map = (Html.div [ (Html.Attributes.class "map-tiles-layer"), @@ -59,7 +64,7 @@ get_tiles_html map = ) ] (List.map - (View.Map.Tile.get_html) + (View.Map.Tile.get_html tb) (Array.toList (Struct.Map.get_tiles map)) ) ) @@ -95,6 +100,6 @@ get_html model = ) ] [ - (Html.Lazy.lazy (get_tiles_html) model.map) + (Html.Lazy.lazy2 (get_tiles_html) model.toolbox model.map) ] ) diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index 9aa8411..3431663 100644 --- a/src/map-editor/src/View/Map/Tile.elm +++ b/src/map-editor/src/View/Map/Tile.elm @@ -12,6 +12,7 @@ import Constants.IO import Struct.Event import Struct.Location import Struct.Tile +import Struct.Toolbox -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- @@ -21,10 +22,11 @@ import Struct.Tile -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- get_html : ( + Struct.Toolbox.Type -> Struct.Tile.Instance -> (Html.Html Struct.Event.Type) ) -get_html tile = +get_html tb tile = let tile_loc = (Struct.Tile.get_location tile) in @@ -32,6 +34,16 @@ get_html tile = [ (Html.Attributes.class "map-tile-icon"), (Html.Attributes.class "map-tiled"), + ( + if (Struct.Toolbox.is_selected tile_loc tb) + then (Html.Attributes.class "map-tile-selected") + else (Html.Attributes.class "") + ), + ( + if (Struct.Toolbox.is_square_corner tile_loc tb) + then (Html.Attributes.class "map-tile-square-corner") + else (Html.Attributes.class "") + ), (Html.Attributes.class ( "map-tile-variant-" diff --git a/src/map-editor/src/View/Toolbox.elm b/src/map-editor/src/View/Toolbox.elm index 77c4033..fe8825e 100644 --- a/src/map-editor/src/View/Toolbox.elm +++ b/src/map-editor/src/View/Toolbox.elm @@ -14,6 +14,80 @@ import Util.Html -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +get_template_icon_html : Struct.Toolbox.Type -> (Html.Html Struct.Event.Type) +get_template_icon_html tb = + (Html.div + [(Html.Attributes.class "map-toolbox-template")] + [ + (Html.text "[TEMPLATE_ICON]") + ] + ) + +get_mode_button : ( + Struct.Toolbox.Mode -> + Struct.Toolbox.Mode -> + (Html.Html Struct.Event.Type) + ) +get_mode_button current mode = + (Html.button + ( + if (current == mode) + then [(Html.Attributes.disabled True)] + else [(Html.Events.onClick (Struct.Event.ModeRequested mode))] + ) + [ + (Html.text + (case mode of + Struct.Toolbox.Draw -> "Draw" + Struct.Toolbox.AddSelection -> "Select+" + Struct.Toolbox.RemoveSelection -> "Select-" + ) + ) + ] + ) + +get_modes_menu_html : Struct.Toolbox.Type -> (Html.Html Struct.Event.Type) +get_modes_menu_html tb = + (Html.div + [(Html.Attributes.class "map-toolbox-modes")] + (List.map + (get_mode_button (Struct.Toolbox.get_mode tb)) + (Struct.Toolbox.get_modes) + ) + ) + +get_shape_button : ( + Struct.Toolbox.Shape -> + Struct.Toolbox.Shape -> + (Html.Html Struct.Event.Type) + ) +get_shape_button current shape = + (Html.button + ( + if (current == shape) + then [(Html.Attributes.disabled True)] + else [(Html.Events.onClick (Struct.Event.ShapeRequested shape))] + ) + [ + (Html.text + (case shape of + Struct.Toolbox.Simple -> "Single" + Struct.Toolbox.Fill -> "Fill" + Struct.Toolbox.Square -> "Rectangle" + ) + ) + ] + ) + +get_shapes_menu_html : Struct.Toolbox.Type -> (Html.Html Struct.Event.Type) +get_shapes_menu_html tb = + (Html.div + [(Html.Attributes.class "map-toolbox-shapes")] + (List.map + (get_shape_button (Struct.Toolbox.get_shape tb)) + (Struct.Toolbox.get_shapes) + ) + ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -23,5 +97,8 @@ get_html tb = (Html.div [(Html.Attributes.class "map-toolbox")] [ + (get_template_icon_html tb), + (get_modes_menu_html tb), + (get_shapes_menu_html tb) ] ) diff --git a/src/map-editor/www/style.css b/src/map-editor/www/style.css index fee293f..836a84c 100644 --- a/src/map-editor/www/style.css +++ b/src/map-editor/www/style.css @@ -354,3 +354,21 @@ .map-tile-variant-8 {background-position: 200% 200%;} .map-tile-icon {z-index: 0; position: absolute; background-size: 300%;} + +.map-tile-selected +{ + border: 1px dashed white; +} + +.map-tile-square-corner +{ + animation-name: blinking; + animation-duration: 1s; + animation-iteration-count: infinite; +} + +@keyframes blinking { + 0% {opacity: 1;} + 50% {opacity: 0;} + 100% {opacity: 1;} +} |