| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-03-06 17:08:00 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-03-06 17:08:00 +0100 | 
| commit | 98203d4d0034dab5db72737bcfb92017a11f3245 (patch) | |
| tree | 9c4fd2a8904468d7ee69d86e39ce27051cc8ca2d /src/struct/location.erl | |
| parent | e5bc1b2d1bfcf5f36bd4f0d567e4ec8e0fb22e85 (diff) | |
I might have been using JSON the wrong way.refactoring
Diffstat (limited to 'src/struct/location.erl')
| -rw-r--r-- | src/struct/location.erl | 20 | 
1 files changed, 16 insertions, 4 deletions
| diff --git a/src/struct/location.erl b/src/struct/location.erl index 0d5367d..b8e2bf3 100644 --- a/src/struct/location.erl +++ b/src/struct/location.erl @@ -52,8 +52,20 @@ apply_direction (down, {X, Y}) ->  dist ({OX, OY}, {DX, DY}) ->     (abs(DY - OY) + abs(DX - OX)). --spec encode (type()) -> list(non_neg_integer()). -encode ({X, Y}) -> [X, Y]. +-spec encode (type()) -> {list(any())}. +encode ({X, Y}) -> +   { +      [ +         {<<"x">>, X}, +         {<<"y">>, Y} +      ] +   }. --spec decode (list(non_neg_integer())) -> type(). -decode ([X, Y]) when (is_integer(X) and is_integer(Y)) -> validate({X, Y}). +-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}). | 


