summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-05-07 17:24:03 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-05-07 17:24:03 +0200
commit6f4069f682a4f1684fe5cf64c431f019260ce3a5 (patch)
treed90ab1f25604948a3c8e442d78fe8eaa692ed620 /src/shared/struct/map
parent70ae1dba72604469e9f9b528cf451734ac43baf6 (diff)
Working on markers...
Diffstat (limited to 'src/shared/struct/map')
-rw-r--r--src/shared/struct/map/shr_map_marker.erl72
1 files changed, 47 insertions, 25 deletions
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).