mirror of
https://github.com/ppy/osu
synced 2024-12-23 23:33:36 +00:00
Introduce private APIRuleset
for online ID equality comparison
This commit is contained in:
parent
c29cc78853
commit
92e22c57a7
@ -98,7 +98,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
|
||||
public string MD5Hash => Checksum;
|
||||
|
||||
public IRulesetInfo Ruleset => new RulesetInfo { OnlineID = RulesetID };
|
||||
public IRulesetInfo Ruleset => new APIRuleset { OnlineID = RulesetID };
|
||||
|
||||
[JsonIgnore]
|
||||
public string Hash => throw new NotImplementedException();
|
||||
@ -106,5 +106,29 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
#endregion
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,6 @@ namespace osu.Game.Rulesets
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (OnlineID >= 0 && other.OnlineID >= 0)
|
||||
return OnlineID == other.OnlineID;
|
||||
|
||||
return ShortName == other.ShortName;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user