Skip to content

Commit dab4637

Browse files
committed
weakpoint families to optional
1 parent 4df0573 commit dab4637

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/monstergenerator.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -870,25 +870,7 @@ void mtype::load( const JsonObject &jo, const std::string &src )
870870
optional( jo, was_loaded, "status_chance_multiplier", status_chance_multiplier, numeric_bound_reader{0.0f, 5.0f},
871871
1.f );
872872

873-
if( !was_loaded || jo.has_array( "families" ) ) {
874-
families.clear();
875-
families.load( jo.get_array( "families" ) );
876-
} else {
877-
if( jo.has_object( "extend" ) ) {
878-
JsonObject tmp = jo.get_object( "extend" );
879-
tmp.allow_omitted_members();
880-
if( tmp.has_array( "families" ) ) {
881-
families.load( tmp.get_array( "families" ) );
882-
}
883-
}
884-
if( jo.has_object( "delete" ) ) {
885-
JsonObject tmp = jo.get_object( "delete" );
886-
tmp.allow_omitted_members();
887-
if( tmp.has_array( "families" ) ) {
888-
families.remove( tmp.get_array( "families" ) );
889-
}
890-
}
891-
}
873+
optional( jo, was_loaded, "families", families );
892874

893875
optional( jo, was_loaded, "absorb_ml_per_hp", absorb_ml_per_hp, 250 );
894876
optional( jo, was_loaded, "split_move_cost", split_move_cost, 200 );

src/weakpoint.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ void weakpoint_families::load( const JsonArray &ja )
200200
}
201201
}
202202

203+
void weakpoint_families::deserialize( const JsonValue &jv )
204+
{
205+
// the load function extends, which is kinda gross, but fine
206+
clear();
207+
load( jv.get_array() );
208+
}
209+
210+
bool weakpoint_families::handle_extend( const JsonValue &jv )
211+
{
212+
// the load function extends, which is fine I guess
213+
load( jv.get_array() );
214+
return true;
215+
}
216+
217+
bool weakpoint_families::handle_delete( const JsonValue &jv )
218+
{
219+
remove( jv.get_array() );
220+
return true;
221+
}
222+
203223
void weakpoint_families::remove( const JsonArray &ja )
204224
{
205225
for( const JsonValue jsin : ja ) {

src/weakpoint.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ struct weakpoint_family {
117117

118118
float modifier( const Character &attacker ) const;
119119
void load( const JsonValue &jsin );
120+
void deserialize( const JsonValue &jsin ) {
121+
load( jsin );
122+
}
120123
};
121124

122125
struct weakpoint_families {
@@ -133,6 +136,10 @@ struct weakpoint_families {
133136
void clear();
134137
void load( const JsonArray &ja );
135138
void remove( const JsonArray &ja );
139+
140+
void deserialize( const JsonValue &jv );
141+
bool handle_extend( const JsonValue &jv );
142+
bool handle_delete( const JsonValue &jv );
136143
};
137144

138145
struct weakpoint {

0 commit comments

Comments
 (0)