summaryrefslogtreecommitdiff |
diff options
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 + }. |