| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-02-15 22:29:05 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-02-15 22:29:05 +0100 | 
| commit | 1e3ed11d30c5c6639de10caca2eea898e506e4cf (patch) | |
| tree | 4bd676ed07ca71c46506b1fc3c1b54a9847e3466 /src/shared | |
| parent | 11ba787cd7a9bbcd0dff71176285337375313409 (diff) | |
Markers/triggers, shr_tile -> shr_tile{,_instance}
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/reply/shr_set_map.erl | 15 | ||||
| -rw-r--r-- | src/shared/struct/map/shr_map.erl | 17 | ||||
| -rw-r--r-- | src/shared/struct/map/shr_tile.erl.m4 | 2 | ||||
| -rw-r--r-- | src/shared/struct/map/shr_tile_instance.erl | 29 | ||||
| -rw-r--r-- | src/shared/util/shr_array_tuple.erl | 4 | 
5 files changed, 44 insertions, 23 deletions
| diff --git a/src/shared/reply/shr_set_map.erl b/src/shared/reply/shr_set_map.erl index b335302..0096b52 100644 --- a/src/shared/reply/shr_set_map.erl +++ b/src/shared/reply/shr_set_map.erl @@ -7,7 +7,7 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). +-export([generate/2]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -16,8 +16,13 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (shr_map:type()) -> {list(any())}. -generate (Map) -> +-spec generate +   ( +      fun ((shr_tile_instance:trigger_name()) -> boolean()), +      shr_map:type() +   ) +   -> {list(any())}. +generate (TriggerVisibilityFun, Map) ->     {        [           {<<"msg">>, <<"set_map">>}, @@ -27,7 +32,9 @@ generate (Map) ->              <<"t">>,              lists:map              ( -               fun shr_tile:instance_to_binary_list/1, +               fun (E) -> +                  shr_tile_instance:encode(TriggerVisibilityFun, E) +               end,                 tuple_to_list(shr_map:get_tile_instances(Map))              )           } diff --git a/src/shared/struct/map/shr_map.erl b/src/shared/struct/map/shr_map.erl index c9f01b4..227c06b 100644 --- a/src/shared/struct/map/shr_map.erl +++ b/src/shared/struct/map/shr_map.erl @@ -97,7 +97,12 @@ get_height (Map) -> Map#map.height.     -> shr_array_tuple:array_tuple(shr_tile_instance:type()).  get_tile_instances (Map) -> Map#map.tile_instances. --spec get_tile_instance (shr_location:type(), type()) -> shr_tile:instance(). +-spec get_tile_instance +   ( +      shr_location:type(), +      type() +   ) +   -> shr_tile_instance:type().  get_tile_instance (Location, Map) ->     TileIX = location_to_index(Map#map.width, Location),     element((TileIX + 1), Map#map.tile_instances). @@ -128,7 +133,7 @@ get_markers_field () -> #map.markers.  get_tile_instances_field () -> #map.tile_instances.  %%%% Utility --spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:class_id()). +-spec get_used_tile_ids (type()) -> ordsets:ordset(shr_tile:id()).  get_used_tile_ids (Map) ->     UsedTileIDs =        lists:foldl @@ -136,7 +141,7 @@ get_used_tile_ids (Map) ->           fun (TileInstance, CurrentTileIDs) ->              ordsets:add_element              ( -               shr_tile:extract_main_class_id(TileInstance), +               shr_tile_instance:get_tile_id(TileInstance),                 CurrentTileIDs              )           end, @@ -152,11 +157,11 @@ get_used_tile_ids (Map) ->        non_neg_integer(),        non_neg_integer(),        shr_map_marker:collection(), -      list(list(binary())) +      list(map())     )     -> type().  update_from_list (Map, Width, Height, Markers, List) -> -   TileInstances = lists:map(fun shr_tile:instance_from_binary_list/1, List), +   TileInstances = lists:map(fun shr_tile_instance:decode/1, List),     Map#map     { @@ -168,7 +173,7 @@ update_from_list (Map, Width, Height, Markers, List) ->  -spec default (binary()) -> type().  default (Owner) -> -   DefaultTileInstance = shr_tile:default_tile_instance(), +   DefaultTileInstance = shr_tile_instance:default(),     #map     { diff --git a/src/shared/struct/map/shr_tile.erl.m4 b/src/shared/struct/map/shr_tile.erl.m4 index 5bd8acd..26f9645 100644 --- a/src/shared/struct/map/shr_tile.erl.m4 +++ b/src/shared/struct/map/shr_tile.erl.m4 @@ -57,7 +57,7 @@ from_id(_) ->  -spec cost_when_oob () -> non_neg_integer().  cost_when_oob () -> __TILE_COST_WHEN_OOB. --spec get_id (type()) -> class_id(). +-spec get_id (type()) -> id().  get_id (Tile) -> Tile#tile.id.  -spec get_cost (type()) -> non_neg_integer(). diff --git a/src/shared/struct/map/shr_tile_instance.erl b/src/shared/struct/map/shr_tile_instance.erl index 6696f35..9f95378 100644 --- a/src/shared/struct/map/shr_tile_instance.erl +++ b/src/shared/struct/map/shr_tile_instance.erl @@ -4,23 +4,24 @@  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -type display_data() :: list(binary()). +-type trigger_name() :: binary().  -opaque type() ::     {        shr_tile:id(),        shr_tile:variant_id(),        display_data(), -      list(shr_map_trigger:id()) +      list(trigger_name())     }. --export_type([type/0, border/0]). +-export_type([type/0, trigger_name/0]).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -export  (     [ -      encode/1, +      encode/2,        decode/1,        default/0,        error/0 @@ -48,11 +49,10 @@ get_tile_id ({TileID, _, _, _}) -> TileID.  -spec get_variant_id (type()) -> shr_tile:variant_id().  get_variant_id ({_, VariantID, _, _}) -> VariantID. --spec decode (list(binary())) -> type(). +-spec decode (map()) -> type().  decode (Map) ->     L = maps:get(<<"b">>, Map), -   T = maps:get(<<"t">>, Map), - +   Triggers = maps:get(<<"t">>, Map),     [TileID|[VariantID|DisplayData]] = L, @@ -62,10 +62,19 @@ decode (Map) ->           _ -> []        end, -   {TileID, VariantID, S0DisplayData, T}. +   {TileID, VariantID, S0DisplayData, Triggers}. --spec encode (instance()) -> list(binary()). -encode (I) -> I. +-spec encode (fun ((trigger_name()) -> boolean()), type()) -> {list(any())}. +encode (VisibilityFun, {TileID, VariantID, DisplayData, Triggers}) -> +   { +      [ +         {<<"b">>, [TileID|[VariantID|DisplayData]]}, +         {<<"t">>, lists:filter(VisibilityFun, Triggers)} +      ] +   }.  -spec default () -> type(). -default () -> [<<"1">>, <<"0">>]. +default () -> {<<"1">>, <<"0">>, [], []}. + +-spec error () -> type(). +error () -> {<<"0">>, <<"0">>, [], []}. diff --git a/src/shared/util/shr_array_tuple.erl b/src/shared/util/shr_array_tuple.erl index 3effb4c..0ca9ffa 100644 --- a/src/shared/util/shr_array_tuple.erl +++ b/src/shared/util/shr_array_tuple.erl @@ -1,8 +1,8 @@  -module(shr_array_tuple).  % My solution to https://stackoverflow.com/questions/53877197/are-there-erlang-arrays-with-a-defined-representation --opaque array_tuple() :: tuple(). --opaque array_tuple(_Type) :: tuple(). +-type array_tuple() :: tuple(). +-type array_tuple(_Type) :: tuple().  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 


