Skip to content

Commit

Permalink
Add conversion for kinds when sending resources to client
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoLR10 committed Jan 25, 2025
1 parent 8cfda8e commit bba1b4d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/apps/server/src/map.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
-export([get_map/2]).
-compile({parse_transform, do}).

-spec atomize(binary()) -> atom().
atomize(Binary) -> list_to_atom(string:lowercase(binary_to_list(Binary))).

-spec transform_tile(map()) -> atom().
transform_tile(Map) ->
list_to_atom(string:lowercase(binary_to_list(maps:get(kind, Map)))).
transform_tile(Map) -> atomize(maps:get(kind, Map)).

-spec transform_object(map()) -> atom().
transform_object(Map) ->
list_to_atom(string:lowercase(binary_to_list(maps:get(kind, Map)))).
transform_object(Map) -> atomize(maps:get(kind, Map)).

-spec transform_resource(map()) -> tuple().
transform_resource(Map) ->
Position = {maps:get(x_position, Map), maps:get(y_position, Map)},
{Position, maps:without([x_position, y_position], Map)}.
NewMap = maps:update_with(kind, fun atomize/1, Map),
{Position, maps:without([x_position, y_position], NewMap)}.

-spec check_dimensions(map()) -> any().
check_dimensions(UnprocessedMap) ->
Expand Down

0 comments on commit bba1b4d

Please sign in to comment.