summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/reply')
-rw-r--r-- | src/reply/add_char.erl | 76 | ||||
-rw-r--r-- | src/reply/set_map.erl | 23 |
2 files changed, 41 insertions, 58 deletions
diff --git a/src/reply/add_char.erl b/src/reply/add_char.erl index a920a2a..b3ef128 100644 --- a/src/reply/add_char.erl +++ b/src/reply/add_char.erl @@ -29,58 +29,46 @@ attributes_as_json (Attributes) -> ] }. --spec encode +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec generate ( non_neg_integer(), character_instance:struct(), player:id() ) - -> binary(). -encode (IX, CharacterInstance, PlayerID) -> + -> {list(any())}. +generate (IX, CharacterInstance, PlayerID) -> Character = character_instance:get_character(CharacterInstance), Location = character_instance:get_location(CharacterInstance), Attributes = character:get_attributes(Character), {ActiveWeapon, SecondaryWeapon} = character:get_weapon_ids(Character), OwnerID = character:get_owner_id(Character), - jiffy:encode - ( - { - [ - {<<"ix">>, IX}, - {<<"nam">>, character:get_name(Character)}, - {<<"ico">>, character:get_icon(Character)}, - {<<"prt">>, character:get_portrait(Character)}, - { - <<"hea">>, - character_instance:get_current_health(CharacterInstance) - }, - {<<"lc">>, location:encode(Location)}, - {<<"pla">>, OwnerID}, - { - <<"ena">>, - ( - character_instance:get_is_active(CharacterInstance) - and - (OwnerID == PlayerID) - ) - }, - {<<"att">>, attributes_as_json(Attributes)}, - {<<"awp">>, ActiveWeapon}, - {<<"swp">>, SecondaryWeapon} - ] - } - ). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate - ( - non_neg_integer(), - character_instance:struct(), - player:id() - ) - -> list(binary()). -generate (IX, CharacterInstance, PlayerID) -> - [<<"add_char">>, encode(IX, CharacterInstance, PlayerID)]. + { + [ + {<<"msg">>, <<"add_char">>}, + {<<"ix">>, IX}, + {<<"nam">>, character:get_name(Character)}, + {<<"ico">>, character:get_icon(Character)}, + {<<"prt">>, character:get_portrait(Character)}, + { + <<"hea">>, + character_instance:get_current_health(CharacterInstance) + }, + {<<"lc">>, location:encode(Location)}, + {<<"pla">>, OwnerID}, + { + <<"ena">>, + ( + character_instance:get_is_active(CharacterInstance) + and + (OwnerID == PlayerID) + ) + }, + {<<"att">>, attributes_as_json(Attributes)}, + {<<"awp">>, ActiveWeapon}, + {<<"swp">>, SecondaryWeapon} + ] + }. diff --git a/src/reply/set_map.erl b/src/reply/set_map.erl index 0941239..6a7cd39 100644 --- a/src/reply/set_map.erl +++ b/src/reply/set_map.erl @@ -12,22 +12,17 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec encode (battlemap:struct()) -> binary(). -encode (Battlemap) -> - jiffy:encode - ( - { - [ - {<<"w">>, battlemap:get_width(Battlemap)}, - {<<"h">>, battlemap:get_height(Battlemap)}, - {<<"t">>, array:sparse_to_list(battlemap:get_tile_ids(Battlemap))} - ] - } - ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec generate (battlemap:struct()) -> list(binary()). +-spec generate (battlemap:struct()) -> {list(any())}. generate (Battlemap) -> - [<<"set_map">>, encode(Battlemap)]. + { + [ + {<<"msg">>, <<"set_map">>}, + {<<"w">>, battlemap:get_width(Battlemap)}, + {<<"h">>, battlemap:get_height(Battlemap)}, + {<<"t">>, array:sparse_to_list(battlemap:get_tile_ids(Battlemap))} + ] + }. |