Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise grouping and ordering of IRulesetInfo/RulesetInfos #16852

Merged
merged 7 commits into from Feb 11, 2022

Conversation

frenzibyte
Copy link
Member

Since RulesetInfo provides an IComparable<T> implementation, all usages should always compare by it rather than arbitrarily ordering by OnlineID/ShortName.

This fixes ruleset groups in Editor's difficulty switch menu not being ordered appropriately:

Before After
CleanShot 2022-02-11 at 03 20 14 CleanShot 2022-02-11 at 04 23 17

I have updated EFRulesetInfo as well and isolated it from potentially comparing with realm RulesetInfos, in case that ever happens. Have tested performing an EF migration with this change and everything seem to still work.

At first I was planning on making `CompareTo` implemented at
`IRulesetInfo` itself and shared across classes, but turns out it only
implements it explicitly and not allow direct `IRulesetInfo.Equals`
calls.

It messed with my head enough that I decided to just let each class have
its own implementation and only allow same type.
Required for `APIBeatmap`s, which provide `Ruleset` instances with `OnlineID` available only.

Also consistent with the comparer implementation.
@peppy
Copy link
Sponsor Member

peppy commented Feb 11, 2022

One thing to keep in mind is that this won't be compatible with realm IQueryable, which is why I was using the direct ShortName reference previously.

But I guess we can use this if it looks to be passing.

@frenzibyte
Copy link
Member Author

Interesting point. BeatmapSet.Beatmaps are of type IList<BeatmapInfo though, so it shouldn't be a problem if I understand this correctly.

Comment on lines 47 to 48
if (OnlineID >= 0 && other.OnlineID >= 0)
return OnlineID == other.OnlineID;
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this in other models – why are we doing it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have mentioned it in commit description, but it's here to handle performing equality comparsions of rulesets provided by APIBeatmaps, in which they would only have an OnlineID present rather than ShortNames.

For cases like:

foreach (var rulesetBeatmaps in apiBeatmaps.GroupBy(b => b.Ruleset).OrderBy(g => g.Key))
    ...

to work correctly.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be doing this..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look at how things are structured for APIBeatmap, I think APIRuleset is what we want going forward, with a custom Equals implementation that uses MatchesOnlineID. Curious if that's something you're against?

Would be a private class since its only benefit is the different and more correct Equals override.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, I just don't want one Equals implementation of models to not match the others (right now, every implementation is the same across ruleset/beatmap/skin/etc).

Comment on lines 460 to 465
private class TestUnimplementedModOsuRuleset : OsuRuleset, ILegacyRuleset
{
public override string ShortName => "unimplemented";

int ILegacyRuleset.LegacyID => -1;

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests seem to pass without this being present – what's the reason for adding this here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's no longer required with 92e22c5.

@peppy peppy enabled auto-merge February 11, 2022 06:20
@peppy peppy merged commit 09d2989 into ppy:master Feb 11, 2022
@frenzibyte frenzibyte deleted the ruleset-grouping-order branch February 11, 2022 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants