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

JSON flag for default collapse of container contents #51434

Merged
merged 1 commit into from
Sep 21, 2021
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
5 changes: 5 additions & 0 deletions data/json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
"type": "json_flag",
"info": "This clothing has a <info>wide collar</info> that can keep your mouth warm if it is unencumbered."
},
{
"id": "COLLAPSE_CONTENTS",
"type": "json_flag",
"info": "Contents are hidden by default in inventory view."
},
{
"id": "DEAF",
"type": "json_flag",
Expand Down
3 changes: 3 additions & 0 deletions data/json/items/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@
"price_postapoc": 0,
"to_hit": -2,
"material": [ "plastic" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"pocket_data": [
{
"pocket_type": "CONTAINER",
Expand All @@ -1778,6 +1779,7 @@
"price_postapoc": 10,
"to_hit": -2,
"material": [ "cotton", "neoprene" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"pocket_data": [
{
"pocket_type": "CONTAINER",
Expand Down Expand Up @@ -1892,6 +1894,7 @@
}
],
"material": [ "plastic", "aluminum" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"symbol": ")",
"color": "light_gray"
},
Expand Down
3 changes: 2 additions & 1 deletion data/json/items/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,7 @@
"price": 1,
"price_postapoc": 10,
"material": [ "plastic" ],
"flags": [ "COLLAPSE_CONTENTS" ],
"symbol": ")",
"color": "dark_gray",
"pocket_data": [
Expand Down Expand Up @@ -3462,7 +3463,7 @@
"price": 15000,
"price_postapoc": 250,
"material": [ "plastic", "leather" ],
"flags": [ "OVERSIZE", "BELTED", "ALLOWS_NATURAL_ATTACKS", "TARDIS" ],
"flags": [ "OVERSIZE", "BELTED", "ALLOWS_NATURAL_ATTACKS", "TARDIS", "COLLAPSE_CONTENTS" ],
"weight": "708 g",
"volume": "500 ml",
"bashing": 1,
Expand Down
1 change: 1 addition & 0 deletions src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const flag_id flag_CITY_START( "CITY_START" );
const flag_id flag_CLIMATE_CONTROL( "CLIMATE_CONTROL" );
const flag_id flag_COLD( "COLD" );
const flag_id flag_COLD_IMMUNE( "COLD_IMMUNE" );
const flag_id flag_COLLAPSE_CONTENTS( "COLLAPSE_CONTENTS" );
const flag_id flag_COLLAPSIBLE_STOCK( "COLLAPSIBLE_STOCK" );
const flag_id flag_COLLAR( "COLLAR" );
const flag_id flag_CONDUCTIVE( "CONDUCTIVE" );
Expand Down
1 change: 1 addition & 0 deletions src/flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern const flag_id flag_CITY_START;
extern const flag_id flag_CLIMATE_CONTROL;
extern const flag_id flag_COLD;
extern const flag_id flag_COLD_IMMUNE;
extern const flag_id flag_COLLAPSE_CONTENTS;
extern const flag_id flag_COLLAPSIBLE_STOCK;
extern const flag_id flag_COLLAR;
extern const flag_id flag_CONDUCTIVE;
Expand Down
6 changes: 6 additions & 0 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ item::item( const itype *type, time_point turn, int qty ) : type( type ), bday(
activate();
}

if( has_flag( flag_COLLAPSE_CONTENTS ) ) {
for( item_pocket *pocket : contents.get_all_contained_pockets().value() ) {
pocket->settings.set_collapse( true );
}
}

if( has_flag( flag_NANOFAB_TEMPLATE ) ) {
itype_id nanofab_recipe =
item_group::item_from( type->nanofab_template_group ).typeId();
Expand Down
28 changes: 19 additions & 9 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,20 +1199,24 @@ bool Item_factory::check_ammo_type( std::string &msg, const ammotype &ammo ) con

void Item_factory::check_definitions() const
{
auto is_container = []( const itype * t ) {
bool am_container = false;
for( const pocket_data &pocket : t->pockets ) {
if( pocket.type == item_pocket::pocket_type::CONTAINER ) {
am_container = true;
// no need to look further
break;
}
}
return am_container;
};

for( const auto &elem : m_templates ) {
std::string msg;
const itype *type = &elem.second;

if( !type->has_flag( flag_TARDIS ) ) {
bool is_container = false;
for( const pocket_data &pocket : type->pockets ) {
if( pocket.type == item_pocket::pocket_type::CONTAINER ) {
is_container = true;
// no need to look further
break;
}
}
if( is_container ) {
if( is_container( type ) ) {
units::volume volume = type->volume;
if( type->count_by_charges() ) {
volume /= type->charges_default();
Expand All @@ -1223,6 +1227,12 @@ void Item_factory::check_definitions() const
}
}

if( type->has_flag( flag_COLLAPSE_CONTENTS ) ) {
if( !is_container( type ) ) {
msg += "is not a container so COLLAPSE_CONTENTS is unnecessary.\n";
}
}

if( !type->picture_id.is_empty() && !type->picture_id.is_valid() ) {
msg += "item has unknown ascii_picture.";
}
Expand Down