Skip to content

Commit

Permalink
fix: item sorting (#3568)
Browse files Browse the repository at this point in the history
* Fix sort in pickup

* Fix sort in inventory
  • Loading branch information
joveeater authored Nov 5, 2023
1 parent 7c729d2 commit 8527fff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void inventory::unsort()

static bool stack_compare( const std::vector<item *> &lhs, const std::vector<item *> &rhs )
{
return lhs.front() < rhs.front();
return *lhs.front() < *rhs.front();
}

void inventory::clear()
Expand Down
4 changes: 2 additions & 2 deletions src/pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,15 @@ std::vector<stacked_items> stack_for_pickup_ui( const
// Each sub-stack has to be sorted separately
std::sort( restacked_children.begin(), restacked_children.end(),
[]( const std::list<item_stack::iterator> &lhs, const std::list<item_stack::iterator> &rhs ) {
return *lhs.front() < *rhs.front();
return **lhs.front() < **rhs.front();
} );
restacked_with_parents.emplace_back( stacked_items{ pr.second.parent, restacked_children } );
}

// Sorting by parent is a bit arbitrary (parent-less go last) - sort by count?
std::sort( restacked_with_parents.begin(), restacked_with_parents.end(),
[]( const stacked_items & lhs, stacked_items & rhs ) {
return lhs.parent.has_value() && ( !rhs.parent.has_value() || *lhs.parent < *rhs.parent );
return lhs.parent.has_value() && ( !rhs.parent.has_value() || **lhs.parent < **rhs.parent );
} );


Expand Down

0 comments on commit 8527fff

Please sign in to comment.