summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-04 10:23:00 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-04 10:23:00 +0200
commit74d5f55bbfa96d9a60aa9932746cbcbbe68bad8f (patch)
tree7f8f797bba39093ec8017dd12eaae8e0104b1af1
parentdd08a1e28273db632ca3b5fe4b72c57085f01429 (diff)
Lets the user save their map.
-rw-r--r--src/map-editor/src/Comm/SendMapUpdate.elm83
-rw-r--r--src/map-editor/src/ElmModule/Update.elm4
-rw-r--r--src/map-editor/src/Struct/Event.elm2
-rw-r--r--src/map-editor/src/Update/HandleServerReply.elm2
-rw-r--r--src/map-editor/src/Update/SelectTile.elm2
-rw-r--r--src/map-editor/src/Update/SendMapUpdate.elm24
-rw-r--r--src/map-editor/src/View/Map/Tile.elm1
-rw-r--r--src/map-editor/src/View/SubMenu/Settings.elm6
8 files changed, 117 insertions, 7 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
+ )
diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm
index b6c35ba..bc84f5b 100644
--- a/src/map-editor/src/ElmModule/Update.elm
+++ b/src/map-editor/src/ElmModule/Update.elm
@@ -10,6 +10,7 @@ import Update.ChangeScale
import Update.ClearToolboxSelection
import Update.HandleServerReply
import Update.PrettifySelectedTiles
+import Update.SendMapUpdate
import Update.SelectTab
import Update.SelectTile
import Update.SetRequestedHelp
@@ -71,3 +72,6 @@ update event model =
Struct.Event.PrettifySelectionRequested ->
(Update.PrettifySelectedTiles.apply_to new_model)
+
+ Struct.Event.SendMapUpdateRequested ->
+ (Update.SendMapUpdate.apply_to new_model)
diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm
index 93e6bfd..d0d84e1 100644
--- a/src/map-editor/src/Struct/Event.elm
+++ b/src/map-editor/src/Struct/Event.elm
@@ -4,7 +4,6 @@ module Struct.Event exposing (Type(..), attempted)
import Http
-- Battlemap -------------------------------------------------------------------
-import Struct.Direction
import Struct.Error
import Struct.HelpRequest
import Struct.Location
@@ -28,6 +27,7 @@ type Type =
| ClearSelectionRequested
| TemplateRequested (Int, Int)
| PrettifySelectionRequested
+ | SendMapUpdateRequested
attempted : (Result.Result err val) -> Type
attempted act =
diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm
index 5c8d74b..0e69c51 100644
--- a/src/map-editor/src/Update/HandleServerReply.elm
+++ b/src/map-editor/src/Update/HandleServerReply.elm
@@ -1,8 +1,6 @@
module Update.HandleServerReply exposing (apply_to)
-- Elm -------------------------------------------------------------------------
-import Dict
-
import Http
-- Map -------------------------------------------------------------------
diff --git a/src/map-editor/src/Update/SelectTile.elm b/src/map-editor/src/Update/SelectTile.elm
index 8d5edd2..260c533 100644
--- a/src/map-editor/src/Update/SelectTile.elm
+++ b/src/map-editor/src/Update/SelectTile.elm
@@ -3,12 +3,10 @@ module Update.SelectTile exposing (apply_to)
-- Elm -------------------------------------------------------------------------
-- Battlemap -------------------------------------------------------------------
-import Struct.Error
import Struct.Event
import Struct.Location
import Struct.Model
import Struct.Toolbox
-import Struct.UI
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
diff --git a/src/map-editor/src/Update/SendMapUpdate.elm b/src/map-editor/src/Update/SendMapUpdate.elm
new file mode 100644
index 0000000..0fd5039
--- /dev/null
+++ b/src/map-editor/src/Update/SendMapUpdate.elm
@@ -0,0 +1,24 @@
+module Update.SendMapUpdate exposing (apply_to)
+-- Elm -------------------------------------------------------------------------
+
+-- Battlemap -------------------------------------------------------------------
+import Comm.SendMapUpdate
+
+import Struct.Event
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model =
+ case (Comm.SendMapUpdate.try model) of
+ (Just cmd) -> (model, cmd)
+ Nothing -> (model, Cmd.none)
diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm
index 89b6300..bd3bc81 100644
--- a/src/map-editor/src/View/Map/Tile.elm
+++ b/src/map-editor/src/View/Map/Tile.elm
@@ -17,7 +17,6 @@ import Struct.Toolbox
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-
get_layer_html : (
Int ->
Struct.Tile.Border ->
diff --git a/src/map-editor/src/View/SubMenu/Settings.elm b/src/map-editor/src/View/SubMenu/Settings.elm
index 1661053..98405d0 100644
--- a/src/map-editor/src/View/SubMenu/Settings.elm
+++ b/src/map-editor/src/View/SubMenu/Settings.elm
@@ -36,6 +36,10 @@ get_html model =
[
(scale_button (0.75) "Zoom -"),
(scale_button 0 "Zoom Reset"),
- (scale_button (1.15) "Zoom +")
+ (scale_button (1.15) "Zoom +"),
+ (Html.button
+ [ (Html.Events.onClick Struct.Event.SendMapUpdateRequested) ]
+ [ (Html.text "Save Map") ]
+ )
]
)