summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-04-19 19:00:57 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-04-19 19:00:57 +0200
commit7ad856639b0d8470728d4e5436c3b1152959fd99 (patch)
tree0ccb9f855f0e10182977c03dbff0d908b598ebad /src/shared/struct/inventory/shr_inventory.erl
parent2ed5b1f48f7784411bcb0983b3490b7c79032eb7 (diff)
[Broken] ...
Diffstat (limited to 'src/shared/struct/inventory/shr_inventory.erl')
-rw-r--r--src/shared/struct/inventory/shr_inventory.erl36
1 files changed, 36 insertions, 0 deletions
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.