Skip to content

Commit

Permalink
Swap recipe dictionary to use duplicate entries method
Browse files Browse the repository at this point in the history
  • Loading branch information
b3brodie committed Oct 13, 2024
1 parent 4eb9249 commit 52d7c73
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/recipe_dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,30 +441,9 @@ recipe &recipe_dictionary::load( const JsonObject &jo, const std::string &src,
r.was_loaded = true;

// Check for duplicate recipe_ids before assigning it to the map
if( out.find( r.ident() ) != out.end() ) {
const std::string new_mod_src = enumerate_as_string( r.src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
const std::string old_mod_src = enumerate_as_string( out[ r.ident() ].src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );

const std::string base_json = string_format( "'%s'", _( "Dark Days Ahead" ) );
if( old_mod_src == base_json && new_mod_src != base_json ) {
// Assume the mod developer knows what they're doing
} else if( old_mod_src == new_mod_src ) {
// Conflict within a single source. Throw an error:
debugmsg( "Unable to load recipe_id %1$s. A recipe with that id already exists.\nExisting recipe source: %2$s\nNew recipe source: %3$s",
r.ident().str(), old_mod_src, new_mod_src );
} else {
// Conflict between mods, leave a warning for debugging
DebugLog( DebugLevel::D_WARNING,
DC_ALL ) <<
string_format( "Recipe_id conflict: %1$s is included in both %2$s and %3$s. Only the latter recipe will be loaded",
r.ident().str(), old_mod_src, new_mod_src );
}
auto duplicate = out.find( r.ident() );
if( duplicate != out.end() ) {
mod_tracker::check_duplicate_entries(r, duplicate->second);
}

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

0 comments on commit 52d7c73

Please sign in to comment.