| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2019-02-18 18:37:29 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2019-02-18 18:37:29 +0100 | 
| commit | d12d6328f1001552ad8ce0f44bc1271eeb94ddbb (patch) | |
| tree | 2677987135f0a38f28fd075d9234f07c8611f497 /src/shared | |
| parent | 1e3ed11d30c5c6639de10caca2eea898e506e4cf (diff) | |
...
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/struct/map/shr_map.erl | 15 | ||||
| -rw-r--r-- | src/shared/struct/map/shr_map_marker.erl | 55 | 
2 files changed, 45 insertions, 25 deletions
| diff --git a/src/shared/struct/map/shr_map.erl b/src/shared/struct/map/shr_map.erl index 227c06b..97f778b 100644 --- a/src/shared/struct/map/shr_map.erl +++ b/src/shared/struct/map/shr_map.erl @@ -13,7 +13,7 @@        width :: non_neg_integer(),        height :: non_neg_integer(),        tile_instances :: shr_array_tuple:array_tuple(shr_tile_instance:type()), -      markers :: shr_map_marker:collection() +      markers :: orddict:orddict(shr_map_marker:name(), shr_map_marker:type())     }  ). @@ -107,7 +107,10 @@ get_tile_instance (Location, Map) ->     TileIX = location_to_index(Map#map.width, Location),     element((TileIX + 1), Map#map.tile_instances). --spec get_markers (type()) -> shr_map_marker:collection(). +-spec get_markers +   ( +      type() +   ) -> orddict:orddict(shr_map_marker:name(), shr_map_marker:type()).  get_markers (Map) -> Map#map.markers.  -spec get_marker @@ -115,9 +118,9 @@ get_markers (Map) -> Map#map.markers.        shr_map_marker:name(),        type()     ) -   -> ('not_found' | {'ok', shr_map_marker:type()}). +   -> ('error' | {'ok', shr_map_marker:type()}).  get_marker (Name, Map) -> -   shr_map_marker:get(Name, Map#map.markers). +   orddict:find(Name, Map#map.markers).  %%%% Fields  -spec get_width_field () -> non_neg_integer(). @@ -156,7 +159,7 @@ get_used_tile_ids (Map) ->        type(),        non_neg_integer(),        non_neg_integer(), -      shr_map_marker:collection(), +      orddict:orddict(shr_map_marker:name(), shr_map_marker:type()),        list(map())     )     -> type(). @@ -180,6 +183,6 @@ default (Owner) ->        owner = Owner,        width = 32,        height = 32, -      markers = shr_map_marker:empty_collection(), +      markers = orddict:new(),        tile_instances = list_to_tuple(lists:duplicate(1024, DefaultTileInstance))     }. diff --git a/src/shared/struct/map/shr_map_marker.erl b/src/shared/struct/map/shr_map_marker.erl index 35ba195..3899c23 100644 --- a/src/shared/struct/map/shr_map_marker.erl +++ b/src/shared/struct/map/shr_map_marker.erl @@ -4,10 +4,9 @@  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type name() :: binary(). --type type() :: 'none'. --type collection() :: orddict:orddict(name(), type()). +-type type() :: {ataxia_security:permission(), list(shr_location:type())}. --export_type([name/0, type/0, collection/0]). +-export_type([name/0, type/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -15,16 +14,16 @@  -export  (     [ -      get/2, -      empty_collection/0 +      can_access/2, +      get_locations/1     ]  ).  -export  (     [ -      decode_collection/1, -      encode_collection/1 +      decode/1, +      encode/1     ]  ). @@ -35,18 +34,36 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get (name(), collection()) -> ('not_found' | {'ok', type()}). -get (Name, Collection) -> -   case orddict:find(Name, Collection) of -      error -> not_found; -      Other -> Other -   end. +-spec can_access (ataxia_security:user(), type()) -> boolean(). +can_access (User, {Permission, _Locations}) -> +   ataxia_security:can_access(User, Permission). --spec empty_collection () -> collection(). -empty_collection () -> orddict:new(). +-spec get_locations (type()) -> boolean(). +get_locations ({_Permission, Locations}) -> +   Locations. --spec encode_collection (collection()) -> list(any()). -encode_collection (_Collection) -> []. +-spec encode (type()) -> {list(any())}. +encode ({Permission, Locations}) -> +   { +      [ +         { +            <<"p">>, +            ataxia_security:permission_to_json(fun (E) -> E end, Permission) +         }, +         { <<"l">>, lists:map(fun shr_location:encode/1, Locations) } +      ] +   }. --spec decode_collection (map()) -> collection(). -decode_collection (_Map) -> orddict:new(). +-spec decode (map()) -> type(). +decode (Map) -> +   EncodedPermission = maps:get("p", Map), +   EncodedLocations = maps:get("l", Map), + +   Permission = +      ataxia_security:permission_from_json(fun (E) -> E end, EncodedPermission), +   Locations = lists:map(fun shr_location:decode/1, EncodedLocations), + +   { +      Permission, +      Locations +   }. | 


