summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-02-18 21:47:56 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-02-18 21:47:56 +0100
commit265bdd2efca3ea4e94087bee2f55d05527beb2f0 (patch)
tree8455880960d674277cb3548fca1c5bc1ec71e856
parentd39e0230fc26cc1e32d4b2be33fa5f79618f6b11 (diff)
...
-rw-r--r--src/battle/src/Comm/SetMap.elm15
-rw-r--r--src/battle/src/Struct/Location.elm13
-rw-r--r--src/battle/src/Struct/MapMarker.elm97
-rw-r--r--src/map-editor/src/Comm/SetMap.elm3
-rw-r--r--src/map-editor/src/Struct/Map.elm6
5 files changed, 127 insertions, 7 deletions
diff --git a/src/battle/src/Comm/SetMap.elm b/src/battle/src/Comm/SetMap.elm
index 44a6136..407d214 100644
--- a/src/battle/src/Comm/SetMap.elm
+++ b/src/battle/src/Comm/SetMap.elm
@@ -1,12 +1,15 @@
module Comm.SetMap exposing (decode)
-- Elm -------------------------------------------------------------------------
+import Dict
+
import Json.Decode
-- Map -------------------------------------------------------------------------
import Constants.Movement
import Struct.Map
+import Struct.MapMarker
import Struct.ServerReply
import Struct.Tile
@@ -17,7 +20,8 @@ type alias MapData =
{
w : Int,
h : Int,
- t : (List (List String))
+ t : (List (List String)),
+ m : (Dict.Dict String Struct.MapMarker.Type)
}
--------------------------------------------------------------------------------
@@ -86,12 +90,19 @@ decode : (Json.Decode.Decoder Struct.ServerReply.Type)
decode =
(Json.Decode.map
internal_decoder
- (Json.Decode.map3 MapData
+ (Json.Decode.map4 MapData
(Json.Decode.field "w" Json.Decode.int)
(Json.Decode.field "h" Json.Decode.int)
(Json.Decode.field
"t"
(Json.Decode.list (Json.Decode.list Json.Decode.string))
)
+ (Json.Decode.field
+ "m"
+ (Json.Decode.map
+ (Dict.fromList)
+ (Json.Decode.keyValuePairs (Struct.MapMarker.decoder))
+ )
+ )
)
)
diff --git a/src/battle/src/Struct/Location.elm b/src/battle/src/Struct/Location.elm
index da62b26..90f1e03 100644
--- a/src/battle/src/Struct/Location.elm
+++ b/src/battle/src/Struct/Location.elm
@@ -4,7 +4,9 @@ module Struct.Location exposing (..)
import Json.Decode
import Json.Decode.Pipeline
--- Map -------------------------------------------------------------------
+import Json.Encode
+
+-- Battle ----------------------------------------------------------------------
import Struct.Direction
--------------------------------------------------------------------------------
@@ -57,3 +59,12 @@ decoder =
|> (Json.Decode.Pipeline.required "x" Json.Decode.int)
|> (Json.Decode.Pipeline.required "y" Json.Decode.int)
)
+
+encode : Type -> Json.Encode.Value
+encode loc =
+ (Json.Encode.object
+ [
+ ( "x", (Json.Encode.int loc.x) ),
+ ( "y", (Json.Encode.int loc.y) )
+ ]
+ )
diff --git a/src/battle/src/Struct/MapMarker.elm b/src/battle/src/Struct/MapMarker.elm
new file mode 100644
index 0000000..7b3e5e0
--- /dev/null
+++ b/src/battle/src/Struct/MapMarker.elm
@@ -0,0 +1,97 @@
+module Struct.MapMarker exposing
+ (
+ Type,
+ new,
+ get_locations,
+ is_in_locations,
+ decoder,
+ encode
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Set
+import Json.Decode
+import Json.Encode
+import List
+
+-- Battle ----------------------------------------------------------------------
+import Struct.Location
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ permissions : (Set.Set String),
+ locations : (Set.Set Struct.Location.Ref)
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+new : Type
+new =
+ {
+ permissions = (Set.empty),
+ locations = (Set.empty)
+ }
+
+get_locations : Type -> (Set.Set Struct.Location.Ref)
+get_locations marker = marker.locations
+
+is_in_locations : Struct.Location.Ref -> Type -> Bool
+is_in_locations loc_ref marker =
+ (Set.member loc_ref marker.locations)
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.map2
+ Type
+ (Json.Decode.field
+ "p"
+ (Json.Decode.map
+ (Set.fromList)
+ (Json.Decode.list (Json.Decode.string))
+ )
+ )
+ (Json.Decode.field
+ "l"
+ (Json.Decode.map
+ (Set.fromList)
+ (Json.Decode.list
+ (Json.Decode.map
+ (Struct.Location.get_ref)
+ (Struct.Location.decoder)
+ )
+ )
+ )
+ )
+ )
+
+encode : Type -> Json.Encode.Value
+encode marker =
+ (Json.Encode.object
+ [
+ (
+ "p",
+ (Json.Encode.list
+ (Json.Encode.string)
+ (Set.toList marker.permissions)
+ )
+ ),
+ (
+ "l",
+ (Json.Encode.list
+ (\e ->
+ (Struct.Location.encode (Struct.Location.from_ref e))
+ )
+ (Set.toList marker.locations)
+ )
+ )
+ ]
+ )
diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm
index e43edde..5fceea5 100644
--- a/src/map-editor/src/Comm/SetMap.elm
+++ b/src/map-editor/src/Comm/SetMap.elm
@@ -17,7 +17,8 @@ type alias MapData =
{
w : Int,
h : Int,
- t : (List (List String))
+ t : (List (List String)),
+ m : (Dict.Dict String (List Struct.Location.Type))
}
--------------------------------------------------------------------------------
diff --git a/src/map-editor/src/Struct/Map.elm b/src/map-editor/src/Struct/Map.elm
index a00bba2..f0f0e5b 100644
--- a/src/map-editor/src/Struct/Map.elm
+++ b/src/map-editor/src/Struct/Map.elm
@@ -25,9 +25,9 @@ import Struct.Location
--------------------------------------------------------------------------------
type alias Type =
{
- width: Int,
- height: Int,
- content: (Array.Array Struct.Tile.Instance)
+ width : Int,
+ height : Int,
+ content : (Array.Array Struct.Tile.Instance)
}
--------------------------------------------------------------------------------