summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-02-15 22:29:05 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-02-15 22:29:05 +0100
commit1e3ed11d30c5c6639de10caca2eea898e506e4cf (patch)
tree4bd676ed07ca71c46506b1fc3c1b54a9847e3466 /src/shared/struct/map
parent11ba787cd7a9bbcd0dff71176285337375313409 (diff)
Markers/triggers, shr_tile -> shr_tile{,_instance}
Diffstat (limited to 'src/shared/struct/map')
-rw-r--r--src/shared/struct/map/shr_map.erl17
-rw-r--r--src/shared/struct/map/shr_tile.erl.m42
-rw-r--r--src/shared/struct/map/shr_tile_instance.erl29
3 files changed, 31 insertions, 17 deletions
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">>, [], []}.