Skip to content

Conversation

@MSchmoecker
Copy link

In many mods, categories are prefixed with numbers to control their order. However, since sorting is done lexical, numbers greater than 10 are not ordered intuitively. E.g. "10" comes before "2".

This PR improves category sorting by extracting numeric prefixes and sorting them numerically before applying a lexical sort. Categories without a numeric prefix remain unaffected. Categories with the same number prefix are still sorted lexical.

For example, instead of:

1 - First Category
10 - Tenth Category
2 - Second Category
...

They are now ordered:

1 - First Category
2 - Second Category
...
10 - Tenth Category

@ManlyMarco
Copy link
Member

ManlyMarco commented Jan 11, 2025

Don't do that, just set the Order property https://github.com/BepInEx/BepInEx.ConfigurationManager?tab=readme-ov-file#overriding-default-configuration-manager-behavior

Though to be fair I don't remember if this affects category ordering as well, but still changing how strings are sorted just for this is not a great idea. You can add a 0 and it will sort fine, e.g. 01 02 03 ... 10 11

@MSchmoecker
Copy link
Author

MSchmoecker commented Jan 11, 2025

Category ordering cannot be controlled via ConfigurationManagerAttributes. This only applied to the entry within the section.

Adding leading 0's is a bit akward and if not implemented from the beginning, introducing it in a later release requires to regenerating the configuration file.

There is not much harm changing the order in which categories are listed to behave more intuitively if they start with a numbering. Of course, a more sophisticated control of category order would be nice but this is a simple change that solves the issue of wrongly ordered numbered sections in the Config Manager.

@ManlyMarco
Copy link
Member

How about simply keeping the original order of categories in which they were added? I made a quick test and it seems to work fine with all of the plugins I had to test with master...cat-order

What do you think?

Here's a test build if you want one ConfigurationManager.zip

@MSchmoecker
Copy link
Author

@ManlyMarco keeping the original order of categories works for me and your test version runs as expected.

@ManlyMarco
Copy link
Member

Merged #102 with the order change, so I'll close this PR.

@ManlyMarco ManlyMarco closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants