Skip to content

Commit

Permalink
Adjust "protected from rot" lines in item description (#2326)
Browse files Browse the repository at this point in the history
* Fridge pseudo-flag display adjustments

Don't show duration for unprotected
Fix "indefinite" duration for contained items

* Test fix
  • Loading branch information
Coolthulhu authored Feb 6, 2023
1 parent ce24b87 commit cda4bc7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
18 changes: 12 additions & 6 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1801,30 +1801,35 @@ void item::food_info( const item *food_item, std::vector<iteminfo> &info,


if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
std::string temperature_description;
const char *temperature_description;
bool print_freshness_duration = false;
// There should be a better way to do this...
switch( temperature ) {
case temperature_flag::TEMP_NORMAL:
case temperature_flag::TEMP_HEATER: {
temperature_description = _( "* Current storage conditions <bad>do not</bad> "
"protect this item from rot. It will stay fresh at least <info>%s</info>." );
"protect this item from rot." );
}
break;
case temperature_flag::TEMP_FRIDGE:
case temperature_flag::TEMP_ROOT_CELLAR: {
temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
"protect this item from rot. It will stay fresh at least <info>%s</info>." );
print_freshness_duration = true;
}
break;
case temperature_flag::TEMP_FREEZER: {
temperature_description = _( "* Current storage conditions <good>fully</good> "
"protect this item from rot. It will stay fresh indefinitely." );
}
break;
default: {
temperature_description = "BUGGED TEMPERATURE INFO";
}
}

if( temperature != temperature_flag::TEMP_FREEZER ) {
time_duration remaining_fresh = minimum_freshness_duration( temperature );
if( print_freshness_duration ) {
time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
std::string time_string = to_string_clipped( remaining_fresh );
info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
} else {
Expand Down Expand Up @@ -4041,9 +4046,10 @@ std::string item::info_string() const
return info_string( iteminfo_query::all, 1 );
}

std::string item::info_string( const iteminfo_query &parts, int batch ) const
std::string item::info_string( const iteminfo_query &parts, int batch,
temperature_flag temperature ) const
{
std::vector<iteminfo> item_info = info( parts, batch, temperature_flag::TEMP_NORMAL );
std::vector<iteminfo> item_info = info( parts, batch, temperature );
return format_item_info( item_info, {} );
}

Expand Down
3 changes: 2 additions & 1 deletion src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ class item : public visitable<item>
*/
/*@{*/
std::string info_string() const;
std::string info_string( const iteminfo_query &parts, int batch = 1 ) const;
std::string info_string( const iteminfo_query &parts, int batch = 1,
temperature_flag temperature = temperature_flag::TEMP_NORMAL ) const;
/*@}*/

/* type specific helper functions for info() that should probably be in itype() */
Expand Down
56 changes: 32 additions & 24 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ static std::string escape_newlines( const std::string &input )
}

static void test_info_equals( const item &i, const iteminfo_query &q,
const std::string &reference )
const std::string &reference,
temperature_flag temperature = temperature_flag::TEMP_NORMAL )
{
g->u.clear_mutations();
std::string info = i.info_string( q, 1 );
std::string info = i.info_string( q, 1, temperature );
CAPTURE( escape_newlines( info ) );
CAPTURE( escape_newlines( reference ) );
CHECK( info == reference );
Expand Down Expand Up @@ -393,9 +394,6 @@ TEST_CASE( "nutrients in food", "[item][iteminfo][food]" )
}
}

// TODO: Clean up before merging
#include "output.h"

TEST_CASE( "food freshness and lifetime", "[item][iteminfo][food]" )
{
iteminfo_query q = q_vec( { iteminfo_parts::FOOD_ROT, iteminfo_parts::FOOD_ROT_STORAGE} );
Expand All @@ -411,7 +409,7 @@ TEST_CASE( "food freshness and lifetime", "[item][iteminfo][food]" )
"* This food is <color_c_yellow>perishable</color>, and at room temperature has"
" an estimated nominal shelf life of <color_c_cyan>3 seasons</color>.\n"
"* Current storage conditions <color_c_red>do not</color> protect this item"
" from rot. It will stay fresh at least <color_c_cyan>1 week</color>.\n"
" from rot.\n"
"* This food looks as <color_c_green>fresh</color> as it can be.\n" );
}

Expand All @@ -424,28 +422,38 @@ TEST_CASE( "food freshness and lifetime", "[item][iteminfo][food]" )
"* This food is <color_c_yellow>perishable</color>, and at room temperature has"
" an estimated nominal shelf life of <color_c_cyan>3 seasons</color>.\n"
"* Current storage conditions <color_c_red>do not</color> protect this item"
" from rot. It will stay fresh at least <color_c_cyan>0 seconds</color>.\n"
" from rot.\n"
"* This food looks <color_c_red>old</color>. It's on the brink of becoming inedible.\n"
);
}

/*
SECTION( "food is stored in a fridge" ) {
item nuts( "test_pine_nuts" );
get_avatar().clear_mutations();
std::string reference = "--\n"
"* This food is <color_c_yellow>perishable</color>, and at room temperature has"
" an estimated nominal shelf life of <color_c_cyan>3 seasons</color>.\n"
"* This food looks <color_c_red>old</color>. It's on the brink of becoming inedible.\n"
"* Current storage conditions <color_c_red>do not</color> protect this item"
" from rot. It will stay fresh at least <color_c_cyan>0 seconds</color>.\n"
"* This food looks <color_c_red>old</color>. It's on the brink of becoming"
" inedible.";
std::vector<iteminfo> item_info = nuts.info( q, 1, temperature_flag::TEMP_FRIDGE );
std::string info = format_item_info( item_info, {} );
CHECK( info == reference );
}
*/
SECTION( "food is stored in a fridge" ) {
item nuts( "test_pine_nuts" );
test_info_equals(
nuts, q,
"--\n"
"* This food is <color_c_yellow>perishable</color>, and at room temperature"
" has an estimated nominal shelf life of <color_c_cyan>3 seasons</color>.\n"
"* Current storage conditions <color_c_yellow>partially</color> protect this"
" item from rot. It will stay fresh at least <color_c_cyan>3 years</color>.\n"
"* This food looks as <color_c_green>fresh</color> as it can be.\n",
temperature_flag::TEMP_FRIDGE
);
}

SECTION( "liquid food is stored in a container in a fridge" ) {
item food_item = item( itype_id( "milk" ) ).in_container( itype_id( "glass" ) );
test_info_equals(
food_item, q,
"--\n"
"* This food is <color_c_yellow>perishable</color>, and at room temperature"
" has an estimated nominal shelf life of <color_c_cyan>1 day</color>.\n"
"* Current storage conditions <color_c_yellow>partially</color> protect this"
" item from rot. It will stay fresh at least <color_c_cyan>4 days</color>.\n"
"* This food looks as <color_c_green>fresh</color> as it can be.\n",
temperature_flag::TEMP_FRIDGE
);
}
}

TEST_CASE( "item conductivity", "[item][iteminfo][conductivity]" )
Expand Down

0 comments on commit cda4bc7

Please sign in to comment.