summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/query/map_load.erl | 4 | ||||
-rw-r--r-- | src/map/query/map_update.erl | 12 | ||||
-rw-r--r-- | src/map/reply/map_add_tile.erl | 28 | ||||
-rw-r--r-- | src/map/reply/map_set_map.erl | 35 | ||||
-rw-r--r-- | src/map/struct/map_direction.erl | 38 | ||||
-rw-r--r-- | src/map/struct/map_location.erl | 90 | ||||
-rw-r--r-- | src/map/struct/map_map.erl | 150 |
7 files changed, 8 insertions, 349 deletions
diff --git a/src/map/query/map_load.erl b/src/map/query/map_load.erl index dde2fab..b8126dd 100644 --- a/src/map/query/map_load.erl +++ b/src/map/query/map_load.erl @@ -17,7 +17,7 @@ ( query_state, { - map :: map_map:type() + map :: shr_map:type() } ). @@ -80,7 +80,7 @@ fetch_data (Input) -> generate_reply (QueryState) -> Map = QueryState#query_state.map, - SetMap = map_set_map:generate(Map), + SetMap = shr_set_map:generate(Map), Output = jiffy:encode([SetMap]), Output. diff --git a/src/map/query/map_update.erl b/src/map/query/map_update.erl index b6e36c2..5cb9e42 100644 --- a/src/map/query/map_update.erl +++ b/src/map/query/map_update.erl @@ -20,7 +20,7 @@ ( query_state, { - map :: map_map:type() + map :: shr_map:type() } ). @@ -104,7 +104,7 @@ update_data (QueryState, Input) -> QueryState#query_state { map = - map_map:update_from_list + shr_map:update_from_list ( QueryState#query_state.map, Input#input.w, @@ -131,18 +131,18 @@ commit_update (QueryState, Input) -> [ ataxic:update_field ( - map_map:get_height_field(), + shr_map:get_height_field(), ataxic:constant(Input#input.h) ), ataxic:update_field ( - map_map:get_width_field(), + shr_map:get_width_field(), ataxic:constant(Input#input.w) ), ataxic:update_field ( - map_map:get_tile_instances_field(), - ataxic:constant(map_map:get_tile_instances(Map)) + shr_map:get_tile_instances_field(), + ataxic:constant(shr_map:get_tile_instances(Map)) ) ] ) diff --git a/src/map/reply/map_add_tile.erl b/src/map/reply/map_add_tile.erl deleted file mode 100644 index d5f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%%%%%% --spec generate (shr_tile:type()) -> {list(any())}. -generate (Tile) -> - { - [ - {<<"msg">>, <<"add_tile">>}, - {<<"id">>, shr_tile:get_class_id(Tile)}, - {<<"nam">>, shr_tile:get_name(Tile)}, - {<<"ct">>, shr_tile:get_cost(Tile)} - ] - }. diff --git a/src/map/reply/map_set_map.erl b/src/map/reply/map_set_map.erl deleted file mode 100644 index 67675fe..0000000 --- a/src/map/reply/map_set_map.erl +++ /dev/null @@ -1,35 +0,0 @@ --module(map_set_map). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export([generate/1]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (map_map:type()) -> {list(any())}. -generate (Map) -> - { - [ - {<<"msg">>, <<"set_map">>}, - {<<"w">>, map_map:get_width(Map)}, - {<<"h">>, map_map:get_height(Map)}, - { - <<"t">>, - lists:map - ( - fun shr_tile:instance_to_binary_list/1, - tuple_to_list(map_map:get_tile_instances(Map)) - ) - } - ] - }. diff --git a/src/map/struct/map_direction.erl b/src/map/struct/map_direction.erl deleted file mode 100644 index bd61b7d..0000000 --- a/src/map/struct/map_direction.erl +++ /dev/null @@ -1,38 +0,0 @@ --module(map_direction). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type enum() :: ('up' | 'down' | 'left' | 'right'). --type type() :: enum(). - --export_type([enum/0, type/0]). -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - decode/1, - encode/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec decode (binary()) -> enum(). -decode (<<"U">>) -> up; -decode (<<"D">>) -> down; -decode (<<"L">>) -> left; -decode (<<"R">>) -> right. - --spec encode (enum()) -> binary(). -encode (up) -> <<"U">>; -encode (down) -> <<"D">>; -encode (left) -> <<"L">>; -encode (right) -> <<"R">>. diff --git a/src/map/struct/map_location.erl b/src/map/struct/map_location.erl deleted file mode 100644 index edfb85a..0000000 --- a/src/map/struct/map_location.erl +++ /dev/null @@ -1,90 +0,0 @@ --module(map_location). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type type() :: ({non_neg_integer(), non_neg_integer()} | 'nowhere'). - --export_type([type/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --export -( - [ - decode/1, - encode/1, - get_nowhere/0 - ] -). - --export -( - [ - apply_direction/2, - dist/2 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec validate ({integer(), integer()}) -> type(). -validate ({X, Y}) -> - if - (X < 0) -> nowhere; - (Y < 0) -> nowhere; - true -> {X, Y} - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec get_nowhere () -> type(). -get_nowhere () -> nowhere. - --spec apply_direction (map_direction:enum(), type()) -> type(). -apply_direction (left, {X, Y}) -> - validate({(X - 1), Y}); -apply_direction (right, {X, Y}) -> - validate({(X + 1), Y}); -apply_direction (up, {X, Y}) -> - validate({X, (Y - 1)}); -apply_direction (down, {X, Y}) -> - validate({X, (Y + 1)}); -apply_direction (_, nowhere) -> - error("Trying to move from 'nowhere'."), - nowhere. - --spec dist(type(), type()) -> non_neg_integer(). -dist ({OX, OY}, {DX, DY}) -> - (abs(DY - OY) + abs(DX - OX)); -dist (_, _) -> - error("Trying to measure distance to 'nowhere'"), - 999. - --spec encode (type()) -> {list(any())}. -encode ({X, Y}) -> - { - [ - {<<"x">>, X}, - {<<"y">>, Y} - ] - }; -encode (nowhere) -> - { - [ - {<<"x">>, -1}, - {<<"y">>, -1} - ] - }. - --spec decode (map()) -> type(). -decode (Map) -> - X = maps:get(<<"x">>, Map), - Y = maps:get(<<"y">>, Map), - - true = (is_integer(X) and is_integer(Y)), - - validate({X, Y}). diff --git a/src/map/struct/map_map.erl b/src/map/struct/map_map.erl deleted file mode 100644 index b8d37c9..0000000 --- a/src/map/struct/map_map.erl +++ /dev/null @@ -1,150 +0,0 @@ --module(map_map). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type id() :: ataxia_id:type(). - --record -( - map, - { - owner :: binary(), - width :: integer(), - height :: integer(), - tile_instances :: shr_tile:instances_tuple() - } -). - --opaque type() :: #map{}. - --export_type([type/0, id/0]). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( - [ - get_owner/1, - get_width/1, - get_height/1, - get_tile_instances/1, - get_tile_instance/2 - ] -). - --export -( - [ - get_width_field/0, - get_height_field/0, - get_tile_instances_field/0 - ] -). - --export -( - [ - from_list/4, - update_from_list/4, - default/1 - ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec location_to_index - ( - non_neg_integer(), - map_location:type() - ) - -> ('error' | non_neg_integer()). -location_to_index (ArrayWidth, {X, Y}) -> - if - (X < 0) -> error; - (Y < 0) -> error; - (X >= ArrayWidth) -> error; - true -> ((Y * ArrayWidth) + X) - end. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --spec get_owner (type()) -> binary(). -get_owner (Map) -> Map#map.owner. - --spec get_width (type()) -> integer(). -get_width (Map) -> Map#map.width. - --spec get_height (type()) -> integer(). -get_height (Map) -> Map#map.height. - --spec get_tile_instances (type()) -> shr_tile:instances_tuple(). -get_tile_instances (Map) -> Map#map.tile_instances. - --spec get_tile_instance (map_location:type(), type()) -> shr_tile:instance(). -get_tile_instance (Location, Map) -> - TileIX = location_to_index(Map#map.width, Location), - element((TileIX + 1), Map#map.tile_instances). - --spec get_width_field () -> non_neg_integer(). -get_width_field () -> #map.width. - --spec get_height_field () -> non_neg_integer(). -get_height_field () -> #map.height. - --spec get_tile_instances_field () -> non_neg_integer(). -get_tile_instances_field () -> #map.tile_instances. - --spec from_list - ( - binary(), - non_neg_integer(), - non_neg_integer(), - list(list(binary())) - ) - -> type(). -from_list (Owner, Width, Height, List) -> - TileInstances = lists:map(fun shr_tile:instance_from_binary_list/1, List), - - #map - { - owner = Owner, - width = Width, - height = Height, - tile_instances = list_to_tuple(TileInstances) - }. - --spec update_from_list - ( - type(), - non_neg_integer(), - non_neg_integer(), - list(list(binary())) - ) - -> type(). -update_from_list (Map, Width, Height, List) -> - TileInstances = lists:map(fun shr_tile:instance_from_binary_list/1, List), - - Map#map - { - width = Width, - height = Height, - tile_instances = list_to_tuple(TileInstances) - }. - --spec default (binary()) -> type(). -default (Owner) -> - DefaultTileInstance = shr_tile:default_tile_instance(), - - #map - { - owner = Owner, - width = 32, - height = 32, - tile_instances = list_to_tuple(lists:duplicate(1024, DefaultTileInstance)) - }. |