Add Quality item sorting + major item sorting refactor - #222
Merged
Conversation
apparently there was a reason the old one did things like this...
except alphabetical sorting cus i cannot be Fucked rn tbh 😭
my head hurts
SSM240
force-pushed
the
quality-sorting
branch
from
February 8, 2026 00:28
ce81e9e to
2adf014
Compare
Collaborator
Author
|
Well I've done a decent few runs with this version now, and aside from the bug I just fixed (modded items were accidentally being sorted like an uncommon quality because I used the wrong default), I haven't found any problems with sorting or errors in the log, so I'm reasonably certain it's stable. Can probably be merged unless you have any major concerns. (also, the force push was just cus i wanted to add a quick code comment without making a new commit, but it turns out doing that also shows up here lol) |
Member
|
Sorry, I forgot to merge this forever ago. That's my bad |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a recent update to Quality, they added the feature to group together different quality versions of the same item. However, it ends up not doing that much if you have stack count sorting on from this mod.
So I was like, fuck it, let's just do it myself, and then also go further, because I apparently can't get enough of item sorting.
First off, to make it more easily extensible, I completely rewrote the
SortItemsmethod. Instead of worrying about separate lists for tiers and scrap and all that, or trying to shove all our sorting criteria into a single number, I just use a tuple instead. This is a much cleaner way of sorting based on several different criteria with different priorities - the stuff we want to separate out goes first, and the stuff we want to keep grouped together goes at the end. And since the sort is stable, we can just disable a given sorting criterion by setting its key to 0.(While I was at it, I changed
SortPickups(used for the Chef crafting interface) to simply defer to SortItems instead of duplicating logic, and made it consistently match scrapper sort settings. except I didn't implement the alphabetical sorting because I could not be assed lol, someone else can probably figure that out if it's deemed important)All that was to more easily support the main feature, which adds two settings:
On a technical level, this involved adding a soft dependency + assembly reference for the ItemQualities mod. The important notes regarding the compat are:
NoInliningandNoOptimizationflags help with this, by stopping the runtime from being too greedy and potentially accessing the method bodies without them being called.usings so you're not getting autocomplete for ItemQualities everywhere else.Miscellaneous details / concerns:
acquiredOrderdict might seem dumb at first, since they're already ordered that way by default, but it's necessary for quality grouping while otherwise maintaining acquisition order, since I need to access other items' positions in the inventory. (Technically you don't need it, but searching an array is O(n), and doing that for every single item sounds probably bad.)HandleQualityItemscould be handled better? It does need to be its own method, but I will admit taking a billion parameters, some of them ref, is a bit ugly. I just felt like it was most straightforward to treat it as "part of" SortItems, just separated out for technical reasons. (I guess it could be another nested local function to avoid having to pass all that state, but that also feels ugly + not having it in its own file means you run into theusings problem I mentioned.)