From 7ad856639b0d8470728d4e5436c3b1152959fd99 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Fri, 19 Apr 2019 19:00:57 +0200 Subject: [Broken] ... --- src/shared/struct/inventory/shr_equipment.erl | 17 ++++++++++++- src/shared/struct/inventory/shr_inventory.erl | 36 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) (limited to 'src/shared/struct/inventory') diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl index e505d91..11dc19e 100644 --- a/src/shared/struct/inventory/shr_equipment.erl +++ b/src/shared/struct/inventory/shr_equipment.erl @@ -91,8 +91,23 @@ ( [ default/0, - default_unresolved/0, + default_unresolved/0 + ] +). +-export +( + [ + resolve/1, + to_unresolved/1, + encode/1, + decode/1 + ] +). + +-export +( + [ get_primary_weapon_field/0, get_secondary_weapon_field/0, get_armor_field/0, diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl index 4f64f68..4ea3e7b 100644 --- a/src/shared/struct/inventory/shr_inventory.erl +++ b/src/shared/struct/inventory/shr_inventory.erl @@ -1,5 +1,11 @@ -module(shr_inventory). +-define(WEAPONS_FIELD, <<"wp">>). +-define(ARMORS_FIELD, <<"ar">>). +-define(PORTRAITS_FIELD, <<"pt">>). +-define(GLYPH_BOARDS_FIELD, <<"gb">>). +-define(GLYPHS_FIELD, <<"gl">>). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -47,6 +53,14 @@ ). %%%% Accessors +-export +( + [ + encode/1, + decode/1 + ] +). + -export ( [ @@ -373,6 +387,28 @@ ataxia_add_equipment (Eq, Inv) -> ) }. +-spec decode (map()) -> type(). +decode (Map) -> + #inventory + { + weapons = ordsets:from_list(maps:get(?WEAPONS_FIELD, Map)), + armors = ordsets:from_list(maps:get(?ARMORS_FIELD, Map)), + portraits = ordsets:from_list(maps:get(?PORTRAITS_FIELD, Map)), + glyph_boards = ordsets:from_list(maps:get(?GLYPH_BOARDS_FIELD, Map)), + glyphs = ordsets:from_list(maps:get(?GLYPHS_FIELD, Map)) + }. + +-spec encode (type()) -> {list({binary(), any()})}. +encode (Inv) -> + { + [ + {?WEAPONS_FIELD, ordsets:to_list(Inv#inventory.weapons)}, + {?ARMORS_FIELD, ordsets:to_list(Inv#inventory.armors)}, + {?PORTRAITS_FIELD, ordsets:to_list(Inv#inventory.portraits)}, + {?GLYPH_BOARDS_FIELD, ordsets:to_list(Inv#inventory.glyph_boards)}, + {?GLYPHS_FIELD, ordsets:to_list(Inv#inventory.glyphs)} + ] + }. -spec get_weapons_field () -> non_neg_integer(). get_weapons_field () -> #inventory.weapons. -- cgit v1.2.3-70-g09d2