Skip to content

Commit

Permalink
Introduce private APIRuleset for online ID equality comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Feb 11, 2022
1 parent c29cc78 commit 92e22c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 25 additions & 1 deletion osu.Game/Online/API/Requests/Responses/APIBeatmap.cs
Expand Up @@ -98,13 +98,37 @@ private double lengthInSeconds

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();

#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;
}
}
}
3 changes: 0 additions & 3 deletions osu.Game/Rulesets/RulesetInfo.cs
Expand Up @@ -44,9 +44,6 @@ public bool Equals(RulesetInfo? other)
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;
}

Expand Down

0 comments on commit 92e22c5

Please sign in to comment.