mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 03:07:19 +08:00
Merge pull request #16852 from frenzibyte/ruleset-grouping-order
Standardise grouping and ordering of `IRulesetInfo`/`RulesetInfo`s
This commit is contained in:
commit
09d29892c9
@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
|
|
||||||
bool firstGroup = true;
|
bool firstGroup = true;
|
||||||
|
|
||||||
foreach (var group in beatmapSetInfo.Beatmaps.GroupBy(beatmap => beatmap.Ruleset.OnlineID).OrderBy(group => group.Key))
|
foreach (var group in beatmapSetInfo.Beatmaps.GroupBy(beatmap => beatmap.Ruleset).OrderBy(group => group.Key))
|
||||||
{
|
{
|
||||||
if (!firstGroup)
|
if (!firstGroup)
|
||||||
{
|
{
|
||||||
|
@ -62,10 +62,8 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
// matching web: https://github.com/ppy/osu-web/blob/d06d8c5e735eb1f48799b1654b528e9a7afb0a35/resources/assets/lib/beatmapset-panel.tsx#L127
|
// matching web: https://github.com/ppy/osu-web/blob/d06d8c5e735eb1f48799b1654b528e9a7afb0a35/resources/assets/lib/beatmapset-panel.tsx#L127
|
||||||
bool collapsed = beatmapSet.Beatmaps.Count() > 12;
|
bool collapsed = beatmapSet.Beatmaps.Count() > 12;
|
||||||
|
|
||||||
foreach (var rulesetGrouping in beatmapSet.Beatmaps.GroupBy(beatmap => beatmap.Ruleset.OnlineID).OrderBy(group => group.Key))
|
foreach (var rulesetGrouping in beatmapSet.Beatmaps.GroupBy(beatmap => beatmap.Ruleset).OrderBy(group => group.Key))
|
||||||
{
|
flow.Add(new RulesetDifficultyGroup(rulesetGrouping.Key.OnlineID, rulesetGrouping, collapsed));
|
||||||
flow.Add(new RulesetDifficultyGroup(rulesetGrouping.Key, rulesetGrouping, collapsed));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -98,7 +98,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
|
|
||||||
public string MD5Hash => Checksum;
|
public string MD5Hash => Checksum;
|
||||||
|
|
||||||
public IRulesetInfo Ruleset => new RulesetInfo { OnlineID = RulesetID };
|
public IRulesetInfo Ruleset => new APIRuleset { OnlineID = RulesetID };
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string Hash => throw new NotImplementedException();
|
public string Hash => throw new NotImplementedException();
|
||||||
@ -106,5 +106,29 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && this.MatchesOnlineID(b);
|
public bool Equals(IBeatmapInfo? other) => other is APIBeatmap b && this.MatchesOnlineID(b);
|
||||||
|
|
||||||
|
private class APIRuleset : IRulesetInfo
|
||||||
|
{
|
||||||
|
public int OnlineID { get; set; } = -1;
|
||||||
|
|
||||||
|
public string Name => $@"{nameof(APIRuleset)} (ID: {OnlineID})";
|
||||||
|
public string ShortName => nameof(APIRuleset);
|
||||||
|
public string InstantiationInfo => string.Empty;
|
||||||
|
|
||||||
|
public Ruleset CreateInstance() => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public bool Equals(IRulesetInfo? other) => other is APIRuleset r && this.MatchesOnlineID(r);
|
||||||
|
|
||||||
|
public int CompareTo(IRulesetInfo other)
|
||||||
|
{
|
||||||
|
if (!(other is APIRuleset ruleset))
|
||||||
|
throw new ArgumentException($@"Object is not of type {nameof(APIRuleset)}.", nameof(other));
|
||||||
|
|
||||||
|
return OnlineID.CompareTo(ruleset.OnlineID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReSharper disable once NonReadonlyMemberInGetHashCode
|
||||||
|
public override int GetHashCode() => OnlineID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace osu.Game.Rulesets
|
|||||||
{
|
{
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
[Table(@"RulesetInfo")]
|
[Table(@"RulesetInfo")]
|
||||||
public sealed class EFRulesetInfo : IEquatable<EFRulesetInfo>, IRulesetInfo
|
public sealed class EFRulesetInfo : IEquatable<EFRulesetInfo>, IComparable<EFRulesetInfo>, IRulesetInfo
|
||||||
{
|
{
|
||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
|
|
||||||
@ -42,7 +42,15 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
public bool Equals(EFRulesetInfo other) => other != null && ID == other.ID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo;
|
public bool Equals(EFRulesetInfo other) => other != null && ID == other.ID && Available == other.Available && Name == other.Name && InstantiationInfo == other.InstantiationInfo;
|
||||||
|
|
||||||
public int CompareTo(RulesetInfo other) => OnlineID.CompareTo(other.OnlineID);
|
public int CompareTo(EFRulesetInfo other) => OnlineID.CompareTo(other.OnlineID);
|
||||||
|
|
||||||
|
public int CompareTo(IRulesetInfo other)
|
||||||
|
{
|
||||||
|
if (!(other is EFRulesetInfo ruleset))
|
||||||
|
throw new ArgumentException($@"Object is not of type {nameof(EFRulesetInfo)}.", nameof(other));
|
||||||
|
|
||||||
|
return CompareTo(ruleset);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj) => obj is EFRulesetInfo rulesetInfo && Equals(rulesetInfo);
|
public override bool Equals(object obj) => obj is EFRulesetInfo rulesetInfo && Equals(rulesetInfo);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace osu.Game.Rulesets
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A representation of a ruleset's metadata.
|
/// A representation of a ruleset's metadata.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRulesetInfo : IHasOnlineID<int>, IEquatable<IRulesetInfo>, IComparable<RulesetInfo>
|
public interface IRulesetInfo : IHasOnlineID<int>, IEquatable<IRulesetInfo>, IComparable<IRulesetInfo>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user-exposed name of this ruleset.
|
/// The user-exposed name of this ruleset.
|
||||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Rulesets
|
|||||||
{
|
{
|
||||||
[ExcludeFromDynamicCompile]
|
[ExcludeFromDynamicCompile]
|
||||||
[MapTo("Ruleset")]
|
[MapTo("Ruleset")]
|
||||||
public class RulesetInfo : RealmObject, IEquatable<RulesetInfo>, IRulesetInfo
|
public class RulesetInfo : RealmObject, IEquatable<RulesetInfo>, IComparable<RulesetInfo>, IRulesetInfo
|
||||||
{
|
{
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public string ShortName { get; set; } = string.Empty;
|
public string ShortName { get; set; } = string.Empty;
|
||||||
@ -47,7 +47,7 @@ namespace osu.Game.Rulesets
|
|||||||
return ShortName == other.ShortName;
|
return ShortName == other.ShortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
|
public bool Equals(IRulesetInfo? other) => other is RulesetInfo r && Equals(r);
|
||||||
|
|
||||||
public int CompareTo(RulesetInfo other)
|
public int CompareTo(RulesetInfo other)
|
||||||
{
|
{
|
||||||
@ -63,6 +63,14 @@ namespace osu.Game.Rulesets
|
|||||||
return string.Compare(ShortName, other.ShortName, StringComparison.Ordinal);
|
return string.Compare(ShortName, other.ShortName, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CompareTo(IRulesetInfo other)
|
||||||
|
{
|
||||||
|
if (!(other is RulesetInfo ruleset))
|
||||||
|
throw new ArgumentException($@"Object is not of type {nameof(RulesetInfo)}.", nameof(other));
|
||||||
|
|
||||||
|
return CompareTo(ruleset);
|
||||||
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
// Importantly, ignore the underlying realm hash code, as it will usually not match.
|
// Importantly, ignore the underlying realm hash code, as it will usually not match.
|
||||||
|
@ -851,7 +851,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
var difficultyItems = new List<MenuItem>();
|
var difficultyItems = new List<MenuItem>();
|
||||||
|
|
||||||
foreach (var rulesetBeatmaps in beatmapSet.Beatmaps.GroupBy(b => b.Ruleset.ShortName).OrderBy(group => group.Key))
|
foreach (var rulesetBeatmaps in beatmapSet.Beatmaps.GroupBy(b => b.Ruleset).OrderBy(group => group.Key))
|
||||||
{
|
{
|
||||||
if (difficultyItems.Count > 0)
|
if (difficultyItems.Count > 0)
|
||||||
difficultyItems.Add(new EditorMenuItemSpacer());
|
difficultyItems.Add(new EditorMenuItemSpacer());
|
||||||
|
@ -87,7 +87,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
var beatmaps = carouselSet.Beatmaps.ToList();
|
var beatmaps = carouselSet.Beatmaps.ToList();
|
||||||
|
|
||||||
return beatmaps.Count > maximum_difficulty_icons
|
return beatmaps.Count > maximum_difficulty_icons
|
||||||
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.BeatmapInfo.Ruleset.ShortName)
|
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.BeatmapInfo.Ruleset)
|
||||||
.Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Last().BeatmapInfo.Ruleset))
|
.Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Last().BeatmapInfo.Ruleset))
|
||||||
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
|
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user