Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iteminfo tests and refactor pocket display #40314

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3689,7 +3689,7 @@ void item::final_info( std::vector<iteminfo> &info, const iteminfo_query *parts,
}
}

contents.info( info );
contents.info( info, parts );
contents_info( info, parts, batch, debug );

if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
Expand Down
25 changes: 15 additions & 10 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "enums.h"
#include "game.h"
#include "item.h"
#include "iteminfo_query.h"
#include "itype.h"
#include "item_pocket.h"
#include "map.h"
Expand Down Expand Up @@ -819,7 +820,7 @@ static void insert_separation_line( std::vector<iteminfo> &info )
}
}

void item_contents::info( std::vector<iteminfo> &info ) const
void item_contents::info( std::vector<iteminfo> &info, const iteminfo_query *parts ) const
{
int pocket_number = 1;
std::vector<iteminfo> contents_info;
Expand All @@ -843,15 +844,19 @@ void item_contents::info( std::vector<iteminfo> &info ) const
pocket.contents_info( contents_info, pocket_number++, contents.size() != 1 );
}
}
int idx = 0;
for( const item_pocket &pocket : found_pockets ) {
insert_separation_line( info );
if( pocket_num[idx] > 1 ) {
info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Pockets (%d)</bold>" ),
pocket_num[idx] ) );
if( parts->test( iteminfo_parts::DESCRIPTION_POCKETS ) ) {
int idx = 0;
for( const item_pocket &pocket : found_pockets ) {
insert_separation_line( info );
if( pocket_num[idx] > 1 ) {
info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Pockets (%d)</bold>" ),
pocket_num[idx] ) );
}
idx++;
pocket.general_info( info, idx, false );
}
idx++;
pocket.general_info( info, idx, false );
}
info.insert( info.end(), contents_info.begin(), contents_info.end() );
if( parts->test( iteminfo_parts::DESCRIPTION_CONTENTS ) ) {
info.insert( info.end(), contents_info.begin(), contents_info.end() );
}
}
3 changes: 2 additions & 1 deletion src/item_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "enums.h"
#include "item_pocket.h"
#include "iteminfo_query.h"
#include "optional.h"
#include "ret_val.h"
#include "type_id.h"
Expand Down Expand Up @@ -188,7 +189,7 @@ class item_contents
void remove_internal( const std::function<bool( item & )> &filter,
int &count, std::list<item> &res );

void info( std::vector<iteminfo> &info ) const;
void info( std::vector<iteminfo> &info, const iteminfo_query *parts ) const;

void combine( const item_contents &read_input );

Expand Down
2 changes: 2 additions & 0 deletions src/iteminfo_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ enum class iteminfo_parts : size_t {

DESCRIPTION_FAULTS,

DESCRIPTION_POCKETS,

DESCRIPTION_HOLSTERS,

DESCRIPTION_ACTIVATABLE_TRANSFORMATION,
Expand Down
36 changes: 0 additions & 36 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,6 @@ TEST_CASE( "item owner, price, and barter value", "[item][iteminfo][price]" )
}
}

TEST_CASE( "item rigidity", "[item][iteminfo][rigidity][!mayfail]" )
{
iteminfo_query q = q_vec( { iteminfo_parts::BASE_RIGIDITY, iteminfo_parts::ARMOR_ENCUMBRANCE } );

SECTION( "non-rigid items indicate their flexible volume/encumbrance" ) {
test_info_equals(
item( "test_waterskin" ), q,
"--\n"
"<color_c_white>Encumbrance</color>: <color_c_yellow>0</color>"
" Encumbrance when full: <color_c_yellow>6</color>\n"
"--\n"
"* This item is <color_c_cyan>not rigid</color>."
" Its volume and encumbrance increase with contents.\n" );

test_info_equals(
item( "test_backpack" ), q,
"--\n"
"<color_c_white>Encumbrance</color>: <color_c_yellow>2</color>"
" Encumbrance when full: <color_c_yellow>15</color>\n"
"--\n"
"* This item is <color_c_cyan>not rigid</color>."
" Its volume and encumbrance increase with contents.\n" );
}

SECTION( "rigid items do not indicate they are rigid, since almost all items are" ) {
test_info_equals(
item( "test_briefcase" ), q,
"--\n"
"<color_c_white>Encumbrance</color>: <color_c_yellow>30</color>\n" );

test_info_equals( item( "test_jug_plastic" ), q, "" );
test_info_equals( item( "test_pipe" ), q, "" );
test_info_equals( item( "test_pine_nuts" ), q, "" );
}
}

TEST_CASE( "weapon attack ratings and moves", "[item][iteminfo][weapon]" )
{
// new DPS calculations depend on the avatar's stats, so make sure they're consistent
Expand Down