| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/struct')
| -rw-r--r-- | src/struct/attack.erl | 23 | ||||
| -rw-r--r-- | src/struct/location.erl | 20 | ||||
| -rw-r--r-- | src/struct/turn_result.erl | 55 | 
3 files changed, 49 insertions, 49 deletions
| diff --git a/src/struct/attack.erl b/src/struct/attack.erl index 7b81adc..7f6b302 100644 --- a/src/struct/attack.erl +++ b/src/struct/attack.erl @@ -281,7 +281,7 @@ get_sequence (AttackRange, AttackerWeapon, DefenderWeapon) ->           [First, Counter, Second]     end. --spec encode (struct()) -> binary(). +-spec encode (struct()) -> {list(any())}.  % This shouldn't be a possibility. Types in this module are a mess...  encode (Attack) ->     Order = Attack#attack.order, @@ -290,15 +290,12 @@ encode (Attack) ->     IsParry = Attack#attack.is_parry,     Damage = Attack#attack.damage, -   jiffy:encode -   ( -      { -         [ -            {<<"ord">>, encode_order(Order)}, -            {<<"pre">>, encode_precision(Precision)}, -            {<<"cri">>, IsCritical}, -            {<<"par">>, IsParry}, -            {<<"dmg">>, Damage} -         ] -      } -   ). +   { +      [ +         {<<"ord">>, encode_order(Order)}, +         {<<"pre">>, encode_precision(Precision)}, +         {<<"cri">>, IsCritical}, +         {<<"par">>, IsParry}, +         {<<"dmg">>, Damage} +      ] +   }. 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}). diff --git a/src/struct/turn_result.erl b/src/struct/turn_result.erl index c5cafcd..5f796ca 100644 --- a/src/struct/turn_result.erl +++ b/src/struct/turn_result.erl @@ -96,19 +96,16 @@ new_character_attacked (AttackerIX, DefenderIX, AttackSequence) ->        sequence = AttackSequence     }. --spec encode (struct()) -> binary(). +-spec encode (struct()) -> {list(any())}.  encode (TurnResult) when is_record(TurnResult, switched_weapon) ->     CharacterInstanceIX = TurnResult#switched_weapon.character_instance_ix, -   jiffy:encode -   ( -      { -         [ -            {<<"t">>, <<"swp">>}, -            {<<"ix">>, CharacterInstanceIX} -         ] -      } -   ); +   { +      [ +         {<<"t">>, <<"swp">>}, +         {<<"ix">>, CharacterInstanceIX} +      ] +   };  encode (TurnResult) when is_record(TurnResult, moved) ->     CharacterInstanceIX = TurnResult#moved.character_instance_ix,     Path = TurnResult#moved.path, @@ -117,17 +114,14 @@ encode (TurnResult) when is_record(TurnResult, moved) ->     EncodedPath = lists:map(fun direction:encode/1, Path),     EncodedNewLocation = location:encode(NewLocation), -   jiffy:encode -   ( -      { -         [ -            {<<"t">>, <<"mv">>}, -            {<<"ix">>, CharacterInstanceIX}, -            {<<"p">>, EncodedPath}, -            {<<"nlc">>, EncodedNewLocation} -         ] -      } -   ); +   { +      [ +         {<<"t">>, <<"mv">>}, +         {<<"ix">>, CharacterInstanceIX}, +         {<<"p">>, EncodedPath}, +         {<<"nlc">>, EncodedNewLocation} +      ] +   };  encode (TurnResult) when is_record(TurnResult, attacked) ->     AttackerIX = TurnResult#attacked.attacker_ix,     DefenderIX = TurnResult#attacked.defender_ix, @@ -135,17 +129,14 @@ encode (TurnResult) when is_record(TurnResult, attacked) ->     EncodedSequence = lists:map(fun attack:encode/1, Sequence), -   jiffy:encode -   ( -      { -         [ -            {<<"t">>, <<"atk">>}, -            {<<"aix">>, AttackerIX}, -            {<<"dix">>, DefenderIX}, -            {<<"seq">>, EncodedSequence} -         ] -      } -   ); +   { +      [ +         {<<"t">>, <<"atk">>}, +         {<<"aix">>, AttackerIX}, +         {<<"dix">>, DefenderIX}, +         {<<"seq">>, EncodedSequence} +      ] +   };  encode (Other) ->     io:format("~n invalid encode param\"~p\"~n", [Other]),     true = Other. | 


