summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/struct/map/shr_map.erl | 8 | ||||
-rw-r--r-- | src/shared/struct/map/shr_tile.erl.m4 | 83 | ||||
-rw-r--r-- | src/shared/struct/map/shr_tile_instance.erl | 71 | ||||
-rw-r--r-- | src/shared/util/shr_array_tuple.erl | 22 |
4 files changed, 109 insertions, 75 deletions
diff --git a/src/shared/struct/map/shr_map.erl b/src/shared/struct/map/shr_map.erl index b72c566..c9f01b4 100644 --- a/src/shared/struct/map/shr_map.erl +++ b/src/shared/struct/map/shr_map.erl @@ -12,7 +12,7 @@ owner :: shr_player:id(), width :: non_neg_integer(), height :: non_neg_integer(), - tile_instances :: shr_tile:instances_tuple(), + tile_instances :: shr_array_tuple:array_tuple(shr_tile_instance:type()), markers :: shr_map_marker:collection() } ). @@ -90,7 +90,11 @@ get_width (Map) -> Map#map.width. -spec get_height (type()) -> non_neg_integer(). get_height (Map) -> Map#map.height. --spec get_tile_instances (type()) -> shr_tile:instances_tuple(). +-spec get_tile_instances + ( + type() + ) + -> 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(). diff --git a/src/shared/struct/map/shr_tile.erl.m4 b/src/shared/struct/map/shr_tile.erl.m4 index 7876f8f..5bd8acd 100644 --- a/src/shared/struct/map/shr_tile.erl.m4 +++ b/src/shared/struct/map/shr_tile.erl.m4 @@ -3,15 +3,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type class_id() :: binary(). +-type id() :: binary(). -type variant_id() :: binary(). --type instances_tuple() :: tuple(). -record ( tile, { - id :: class_id(), + id :: id(), name :: binary(), cost :: non_neg_integer(), omnimods :: shr_omnimods:type(), @@ -20,54 +19,24 @@ } ). --opaque instance() :: list(binary()). --opaque border() :: list(binary()). - -opaque type() :: #tile{}. --export_type([type/0, class_id/0, variant_id/0, instance/0, border/0]). --export_type([instances_tuple/0]). +-export_type([type/0, id/0, variant_id/0]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -export ( [ - get_class_id/1, + get_id/1, get_name/1, get_cost/1, get_omnimods/1, - from_class_id/1, + from_id/1, cost_when_oob/0 ] ). --export -( - [ - instance_to_binary_list/1, - instance_from_binary_list/1, - default_tile_instance/0 - ] -). - --export -( - [ - extract_main_class_id/1, - extract_variant_id/1, - extract_borders/1 - ] -). - --export -( - [ - extract_border_main_class_id/1, - extract_border_variant_id/1 - ] -). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -76,37 +45,20 @@ %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec extract_main_class_id (instance()) -> class_id(). -extract_main_class_id (I) -> lists:nth(1, I). - --spec extract_borders (instance()) -> list(border()). -extract_borders (I) -> - [_|[_|Result]] = I, - Result. - --spec extract_variant_id (instance()) -> variant_id(). -extract_variant_id (I) -> lists:nth(2, I). - --spec extract_border_main_class_id (border()) -> class_id(). -extract_border_main_class_id (B) -> lists:nth(1, B). - --spec extract_border_variant_id (border()) -> variant_id(). -extract_border_variant_id (B) -> lists:nth(2, B). - --spec from_class_id (class_id()) -> type(). +-spec from_id (id()) -> type(). m4_include(__MAKEFILE_DATA_DIR/tile/global.m4.conf)m4_dnl m4_include(__MAKEFILE_DATA_DIR/tile/special.m4d)m4_dnl m4_include(__MAKEFILE_DATA_DIR/tile/grassland.m4d)m4_dnl m4_include(__MAKEFILE_DATA_DIR/tile/mud.m4d)m4_dnl m4_include(__MAKEFILE_DATA_DIR/tile/water.m4d)m4_dnl -from_class_id(_) -> - from_class_id(<<"0">>). +from_id(_) -> + from_id(<<"0">>). -spec cost_when_oob () -> non_neg_integer(). cost_when_oob () -> __TILE_COST_WHEN_OOB. --spec get_class_id (type()) -> class_id(). -get_class_id (Tile) -> Tile#tile.id. +-spec get_id (type()) -> class_id(). +get_id (Tile) -> Tile#tile.id. -spec get_cost (type()) -> non_neg_integer(). get_cost (Tile) -> Tile#tile.cost. @@ -116,18 +68,3 @@ get_name (Tile) -> Tile#tile.name. -spec get_omnimods (type()) -> shr_omnimods:type(). get_omnimods (Tile) -> Tile#tile.omnimods. - --spec instance_from_binary_list (list(binary())) -> instance(). -instance_from_binary_list (L) -> - LLength = length(L), - - case (((LLength rem 2) == 0) and (LLength /= 0)) of - true -> L; - _ -> [<<"0">>, <<"0">>] - end. - --spec instance_to_binary_list (instance()) -> list(binary()). -instance_to_binary_list (I) -> I. - --spec default_tile_instance () -> instance(). -default_tile_instance () -> [<<"1">>, <<"0">>]. diff --git a/src/shared/struct/map/shr_tile_instance.erl b/src/shared/struct/map/shr_tile_instance.erl new file mode 100644 index 0000000..6696f35 --- /dev/null +++ b/src/shared/struct/map/shr_tile_instance.erl @@ -0,0 +1,71 @@ +-module(shr_tile_instance). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-type display_data() :: list(binary()). + +-opaque type() :: + { + shr_tile:id(), + shr_tile:variant_id(), + display_data(), + list(shr_map_trigger:id()) + }. + +-export_type([type/0, border/0]). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( + [ + encode/1, + decode/1, + default/0, + error/0 + ] +). + +-export +( + [ + get_tile_id/1, + get_variant_id/1 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec get_tile_id (type()) -> shr_tile:id(). +get_tile_id ({TileID, _, _, _}) -> TileID. + +-spec get_variant_id (type()) -> shr_tile:variant_id(). +get_variant_id ({_, VariantID, _, _}) -> VariantID. + +-spec decode (list(binary())) -> type(). +decode (Map) -> + L = maps:get(<<"b">>, Map), + T = maps:get(<<"t">>, Map), + + + [TileID|[VariantID|DisplayData]] = L, + + S0DisplayData = + case (((length(DisplayData) rem 2) == 0)) of + true -> DisplayData; + _ -> [] + end, + + {TileID, VariantID, S0DisplayData, T}. + +-spec encode (instance()) -> list(binary()). +encode (I) -> I. + +-spec default () -> type(). +default () -> [<<"1">>, <<"0">>]. diff --git a/src/shared/util/shr_array_tuple.erl b/src/shared/util/shr_array_tuple.erl new file mode 100644 index 0000000..3effb4c --- /dev/null +++ b/src/shared/util/shr_array_tuple.erl @@ -0,0 +1,22 @@ +-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(). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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