Skip to content

Commit

Permalink
Force recipes to provide (sub)category
Browse files Browse the repository at this point in the history
As suggested in CleverRaven#50866, require all recipe definitions to provide a
category and subcategory when loading from JSON.
  • Loading branch information
jbytheway committed Sep 22, 2021
1 parent 3c64818 commit 6764eeb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/recipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ void recipe::load( const JsonObject &jo, const std::string &src )

if( type == "recipe" ) {

assign( jo, "category", category, strict );
assign( jo, "subcategory", subcategory, strict );
mandatory( jo, was_loaded, "category", category );
mandatory( jo, was_loaded, "subcategory", subcategory );
assign( jo, "description", description, strict );
assign( jo, "reversible", reversible, strict );

Expand Down Expand Up @@ -377,10 +377,10 @@ void recipe::load( const JsonObject &jo, const std::string &src )
}
} else if( type == "practice" ) {
mandatory( jo, false, "name", name_ );
assign( jo, "category", category, strict );
assign( jo, "subcategory", subcategory, strict );
mandatory( jo, was_loaded, "category", category );
mandatory( jo, was_loaded, "subcategory", subcategory );
assign( jo, "description", description, strict );
mandatory( jo, false, "practice_data", practice_data );
mandatory( jo, was_loaded, "practice_data", practice_data );

if( jo.has_member( "byproducts" ) ) {
byproducts.clear();
Expand Down
1 change: 1 addition & 0 deletions src/recipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class recipe
return result_;
}

bool was_loaded = false;
bool obsolete = false;

std::string category;
Expand Down
1 change: 1 addition & 0 deletions src/recipe_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ recipe &recipe_dictionary::load( const JsonObject &jo, const std::string &src,
}

r.load( jo, src );
r.was_loaded = true;

return out[ r.ident() ] = std::move( r );
}
Expand Down

0 comments on commit 6764eeb

Please sign in to comment.