Skip to content

Commit

Permalink
Extend/Delete in requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Maleclypse committed Feb 22, 2021
1 parent 7bc4088 commit 9da0eae
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/requirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@ void quality_requirement::load( const JsonValue &value )
count = quality_data.get_int( "amount", 1 );
if( count <= 0 ) {
quality_data.throw_error( "quality amount must be a positive number", "amount" );
}
} else {
if( jo.has_object( "extend" ) ) {
JsonObject tmp = jo.get_object( "extend" );
tmp.allow_omitted_members();
extend_qualities_from_json( tmp, "qualities", def );
}
if( jo.has_object( "delete" ) ) {
JsonObject tmp = jo.get_object( "delete" );
tmp.allow_omitted_members();
delete_qualities_from_json( tmp, "qualities", def );
}
}
// Note: level is not checked, negative values and 0 are allow, see butchering quality.
}

Expand Down Expand Up @@ -230,7 +241,18 @@ void tool_comp::load( const JsonValue &value )
}
if( count == 0 ) {
value.throw_error( "tool count must not be 0" );
}
} else {
if( jo.has_object( "extend" ) ) {
JsonObject tmp = jo.get_object( "extend" );
tmp.allow_omitted_members();
extend_qualities_from_json( tmp, "qualities", def );
}
if( jo.has_object( "delete" ) ) {
JsonObject tmp = jo.get_object( "delete" );
tmp.allow_omitted_members();
delete_qualities_from_json( tmp, "qualities", def );
}
}
// Note: negative count means charges (of the tool) should be consumed
}

Expand Down Expand Up @@ -287,7 +309,18 @@ void requirement_data::load_obj_list( const JsonArray &jsarr, std::vector< std::
for( const JsonValue subentry : entry.get_array() ) {
choices.push_back( T() );
choices.back().load( subentry );
}
} else {
if( jo.has_object( "extend" ) ) {
JsonObject tmp = jo.get_object( "extend" );
tmp.allow_omitted_members();
extend_qualities_from_json( tmp, "qualities", def );
}
if( jo.has_object( "delete" ) ) {
JsonObject tmp = jo.get_object( "delete" );
tmp.allow_omitted_members();
delete_qualities_from_json( tmp, "qualities", def );
}
}
if( !choices.empty() ) {
objs.push_back( choices );
}
Expand Down

0 comments on commit 9da0eae

Please sign in to comment.