Introduce private APIRuleset for online ID equality comparison

This commit is contained in:
Salman Ahmed 2022-02-11 08:02:51 +03:00
parent c29cc78853
commit 92e22c57a7
2 changed files with 25 additions and 4 deletions

View File

@ -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;
}
} }
} }

View File

@ -44,9 +44,6 @@ namespace osu.Game.Rulesets
if (ReferenceEquals(this, other)) return true; if (ReferenceEquals(this, other)) return true;
if (other == null) return false; if (other == null) return false;
if (OnlineID >= 0 && other.OnlineID >= 0)
return OnlineID == other.OnlineID;
return ShortName == other.ShortName; return ShortName == other.ShortName;
} }