From 9da0eaeb4e429187370701047115fbf391acf99a Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Mon, 22 Feb 2021 00:21:30 -0600 Subject: [PATCH] Extend/Delete in requirements --- src/requirements.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/requirements.cpp b/src/requirements.cpp index ba5f4a0e712fa..2525158211832 100644 --- a/src/requirements.cpp +++ b/src/requirements.cpp @@ -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. } @@ -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 } @@ -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 ); }