summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/shared/battle-map/BattleMap/Struct/Marker.elm')
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/Marker.elm | 99 |
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) + ) + ) + ] + ) |