Skip to content

Commit

Permalink
Use iteminfo_parts flags for pocket info
Browse files Browse the repository at this point in the history
In the item info display, pocket "general_info" display is now shown
only if the new iteminfo_parts::DESCRIPTION_POCKETS flag is given,
and contents info is only added if DESCRIPTION_CONTENTS is given.

These changes allow 3 of the formerly failing iteminfo_test assertions
to pass. The other 2 formerly failing tests related to BASE_RIGIDITY,
which is handled at the pocket level now), so the "item rigidity" tests
were simply removed.
  • Loading branch information
wapcaplet committed May 7, 2020
1 parent da1e58c commit dc2a35c
Showing 5 changed files with 20 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
@@ -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" ) ) {
25 changes: 15 additions & 10 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
@@ -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"
@@ -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;
@@ -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
@@ -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"
@@ -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 );

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

DESCRIPTION_FAULTS,

DESCRIPTION_POCKETS,

DESCRIPTION_HOLSTERS,

DESCRIPTION_ACTIVATABLE_TRANSFORMATION,
36 changes: 0 additions & 36 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dc2a35c

Please sign in to comment.