From 8103bf80277b759bb9c3b1e032612721f132f256 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Fri, 15 Mar 2019 18:41:39 +0100 Subject: [Broken] Got 'battle' to compile again. --- src/shared/battle-map/BattleMap/Struct/Marker.elm | 99 +++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/shared/battle-map/BattleMap/Struct/Marker.elm (limited to 'src/shared/battle-map/BattleMap/Struct/Marker.elm') 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) + ) + ) + ] + ) -- cgit v1.2.3-70-g09d2