summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-05-07 17:24:03 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-05-07 17:24:03 +0200 |
commit | 6f4069f682a4f1684fe5cf64c431f019260ce3a5 (patch) | |
tree | d90ab1f25604948a3c8e442d78fe8eaa692ed620 /src/shared | |
parent | 70ae1dba72604469e9f9b528cf451734ac43baf6 (diff) |
Working on markers...
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/reply/shr_set_map.erl | 6 | ||||
-rw-r--r-- | src/shared/struct/map/shr_map_marker.erl | 72 |
2 files changed, 50 insertions, 28 deletions
diff --git a/src/shared/reply/shr_set_map.erl b/src/shared/reply/shr_set_map.erl index f0af1cf..170f73c 100644 --- a/src/shared/reply/shr_set_map.erl +++ b/src/shared/reply/shr_set_map.erl @@ -18,12 +18,12 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec generate ( - ataxia_security:user(), + non_neg_integer(), fun ((shr_tile_instance:trigger_name()) -> boolean()), shr_map:type() ) -> {list(any())}. -generate (User, TriggerVisibilityFun, Map) -> +generate (PlayerIX, TriggerVisibilityFun, Map) -> { [ {<<"msg">>, <<"set_map">>}, @@ -43,7 +43,7 @@ generate (User, TriggerVisibilityFun, Map) -> lists:foldl ( fun ({Key, Value}, Acc) -> - case shr_map_marker:can_access(User, Value) of + case shr_map_marker:player_can_see(PlayerIX, Value) of true -> [{ Key, shr_map_marker:encode(Value) }|Acc]; false -> Acc end diff --git a/src/shared/struct/map/shr_map_marker.erl b/src/shared/struct/map/shr_map_marker.erl index 3899c23..e272dff 100644 --- a/src/shared/struct/map/shr_map_marker.erl +++ b/src/shared/struct/map/shr_map_marker.erl @@ -3,10 +3,29 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + matk_mrk, + { + character_ix :: non_neg_integer() + } +). + +-record +( + spawn_mrk, + { + player_ix :: non_neg_integer() + } +). + -type name() :: binary(). --type type() :: {ataxia_security:permission(), list(shr_location:type())}. +-opaque melee_attack_zone() :: #matk_mrk{}. +-opaque spawn_zone() :: #spawn_mrk{}. +-opaque type() :: + {list(shr_location:type()), (melee_attack_zone() | spawn_zone())}. --export_type([name/0, type/0]). +-export_type([name/0, type/0, melee_attack_zone/0, spawn_zone/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -14,7 +33,7 @@ -export ( [ - can_access/2, + player_can_see/2, get_locations/1 ] ). @@ -34,36 +53,39 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec can_access (ataxia_security:user(), type()) -> boolean(). -can_access (User, {Permission, _Locations}) -> - ataxia_security:can_access(User, Permission). - --spec get_locations (type()) -> boolean(). -get_locations ({_Permission, Locations}) -> - Locations. +-spec get_locations (type()) -> list(shr_location:type()). +get_locations ({L, _}) -> L. -spec encode (type()) -> {list(any())}. -encode ({Permission, Locations}) -> +encode ({L, MarkerData}) when is_record(MarkerData, matk_mrk) -> + { + [ + { <<"t">>, <<"matk">> }, + { <<"cix">>, MarkerData#matk_mrk.character_ix }, + { <<"l">>, lists:map(fun shr_location:encode/1, L) } + ] + }; +encode ({L, MarkerData}) when is_record(MarkerData, spawn_mrk) -> { [ - { - <<"p">>, - ataxia_security:permission_to_json(fun (E) -> E end, Permission) - }, - { <<"l">>, lists:map(fun shr_location:encode/1, Locations) } + { <<"t">>, <<"spawn">> }, + { <<"pix">>, MarkerData#spawn_mrk.player_ix }, + { <<"l">>, lists:map(fun shr_location:encode/1, L) } ] }. -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), - + Data = maps:get(<<"d">>, Map), { - Permission, - Locations + lists:map(fun shr_location:decode/1, maps:get(<<"l">>, Map)), + ( + case maps:get(<<"t">>, Data) of + <<"mtak">> -> #matk_mrk{ character_ix = maps:get(<<"cix">>, Data) }; + <<"spawn">> -> #spawn_mrk{ player_ix = maps:get(<<"pix">>, Data) } + end + ) }. + +-spec player_can_see (integer(), type()) -> boolean(). +player_can_see (IX, _Marker) -> (IX >= 0). |