summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-04-26 15:05:44 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-04-26 15:05:44 +0200
commitec6eec260d6383ae948505c3d42b3055ae3dd94c (patch)
tree1d9ab2b09ab0a534fc6c09b62b940d9f1c7e139f /src/shared/struct/inventory
parent7d428bac2f9d62c5a0e704eb32be869c10fec72e (diff)
Makes Dialyzer validate shared & battle.
Diffstat (limited to 'src/shared/struct/inventory')
-rw-r--r--src/shared/struct/inventory/shr_equipment.erl26
-rw-r--r--src/shared/struct/inventory/shr_glyph.erl.m42
-rw-r--r--src/shared/struct/inventory/shr_glyph_board.erl.m49
-rw-r--r--src/shared/struct/inventory/shr_inventory.erl48
-rw-r--r--src/shared/struct/inventory/shr_weapon.erl.m42
5 files changed, 44 insertions, 43 deletions
diff --git a/src/shared/struct/inventory/shr_equipment.erl b/src/shared/struct/inventory/shr_equipment.erl
index cbd4381..a931444 100644
--- a/src/shared/struct/inventory/shr_equipment.erl
+++ b/src/shared/struct/inventory/shr_equipment.erl
@@ -40,7 +40,7 @@
-opaque unresolved() :: #shr_eq_ref{}.
-type either() :: (type() | unresolved()).
--export_type([type/0, unresolved/0]).
+-export_type([type/0, unresolved/0, either/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -84,7 +84,6 @@
set_portrait_id/2,
set_glyph_board_id/2,
set_glyph_ids/2,
- set_glyph_ids/2,
ataxia_set_primary_weapon_id/2,
ataxia_set_secondary_weapon_id/2,
@@ -299,14 +298,12 @@ set_glyphs (V, Eq) when is_record(Eq, shr_eq_ref) ->
(list(shr_glyph:type()), type()) -> {type(), ataxic:basic()};
(list(shr_glyph:type()), unresolved()) -> {unresolved(), ataxic:basic()}.
ataxia_set_glyphs (V, Eq) ->
- {
- set_glyphs(V, Eq),
- ataxic:update_field
- (
- get_glyphs_field(),
- ataxic:constant(shr_glyph:get_id(V))
- )
- }.
+ ataxia_set_glyphs
+ (
+ V,
+ ataxic:constant(lists:map(fun shr_glyph:get_id/1, V)),
+ Eq
+ ).
-spec ataxia_set_glyphs
(
@@ -448,14 +445,7 @@ set_glyph_ids (V, Eq) when is_record(Eq, shr_eq) ->
(list(shr_glyph:id()), type()) -> {type(), ataxic:basic()};
(list(shr_glyph:id()), unresolved()) -> {unresolved(), ataxic:basic()}.
ataxia_set_glyph_ids (V, Eq) ->
- {
- set_glyph_ids(V, Eq),
- ataxic:update_field
- (
- get_glyphs_field(),
- ataxic:constant(V)
- )
- }.
+ ataxia_set_glyph_ids(V, ataxic:constant(V), Eq).
-spec ataxia_set_glyph_ids
(
diff --git a/src/shared/struct/inventory/shr_glyph.erl.m4 b/src/shared/struct/inventory/shr_glyph.erl.m4
index 0ce4c47..a451cc0 100644
--- a/src/shared/struct/inventory/shr_glyph.erl.m4
+++ b/src/shared/struct/inventory/shr_glyph.erl.m4
@@ -35,7 +35,7 @@
[
get_id/1,
get_name/1,
- get_omnimods/1,
+ get_omnimods/1
]
).
diff --git a/src/shared/struct/inventory/shr_glyph_board.erl.m4 b/src/shared/struct/inventory/shr_glyph_board.erl.m4
index c2128a9..3324997 100644
--- a/src/shared/struct/inventory/shr_glyph_board.erl.m4
+++ b/src/shared/struct/inventory/shr_glyph_board.erl.m4
@@ -58,7 +58,7 @@
list(shr_glyph:type()),
list(integer())
)
- -> ({'ok', shr_omnimods:type()} | 'error').
+ -> ('error' | {'ok', shr_omnimods:type()}).
get_omnimods_with_glyphs_internals (Omnimods, [], []) ->
{ok, Omnimods};
get_omnimods_with_glyphs_internals (_Omnimods, [], _) ->
@@ -102,12 +102,15 @@ default () -> from_id(<<"0">>).
list(shr_glyph:type()),
type()
)
- -> ({'ok', shr_omnimods:type()} | 'error').
+ -> shr_omnimods:type().
get_omnimods_with_glyphs (Glyphs, GlyphBoard) ->
BoardOmnimods = GlyphBoard#glyph_board.omnimods,
BoardSlots = GlyphBoard#glyph_board.slots,
- get_omnimods_with_glyphs_internals(BoardOmnimods, Glyphs, BoardSlots).
+ {ok, Omnimods} =
+ get_omnimods_with_glyphs_internals(BoardOmnimods, Glyphs, BoardSlots),
+
+ Omnimods.
-spec default_id () -> id().
default_id () -> <<"0">>.
diff --git a/src/shared/struct/inventory/shr_inventory.erl b/src/shared/struct/inventory/shr_inventory.erl
index 4ea3e7b..884c213 100644
--- a/src/shared/struct/inventory/shr_inventory.erl
+++ b/src/shared/struct/inventory/shr_inventory.erl
@@ -22,8 +22,9 @@
).
-opaque type() :: #inventory{}.
+-type id() :: ataxia_id:type().
--export_type([type/0]).
+-export_type([type/0, id/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -95,19 +96,27 @@ get_glyphs (Inv) -> Inv#inventory.glyphs.
-spec add_weapon (shr_weapon:id(), type()) -> type().
-add_weapon (V, Inv) -> Inv#inventory{ weapons = V }.
+add_weapon (V, Inv) ->
+ Inv#inventory{ weapons = ordsets:add_element(V, Inv#inventory.weapons) }.
-spec add_armor (shr_armor:id(), type()) -> type().
-add_armor (V, Inv) -> Inv#inventory{ armors = V }.
+add_armor (V, Inv) ->
+ Inv#inventory{ armors = ordsets:add_element(V, Inv#inventory.armors) }.
-spec add_portrait (shr_portrait:id(), type()) -> type().
-add_portrait (V, Inv) -> Inv#inventory{ portraits = V }.
+add_portrait (V, Inv) ->
+ Inv#inventory{ portraits = ordsets:add_element(V, Inv#inventory.portraits) }.
-spec add_glyph_board (shr_glyph_board:id(), type()) -> type().
-add_glyph_board (V, Inv) -> Inv#inventory{ glyph_boards = V }.
+add_glyph_board (V, Inv) ->
+ Inv#inventory
+ {
+ glyph_boards = ordsets:add_element(V, Inv#inventory.glyph_boards)
+ }.
-spec add_glyph (shr_glyph:id(), type()) -> type().
-add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }.
+add_glyph (V, Inv) ->
+ Inv#inventory{ glyphs = ordsets:add_element(V, Inv#inventory.glyphs) }.
-spec ataxia_add_weapon
@@ -115,12 +124,12 @@ add_glyph (V, Inv) -> Inv#inventory{ glyphs = V }.
shr_weapon:id(),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_weapon (V, Inv) ->
CurrentWeapons = Inv#inventory.weapons,
case ordsets:is_element(V, CurrentWeapons) of
- true -> Inv;
+ true -> {Inv, ataxic:current_value()};
false ->
{
Inv#inventory{ weapons = ordsets:add_element(V, CurrentWeapons) },
@@ -142,12 +151,12 @@ ataxia_add_weapon (V, Inv) ->
shr_armor:id(),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_armor (V, Inv) ->
CurrentArmors = Inv#inventory.armors,
case ordsets:is_element(V, CurrentArmors) of
- true -> Inv;
+ true -> {Inv, ataxic:current_value()};
false ->
{
Inv#inventory{ armors = ordsets:add_element(V, CurrentArmors) },
@@ -169,12 +178,12 @@ ataxia_add_armor (V, Inv) ->
shr_portrait:id(),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_portrait (V, Inv) ->
CurrentPortraits = Inv#inventory.portraits,
case ordsets:is_element(V, CurrentPortraits) of
- true -> Inv;
+ true -> {Inv, ataxic:current_value()};
false ->
{
Inv#inventory
@@ -199,12 +208,12 @@ ataxia_add_portrait (V, Inv) ->
shr_glyph_board:id(),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_glyph_board (V, Inv) ->
CurrentGlyphBoards = Inv#inventory.glyph_boards,
case ordsets:is_element(V, CurrentGlyphBoards) of
- true -> Inv;
+ true -> {Inv, ataxic:current_value()};
false ->
{
Inv#inventory
@@ -229,12 +238,12 @@ ataxia_add_glyph_board (V, Inv) ->
shr_glyph:id(),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_glyph (V, Inv) ->
CurrentGlyphs = Inv#inventory.glyphs,
case ordsets:is_element(V, CurrentGlyphs) of
- true -> Inv;
+ true -> {Inv, ataxic:current_value()};
false ->
{
Inv#inventory{ glyphs = ordsets:add_element(V, CurrentGlyphs) },
@@ -354,7 +363,7 @@ add_equipment (Eq, Inv) ->
(shr_equipment:type()|shr_equipment:unresolved()),
type()
)
- -> {type(), list(ataxic:basic())}.
+ -> {type(), ataxic:basic()}.
ataxia_add_equipment (Eq, Inv) ->
{S0Inv, Ataxic0} =
ataxia_add_weapon(shr_equipment:get_primary_weapon_id(Eq), Inv),
@@ -380,10 +389,9 @@ ataxia_add_equipment (Eq, Inv) ->
{
S4Inv,
- lists:flatten
+ ataxic:optimize
(
- [Ataxic0, Ataxic1, Ataxic2, Ataxic3],
- lists:flatten(Ataxic4s)
+ ataxic:sequence([Ataxic0, Ataxic1, Ataxic2, Ataxic3|Ataxic4s])
)
}.
diff --git a/src/shared/struct/inventory/shr_weapon.erl.m4 b/src/shared/struct/inventory/shr_weapon.erl.m4
index 189afa7..a18c48e 100644
--- a/src/shared/struct/inventory/shr_weapon.erl.m4
+++ b/src/shared/struct/inventory/shr_weapon.erl.m4
@@ -41,7 +41,7 @@
(
[
default/0,
- default/0,
+ default_id/0,
from_id/1
]
).