Skip to content

Commit

Permalink
Reduce scope of variable.
Browse files Browse the repository at this point in the history
Mostly just make new variables within the blocks. This avoids the need to clear the variable each time.

And sometimes just use the string directly.
  • Loading branch information
BevapDin committed Dec 20, 2019
1 parent 5b53c3c commit 1ceb058
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ int construction_menu( bool blueprint )
current_con->requirements->can_make_with_inventory( total_inv, is_crafting_component );

std::vector<std::string> current_buffer;
std::string current_line;

const auto add_folded = [&]( const std::vector<std::string> &folded ) {
current_buffer.insert( current_buffer.end(), folded.begin(), folded.end() );
Expand All @@ -437,7 +436,7 @@ int construction_menu( bool blueprint )
// in their title what their result is.
if( !current_con->post_terrain.empty() && options.size() > 1 ) {
//also print out stage number when multiple stages are available
current_line += string_format( _( "Stage/Variant #%d: " ), stage_counter );
std::string current_line = string_format( _( "Stage/Variant #%d: " ), stage_counter );

// print name of the result of each stage
std::string result_string;
Expand Down Expand Up @@ -466,7 +465,7 @@ int construction_menu( bool blueprint )

// display description of the result for single stages
} else if( !current_con->post_terrain.empty() ) {
current_line = _( "Result: " );
std::string current_line = _( "Result: " );
if( current_con->post_is_furniture ) {
current_line += colorize(
furn_str_id( current_con->post_terrain ).obj().description,
Expand All @@ -481,14 +480,12 @@ int construction_menu( bool blueprint )
add_line( current_line );
}

current_line.clear();
// display required skill and difficulty
if( current_con->required_skills.empty() ) {
current_line += _( "N/A" );
add_line( _( "N/A" ) );
} else {
current_line += _( "Required skills: " ) +
enumerate_as_string( current_con->required_skills.begin(),
current_con->required_skills.end(),
std::string current_line = _( "Required skills: " ) + enumerate_as_string(
current_con->required_skills.begin(), current_con->required_skills.end(),
[]( const std::pair<skill_id, int> &skill ) {
nc_color col;
int s_lvl = g->u.get_skill_level( skill.first );
Expand All @@ -502,9 +499,9 @@ int construction_menu( bool blueprint )

return colorize( string_format( "%s (%d)", skill.first.obj().name(), skill.second ), col );
}, enumeration_conjunction::none );
add_line( current_line );
}

add_line( current_line );
// TODO: Textify pre_flags to provide a bit more information.
// Example: First step of dig pit could say something about
// requiring diggable ground.
Expand All @@ -516,12 +513,10 @@ int construction_menu( bool blueprint )
require_string = ter_str_id( current_con->pre_terrain )->name();
}
nc_color pre_color = has_pre_terrain( *current_con ) ? c_green : c_red;
current_line = _( "Requires: " ) + colorize( require_string, pre_color );
add_line( current_line );
add_line( _( "Requires: " ) + colorize( require_string, pre_color ) );
}
if( !current_con->pre_note.empty() ) {
current_line = _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data );
add_line( current_line );
add_line( _( "Annotation: " ) + colorize( _( current_con->pre_note ), color_data ) );
}
// get pre-folded versions of the rest of the construction project to be displayed later

Expand Down

0 comments on commit 1ceb058

Please sign in to comment.