summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-04-19 19:00:57 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-04-19 19:00:57 +0200 |
commit | 7ad856639b0d8470728d4e5436c3b1152959fd99 (patch) | |
tree | 0ccb9f855f0e10182977c03dbff0d908b598ebad /src/shared/struct/inventory | |
parent | 2ed5b1f48f7784411bcb0983b3490b7c79032eb7 (diff) |
[Broken] ...
Diffstat (limited to 'src/shared/struct/inventory')
-rw-r--r-- | src/shared/struct/inventory/shr_equipment.erl | 17 | ||||
-rw-r--r-- | src/shared/struct/inventory/shr_inventory.erl | 36 |
2 files changed, 52 insertions, 1 deletions
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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -50,6 +56,14 @@ -export ( [ + encode/1, + decode/1 + ] +). + +-export +( + [ default/0, allows_equipment/2, add_equipment/2, @@ -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. |