mirror of
https://github.com/ppy/osu.git
synced 2025-02-04 23:02:56 +08:00
Add RulesetInfo
hashcode implementation and tidy up equality
This commit is contained in:
parent
c33e163178
commit
5cbd731864
@ -255,7 +255,15 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
prepareTestAPI(true);
|
prepareTestAPI(true);
|
||||||
|
|
||||||
createPlayerTest(false, createRuleset: () => new OsuRuleset { RulesetInfo = { OnlineID = rulesetId ?? -1 } });
|
createPlayerTest(false, createRuleset: () => new OsuRuleset
|
||||||
|
{
|
||||||
|
RulesetInfo =
|
||||||
|
{
|
||||||
|
Name = "custom",
|
||||||
|
ShortName = $"custom{rulesetId}",
|
||||||
|
OnlineID = rulesetId ?? -1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
|
||||||
|
|
||||||
|
@ -47,14 +47,25 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
public bool Available { get; set; }
|
public bool Available { get; set; }
|
||||||
|
|
||||||
public bool Equals(RulesetInfo? other) => other != null
|
public bool Equals(RulesetInfo? other)
|
||||||
&& OnlineID == other.OnlineID
|
{
|
||||||
&& Available == other.Available
|
if (ReferenceEquals(this, other)) return true;
|
||||||
&& Name == other.Name
|
if (other == null) return false;
|
||||||
&& InstantiationInfo == other.InstantiationInfo;
|
|
||||||
|
return ShortName == other.ShortName;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
|
public bool Equals(IRulesetInfo? other) => other is RulesetInfo b && Equals(b);
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
// Importantly, ignore the underlying realm hash code, as it will usually not match.
|
||||||
|
var hashCode = new HashCode();
|
||||||
|
// ReSharper disable once NonReadonlyMemberInGetHashCode
|
||||||
|
hashCode.Add(ShortName);
|
||||||
|
return hashCode.ToHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() => Name;
|
public override string ToString() => Name;
|
||||||
|
|
||||||
public RulesetInfo Clone() => new RulesetInfo
|
public RulesetInfo Clone() => new RulesetInfo
|
||||||
|
Loading…
Reference in New Issue
Block a user