summaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/asset/www/data/tile_patterns.json.m4 | 8 | ||||
-rw-r--r-- | src/map-editor/src/Comm/AddTilePattern.elm | 24 | ||||
-rw-r--r-- | src/map-editor/src/Comm/LoadTilePatterns.elm | 31 | ||||
-rw-r--r-- | src/map-editor/src/Comm/Send.elm | 2 | ||||
-rw-r--r-- | src/map-editor/src/Constants/IO.elm.m4 | 3 | ||||
-rw-r--r-- | src/map-editor/src/ElmModule/Init.elm | 5 | ||||
-rw-r--r-- | src/map-editor/src/ElmModule/Update.elm | 6 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Event.elm | 1 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Location.elm | 13 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Model.elm | 36 | ||||
-rw-r--r-- | src/map-editor/src/Struct/ServerReply.elm | 2 | ||||
-rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 4 | ||||
-rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 14 | ||||
-rw-r--r-- | src/map-editor/src/Update/PrettifySelectedTiles.elm | 49 | ||||
-rw-r--r-- | src/map-editor/src/View/Toolbox.elm | 4 |
15 files changed, 169 insertions, 33 deletions
diff --git a/src/asset/www/data/tile_patterns.json.m4 b/src/asset/www/data/tile_patterns.json.m4 new file mode 100644 index 0000000..9d52da4 --- /dev/null +++ b/src/asset/www/data/tile_patterns.json.m4 @@ -0,0 +1,8 @@ +[ +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 + { + "msg": "okay" + } +] diff --git a/src/map-editor/src/Comm/AddTilePattern.elm b/src/map-editor/src/Comm/AddTilePattern.elm new file mode 100644 index 0000000..bf9b15d --- /dev/null +++ b/src/map-editor/src/Comm/AddTilePattern.elm @@ -0,0 +1,24 @@ +module Comm.AddTilePattern exposing (decode) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode + +-- Battlemap ------------------------------------------------------------------- +import Struct.TilePattern +import Struct.ServerReply + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +internal_decoder : Struct.TilePattern.Type -> Struct.ServerReply.Type +internal_decoder tp = (Struct.ServerReply.AddTilePattern tp) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decode : (Json.Decode.Decoder Struct.ServerReply.Type) +decode = (Json.Decode.map (internal_decoder) (Struct.TilePattern.decoder)) diff --git a/src/map-editor/src/Comm/LoadTilePatterns.elm b/src/map-editor/src/Comm/LoadTilePatterns.elm new file mode 100644 index 0000000..b730642 --- /dev/null +++ b/src/map-editor/src/Comm/LoadTilePatterns.elm @@ -0,0 +1,31 @@ +module Comm.LoadTilePatterns exposing (try) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Comm.Send + +import Constants.IO + +import Struct.Event +import Struct.Model + +-------------------------------------------------------------------------------- +-- TYPES ------------------------------------------------------------------------ +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +try : Struct.Model.Type -> (Maybe (Cmd Struct.Event.Type)) +try model = + (Just + (Comm.Send.empty_request + model + Constants.IO.tile_patterns_data_url + ) + ) diff --git a/src/map-editor/src/Comm/Send.elm b/src/map-editor/src/Comm/Send.elm index f620f68..d70fc13 100644 --- a/src/map-editor/src/Comm/Send.elm +++ b/src/map-editor/src/Comm/Send.elm @@ -8,6 +8,7 @@ import Json.Encode -- Battlemap ------------------------------------------------------------------- import Comm.AddTile +import Comm.AddTilePattern import Comm.Okay import Comm.SetMap @@ -26,6 +27,7 @@ internal_decoder : String -> (Json.Decode.Decoder Struct.ServerReply.Type) internal_decoder reply_type = case reply_type of "add_tile" -> (Comm.AddTile.decode) + "add_tile_pattern" -> (Comm.AddTilePattern.decode) "set_map" -> (Comm.SetMap.decode) "okay" -> (Comm.Okay.decode) other -> diff --git a/src/map-editor/src/Constants/IO.elm.m4 b/src/map-editor/src/Constants/IO.elm.m4 index 397efaa..4ee92bc 100644 --- a/src/map-editor/src/Constants/IO.elm.m4 +++ b/src/map-editor/src/Constants/IO.elm.m4 @@ -9,6 +9,9 @@ data_url = (base_url ++ "/asset/data/") tiles_data_url : String tiles_data_url = (base_url ++ "/asset/data/tiles.json") +tile_patterns_data_url : String +tile_patterns_data_url = (base_url ++ "/asset/data/tile_patterns.json") + map_editor_handler_url : String map_editor_handler_url = (base_url ++ "/handler/map-editor") diff --git a/src/map-editor/src/ElmModule/Init.elm b/src/map-editor/src/ElmModule/Init.elm index 09034dc..40e49b3 100644 --- a/src/map-editor/src/ElmModule/Init.elm +++ b/src/map-editor/src/ElmModule/Init.elm @@ -3,6 +3,7 @@ module ElmModule.Init exposing (init) -- Elm ------------------------------------------------------------------------- -- Battlemap ------------------------------------------------------------------- +import Comm.LoadTilePatterns import Comm.LoadTiles import Comm.LoadMap @@ -31,6 +32,10 @@ init flags = (case (Comm.LoadMap.try model) of (Just cmd) -> cmd Nothing -> Cmd.none + ), + (case (Comm.LoadTilePatterns.try model) of + (Just cmd) -> cmd + Nothing -> Cmd.none ) ] ) diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm index 76ee2e1..8ae27f4 100644 --- a/src/map-editor/src/ElmModule/Update.elm +++ b/src/map-editor/src/ElmModule/Update.elm @@ -7,14 +7,15 @@ import Struct.Event import Struct.Model import Update.ChangeScale +import Update.ClearToolboxSelection import Update.HandleServerReply +import Update.PrettifySelectedTiles import Update.SelectTab import Update.SelectTile import Update.SetRequestedHelp import Update.SetToolboxMode import Update.SetToolboxShape import Update.SetToolboxTemplate -import Update.ClearToolboxSelection -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -67,3 +68,6 @@ update event model = Struct.Event.ClearSelectionRequested -> (Update.ClearToolboxSelection.apply_to new_model) + + Struct.Event.PrettifySelectionRequested -> + (Update.PrettifySelectedTiles.apply_to new_model) diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index 498fbab..b8fac70 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -27,6 +27,7 @@ type Type = | ShapeRequested Struct.Toolbox.Shape | ClearSelectionRequested | TemplateRequested Int + | PrettifySelectionRequested 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 d107bdd..0b373cb 100644 --- a/src/map-editor/src/Struct/Location.elm +++ b/src/map-editor/src/Struct/Location.elm @@ -50,6 +50,19 @@ neighbors loc = {loc | y = (loc.y + 1)} ] +get_full_neighborhood : Type -> (List Type) +get_full_neighborhood loc = + [ + {loc | x = (loc.x - 1), y = (loc.y - 1)}, + {loc | y = (loc.y - 1)}, + {loc | x = (loc.x + 1), y = (loc.y - 1)}, + {loc | x = (loc.x - 1)}, + {loc | x = (loc.x + 1)}, + {loc | x = (loc.x - 1), y = (loc.y + 1)}, + {loc | y = (loc.y + 1)}, + {loc | x = (loc.x + 1), y = (loc.y + 1)} + ] + get_ref : Type -> Ref get_ref l = (l.x, l.y) diff --git a/src/map-editor/src/Struct/Model.elm b/src/map-editor/src/Struct/Model.elm index ffa413f..df7d5cc 100644 --- a/src/map-editor/src/Struct/Model.elm +++ b/src/map-editor/src/Struct/Model.elm @@ -4,6 +4,8 @@ module Struct.Model exposing new, add_tile, add_tile_pattern, + get_tile_patterns_for, + get_wild_tile_patterns, invalidate, reset, clear_error @@ -34,7 +36,8 @@ type alias Type = toolbox: Struct.Toolbox.Type, help_request: Struct.HelpRequest.Type, map: Struct.Map.Type, - tile_patterns: (Dict.Dict (Maybe Int) (List Struct.TilePattern.Type)), + wild_tile_patterns: (List Struct.TilePattern.Type), + tile_patterns: (Dict.Dict Int (List Struct.TilePattern.Type)), tiles: (Dict.Dict Struct.Tile.Ref Struct.Tile.Type), error: (Maybe Struct.Error.Type), player_id: String, @@ -60,7 +63,8 @@ new flags = help_request = Struct.HelpRequest.None, map = (Struct.Map.empty), tiles = (Dict.empty), - tile_patterns = [], + wild_tile_patterns = [], + tile_patterns = (Dict.empty), error = Nothing, map_id = "", player_id = @@ -100,44 +104,32 @@ 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 (Just i) model.tile_patterns) of + case (Dict.get i model.tile_patterns) of Nothing -> {model | tile_patterns = - (Dict.insert (Just i) [tp] model.tile_patterns) + (Dict.insert i [tp] model.tile_patterns) } (Just l) -> {model | tile_patterns = - (Dict.insert (Just i) (tp :: l) model.tile_patterns) + (Dict.insert i (tp :: l) model.tile_patterns) } _ -> - case (Dict.get Nothing model.tile_patterns) of - Nothing -> - {model | - tile_patterns = - (Dict.insert Nothing [tp] model.tile_patterns) - } - - (Just l) -> - {model | - tile_patterns = - (Dict.insert Nothing (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 (Just i) model.tile_patterns) of + 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 = - case (Dict.get Nothing model.tile_patterns) of - Nothing -> [] - (Just r) -> r +get_wild_tile_patterns model = model.wild_tile_patterns reset : Type -> Type reset model = diff --git a/src/map-editor/src/Struct/ServerReply.elm b/src/map-editor/src/Struct/ServerReply.elm index 6f2da71..177950b 100644 --- a/src/map-editor/src/Struct/ServerReply.elm +++ b/src/map-editor/src/Struct/ServerReply.elm @@ -5,6 +5,7 @@ module Struct.ServerReply exposing (Type(..)) -- Battlemap ------------------------------------------------------------------- import Struct.Map import Struct.Tile +import Struct.TilePattern -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -13,6 +14,7 @@ import Struct.Tile type Type = Okay | AddTile Struct.Tile.Type + | AddTilePattern Struct.TilePattern.Type | SetMap Struct.Map.Type -------------------------------------------------------------------------------- diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index 3a4c752..ea3a6d1 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -107,5 +107,5 @@ decoder = get_target : Type -> Int get_target tile_pattern = tile_pattern.t -get_source_pattern : Type -> Int -get_source_pattern 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 e110603..e4a178b 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -18,6 +18,7 @@ import Struct.Event import Struct.Model import Struct.ServerReply import Struct.Tile +import Struct.TilePattern import Struct.UI -------------------------------------------------------------------------------- @@ -37,6 +38,16 @@ add_tile tl current_state = (_, (Just _)) -> current_state (model, _) -> ((Struct.Model.add_tile tl model), Nothing) +add_tile_pattern : ( + Struct.TilePattern.Type -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) + ) +add_tile_pattern tp current_state = + case current_state of + (_, (Just _)) -> current_state + (model, _) -> ((Struct.Model.add_tile_pattern tp model), Nothing) + set_map : ( Struct.Map.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -79,6 +90,9 @@ apply_command command current_state = (Struct.ServerReply.AddTile tl) -> (add_tile tl current_state) + (Struct.ServerReply.AddTilePattern tp) -> + (add_tile_pattern tp current_state) + (Struct.ServerReply.SetMap map) -> (set_map map current_state) diff --git a/src/map-editor/src/Update/PrettifySelectedTiles.elm b/src/map-editor/src/Update/PrettifySelectedTiles.elm index f6a23ce..caee831 100644 --- a/src/map-editor/src/Update/PrettifySelectedTiles.elm +++ b/src/map-editor/src/Update/PrettifySelectedTiles.elm @@ -1,23 +1,45 @@ module Update.PrettifySelectedTiles exposing (apply_to) + -- Elm ------------------------------------------------------------------------- +import Dict -- Battlemap ------------------------------------------------------------------- import Struct.Event -import Struct.Toolbox +import Struct.Location import Struct.Map +import Struct.Model import Struct.Tile import Struct.TilePattern -import Struct.Model +import Struct.Toolbox + +import Util.List -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +set_tile_to : ( + Struct.Model.Type -> + Struct.Location.Type -> + Int -> + Struct.Map.Type -> + Struct.Map.Type + ) +set_tile_to model loc id map = + (Struct.Map.set_tile_to + loc + (Struct.Tile.solve_tile_instance + (Dict.values model.tiles) + (Struct.Tile.error_tile_instance id loc.x loc.y) + ) + map + ) + apply_to_location : ( (List Struct.TilePattern.Type) -> Struct.Model.Type -> Struct.Location.Type -> Struct.Map.Type -> - Struct.Map.Type -> + Struct.Map.Type ) apply_to_location wild_patterns model loc map = case (Struct.Map.try_getting_tile_at loc map) of @@ -28,11 +50,11 @@ apply_to_location wild_patterns model loc map = full_neighborhood_class_ids = (List.map (\e -> - case (Struct.Map.try_getting_tile_at \e map) of + case (Struct.Map.try_getting_tile_at e map) of Nothing -> -1 - (Just e) -> (Struct.Tile.get_type_id e) + (Just t) -> (Struct.Tile.get_type_id t) ) - (Struct.Map.try_getting_tile_at loc map) + (Struct.Location.get_full_neighborhood loc) ) in case @@ -45,6 +67,12 @@ apply_to_location wild_patterns model loc map = ) of (Just pattern) -> -- TODO + (set_tile_to + model + loc + (Struct.TilePattern.get_target pattern) + map + ) Nothing -> case @@ -57,6 +85,12 @@ apply_to_location wild_patterns model loc map = ) of (Just pattern) -> -- TODO + (set_tile_to + model + loc + (Struct.TilePattern.get_target pattern) + map + ) Nothing -> map @@ -79,7 +113,6 @@ apply_to model = model.map (Struct.Toolbox.get_selection model.toolbox) ) - } - {model | toolbox = (Struct.Toolbox.set_mode mode model.toolbox)}, + }, Cmd.none ) diff --git a/src/map-editor/src/View/Toolbox.elm b/src/map-editor/src/View/Toolbox.elm index 5dacb13..4054c4d 100644 --- a/src/map-editor/src/View/Toolbox.elm +++ b/src/map-editor/src/View/Toolbox.elm @@ -117,6 +117,10 @@ get_others_menu_html = (Html.button [(Html.Events.onClick Struct.Event.ClearSelectionRequested)] [(Html.text "Clear Selection")] + ), + (Html.button + [(Html.Events.onClick Struct.Event.PrettifySelectionRequested)] + [(Html.text "Prettify Selection")] ) ] ) |