summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-03-15 18:41:39 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-03-15 18:41:39 +0100
commit8103bf80277b759bb9c3b1e032612721f132f256 (patch)
treea1b1858483281e61a0dcb9cb42fb6df38214c06a /src/shared/battle-map/BattleMap/Struct/Marker.elm
parent6678cfe464ed9ee595f4f3dd7398dec1416454c9 (diff)
[Broken] Got 'battle' to compile again.
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct/Marker.elm')
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Marker.elm99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm
new file mode 100644
index 0000000..9af3ece
--- /dev/null
+++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm
@@ -0,0 +1,99 @@
+module BattleMap.Struct.Marker exposing
+ (
+ Type,
+ new,
+ get_locations,
+ is_in_locations,
+ decoder,
+ encode
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Set
+import Json.Decode
+import Json.Encode
+import List
+
+-- Battle Map ------------------------------------------------------------------
+import BattleMap.Struct.Location
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ permissions : (Set.Set String),
+ locations : (Set.Set BattleMap.Struct.Location.Ref)
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+new : Type
+new =
+ {
+ permissions = (Set.empty),
+ locations = (Set.empty)
+ }
+
+get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref)
+get_locations marker = marker.locations
+
+is_in_locations : BattleMap.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
+ (BattleMap.Struct.Location.get_ref)
+ (BattleMap.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 ->
+ (BattleMap.Struct.Location.encode
+ (BattleMap.Struct.Location.from_ref e)
+ )
+ )
+ (Set.toList marker.locations)
+ )
+ )
+ ]
+ )