summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-04 10:23:00 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-04 10:23:00 +0200 |
commit | 74d5f55bbfa96d9a60aa9932746cbcbbe68bad8f (patch) | |
tree | 7f8f797bba39093ec8017dd12eaae8e0104b1af1 /src/map-editor/src/Comm | |
parent | dd08a1e28273db632ca3b5fe4b72c57085f01429 (diff) |
Lets the user save their map.
Diffstat (limited to 'src/map-editor/src/Comm')
-rw-r--r-- | src/map-editor/src/Comm/SendMapUpdate.elm | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/map-editor/src/Comm/SendMapUpdate.elm b/src/map-editor/src/Comm/SendMapUpdate.elm new file mode 100644 index 0000000..27a5747 --- /dev/null +++ b/src/map-editor/src/Comm/SendMapUpdate.elm @@ -0,0 +1,83 @@ +module Comm.SendMapUpdate exposing (try) + +-- Elm ------------------------------------------------------------------------- +import Array + +import Json.Encode + +-- Map ------------------------------------------------------------------- +import Constants.IO + +import Comm.Send + +import Struct.Event +import Struct.Map +import Struct.Model +import Struct.Tile + +-------------------------------------------------------------------------------- +-- TYPES ------------------------------------------------------------------------ +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +encode_tile_border_values : Struct.Tile.Border -> (List Json.Encode.Value) +encode_tile_border_values border = + [ + (Json.Encode.int (Struct.Tile.get_border_type_id border)), + (Json.Encode.int (Struct.Tile.get_border_variant_ix border)) + ] + +encode_tile_instance : Struct.Tile.Instance -> Json.Encode.Value +encode_tile_instance tile_inst = + (Json.Encode.list + ( + [ + (Json.Encode.int (Struct.Tile.get_type_id tile_inst)), + (Json.Encode.int (Struct.Tile.get_variant_ix tile_inst)) + ] + ++ + (List.concat + (List.map + (encode_tile_border_values) + (Struct.Tile.get_borders tile_inst) + ) + ) + ) + ) + +encode_map : Struct.Model.Type -> (Maybe Json.Encode.Value) +encode_map model = + (Just + (Json.Encode.object + [ + ("stk", (Json.Encode.string model.session_token)), + ("pid", (Json.Encode.string model.player_id)), + ("mid", (Json.Encode.string model.map_id)), + ("w", (Json.Encode.int (Struct.Map.get_width model.map))), + ("h", (Json.Encode.int (Struct.Map.get_height model.map))), + ( + "t", + (Json.Encode.list + (List.map + (encode_tile_instance) + (Array.toList (Struct.Map.get_tiles model.map)) + ) + ) + ) + ] + ) + ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +try : Struct.Model.Type -> (Maybe (Cmd Struct.Event.Type)) +try model = + (Comm.Send.try_sending + model + Constants.IO.map_update_handler + encode_map + ) |