Skip to content

Commit

Permalink
fix loading holsters
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Jan 27, 2020
1 parent 4f4ddd1 commit 5b0cb63
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ void item_contents::combine( const item_contents &rhs )
{
for( const item_pocket &pocket : rhs.contents ) {
if( !pocket.is_valid() || pocket.saved_type() == item_pocket::pocket_type::LEGACY_CONTAINER ) {
for( const item it : pocket.all_items() ) {
insert_legacy( it );
for( const item *it : pocket.all_items_top() ) {
insert_legacy( *it );
}
} else {
for( const item it : pocket.all_items() ) {
const ret_val<bool> inserted = insert_item( it, pocket.saved_type() );
for( const item *it : pocket.all_items_top() ) {
const ret_val<bool> inserted = insert_item( *it, pocket.saved_type() );
if( !inserted.success() ) {
debugmsg( "error: tried to put an item into a pocket that can't fit it while loading. err: %s",
inserted.str() );
Expand Down Expand Up @@ -308,7 +308,7 @@ std::list<item *> item_contents::all_items_top( item_pocket::pocket_type pk_type
std::list<item *> all_items_internal;
for( item_pocket &pocket : contents ) {
if( pocket.is_type( pk_type ) ) {
std::list<item *> contained_items = pocket.all_items_top( pk_type );
std::list<item *> contained_items = pocket.all_items_top();
all_items_internal.insert( all_items_internal.end(), contained_items.begin(),
contained_items.end() );
}
Expand Down
17 changes: 12 additions & 5 deletions src/item_pocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,20 @@ std::list<const item *> item_pocket::all_items_ptr( item_pocket::pocket_type pk_
return all_items_top;
}

std::list<item *> item_pocket::all_items_top( item_pocket::pocket_type pk_type )
std::list<item *> item_pocket::all_items_top()
{
std::list<item *> all_items_top;
if( is_type( pk_type ) ) {
for( item &it : contents ) {
all_items_top.push_back( &it );
}
for( item &it : contents ) {
all_items_top.push_back( &it );
}
return all_items_top;
}

std::list<const item *> item_pocket::all_items_top() const
{
std::list<const item *> all_items_top;
for( const item &it : contents ) {
all_items_top.push_back( &it );
}
return all_items_top;
}
Expand Down
4 changes: 2 additions & 2 deletions src/item_pocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class item_pocket
std::list<item *> all_items_ptr( pocket_type pk_type );
std::list<const item *> all_items_ptr( pocket_type pk_type ) const;

std::list<item *> all_items_top( item_pocket::pocket_type pk_type =
item_pocket::pocket_type::CONTAINER );
std::list<item *> all_items_top();
std::list<const item *> all_items_top() const;

item &back();
const item &back() const;
Expand Down
18 changes: 11 additions & 7 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ static void deserialize( weak_ptr_fast<monster> &obj, JsonIn &jsin )

void item_contents::serialize( JsonOut &json ) const
{
json.start_object();
if( !contents.empty() ) {
json.start_object();

json.member( "contents", contents );
json.member( "contents", contents );

json.end_object();
json.end_object();
}
}

void item_contents::deserialize( JsonIn &jsin )
Expand All @@ -169,8 +171,9 @@ void item_contents::deserialize( JsonIn &jsin )
void item_pocket::serialize( JsonOut &json ) const
{
json.start_object();

json.member( "contents", contents );
if( !contents.empty() ) {
json.member( "contents", contents );
}
json.member( "pocket_type", data->type );

json.end_object();
Expand Down Expand Up @@ -2426,8 +2429,9 @@ void item::serialize( JsonOut &json ) const
{
io::JsonObjectOutputArchive archive( json );
const_cast<item *>( this )->io( archive );

json.member( "contents", contents );
if( !contents.empty() ) {
json.member( "contents", contents );
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 5b0cb63

Please sign in to comment.