Skip to content

Commit

Permalink
Deduplicate origin string generation
Browse files Browse the repository at this point in the history
There's a templated function to do this, so use it instead of
scattering the same snippet of code around in all the places we want to
do this.
  • Loading branch information
ehughsbaird committed Oct 14, 2024
1 parent 7d4507a commit c3ce62c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 40 deletions.
5 changes: 1 addition & 4 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,10 +2400,7 @@ void item::basic_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
bool /* debug */ ) const
{
if( parts->test( iteminfo_parts::BASE_MOD_SRC ) ) {
info.emplace_back( "BASE", string_format( _( "Origin: %s" ), enumerate_as_string( type->src,
[]( const std::pair<itype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow ) ) );
info.emplace_back( "BASE", get_origin( type->src ) );
insert_separation_line( info );
}

Expand Down
17 changes: 2 additions & 15 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,7 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in
const int max_width = getmaxx( w ) - column - 1;
std::ostringstream oss;

oss << get_tag_from_color( c_white ) << _( "Origin: " );
oss << enumerate_as_string( type->src.begin(),
type->src.end(), []( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
oss << "</color>" << "\n";
oss << get_tag_from_color( c_white ) << get_origin( type->src ) << "</color>" << "\n";

if( debug_mode ) {
oss << colorize( type->id.str(), c_white );
Expand Down Expand Up @@ -975,15 +970,7 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in

void monster::print_info_imgui() const
{
ImGui::TextUnformatted( _( "Origin: " ) );
std::string mods = enumerate_as_string( type->src.begin(),
type->src.end(),
[]( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
},
enumeration_conjunction::arrow );
ImGui::SameLine( 0, 0 );
ImGui::TextUnformatted( mods.c_str() );
ImGui::TextUnformatted( get_origin( type->src ).c_str() );

if( debug_mode ) {
ImGui::TextUnformatted( type->id.c_str() );
Expand Down
17 changes: 2 additions & 15 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2136,14 +2136,7 @@ static struct {
static std::string assemble_profession_details( const avatar &u, const input_context &ctxt,
const std::vector<string_id<profession>> &sorted_profs, const int cur_id, const std::string &notes )
{
std::string assembled;

// Display Origin
const std::string mod_src = enumerate_as_string( sorted_profs[cur_id]->src, [](
const std::pair<profession_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";
std::string assembled = get_origin( sorted_profs[cur_id]->src ) + "\n";

std::string profession_name = sorted_profs[cur_id]->gender_appropriate_name( u.male );
if( get_option<bool>( "SCREEN_READER_MODE" ) && !notes.empty() ) {
Expand Down Expand Up @@ -3349,13 +3342,7 @@ static struct {
static std::string assemble_scenario_details( const avatar &u, const input_context &ctxt,
const scenario *current_scenario, const std::string &notes )
{
std::string assembled;
// Display Origin
const std::string mod_src = enumerate_as_string( current_scenario->src,
[]( const std::pair<string_id<scenario>, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";
std::string assembled = get_origin( current_scenario->src ) + "\n";

std::string scenario_name = current_scenario->gender_appropriate_name( !u.male );
if( get_option<bool>( "SCREEN_READER_MODE" ) && !notes.empty() ) {
Expand Down
7 changes: 1 addition & 6 deletions src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,12 +1572,7 @@ std::string overmapbuffer::get_description_at( const tripoint_abs_sm &where )
}
}

// Display Origin
const std::string mod_src = enumerate_as_string( oter->get_type_id().obj().src,
[]( const std::pair<oter_type_str_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
format_string += "\n" + string_format( _( "Origin: %s" ), mod_src );
format_string += "\n" + get_origin( oter->get_type_id()->src );

return string_format( format_string, ter_name, dir_name, closest_city_name );
}
Expand Down

0 comments on commit c3ce62c

Please sign in to comment.