Sort GUI KSP version column correctly #3106
Merged
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.
Problem
If you sort by Max KSP version, 1.10 comes between 1.1 and 1.2, which is wrong.
Cause
Currently this column sorts as a string, which only works if the lexicographical sort order of the strings corresponds to the true sorting of the versions, which it doesn't.
Changes
This gets a bit tricky. We need to expose the
GUIMod
'sKspVersion
object, but we can't just sort by that object naïvely, becauseKspVersion.CompareTo
sorts undefined values inappropriately for upper bounds; it considers 1.8 < 1.8.0, andany
< everything. We want the opposite, so we can't use.OrderBy
or.OrderByDescending
for this.Instead,
ManageMods
now has an alternateSort
overload that takes aComparison<DataGridViewRow>
, which can handle comparisons between two objects rather than just returning a sort key for one object. The KSP version column uses thisSort
with a new function that treats undefined components ofKspVersion
as maximum rather than minimum. This causes the column to sort according to actual compatibility.Fixes #3105.
Quirks
Note that this logic makes finer distinctions in mod compatibility than the
.ToYalovString()
display function does. This means that the alphabetical fallback sorting may sometimes appear to reset unexpectedly. For example, consider this block of mods that all display as "1.10.9":The Versions tab reveals:
So while the column's strings are superficially the same, the introduction of a KSP 1.10.95 or KSP 1.10.100 would draw out real distinctions in their compatibility, which this sort order reflects.