mirror of
https://github.com/ppy/osu.git
synced 2025-03-03 20:02:54 +08:00
Implement equality comparers for HitSampleInfo
This commit is contained in:
parent
5760e1c1fc
commit
199710b941
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
@ -50,16 +51,24 @@ namespace osu.Game.Rulesets.Catch.Objects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BananaHitSampleInfo : HitSampleInfo
|
private class BananaHitSampleInfo : HitSampleInfo, IEquatable<BananaHitSampleInfo>
|
||||||
{
|
{
|
||||||
private static string[] lookupNames { get; } = { "metronomelow", "catch-banana" };
|
private static readonly string[] lookup_names = { "metronomelow", "catch-banana" };
|
||||||
|
|
||||||
public override IEnumerable<string> LookupNames => lookupNames;
|
public override IEnumerable<string> LookupNames => lookup_names;
|
||||||
|
|
||||||
public BananaHitSampleInfo()
|
public BananaHitSampleInfo()
|
||||||
: base(string.Empty)
|
: base(string.Empty)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Equals(BananaHitSampleInfo other)
|
||||||
|
=> other != null;
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
=> Equals((BananaHitSampleInfo)obj);
|
||||||
|
|
||||||
|
public override int GetHashCode() => lookup_names.GetHashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace osu.Game.Audio
|
|||||||
/// Describes a gameplay hit sample.
|
/// Describes a gameplay hit sample.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class HitSampleInfo : ISampleInfo
|
public class HitSampleInfo : ISampleInfo, IEquatable<HitSampleInfo>
|
||||||
{
|
{
|
||||||
public const string HIT_WHISTLE = @"hitwhistle";
|
public const string HIT_WHISTLE = @"hitwhistle";
|
||||||
public const string HIT_FINISH = @"hitfinish";
|
public const string HIT_FINISH = @"hitfinish";
|
||||||
@ -77,5 +77,13 @@ namespace osu.Game.Audio
|
|||||||
/// <returns>The new <see cref="HitSampleInfo"/>.</returns>
|
/// <returns>The new <see cref="HitSampleInfo"/>.</returns>
|
||||||
public virtual HitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<string?> suffix = default, Optional<int> volume = default)
|
public virtual HitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<string?> suffix = default, Optional<int> volume = default)
|
||||||
=> new HitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), suffix.GetOr(Suffix), volume.GetOr(Volume));
|
=> new HitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), suffix.GetOr(Suffix), volume.GetOr(Volume));
|
||||||
|
|
||||||
|
public bool Equals(HitSampleInfo? other)
|
||||||
|
=> other != null && Name == other.Name && Bank == other.Bank && Suffix == other.Suffix;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
=> Equals((HitSampleInfo?)obj);
|
||||||
|
|
||||||
|
public override int GetHashCode() => HashCode.Combine(Name, Bank, Suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
public class LegacyHitSampleInfo : HitSampleInfo
|
public class LegacyHitSampleInfo : HitSampleInfo, IEquatable<LegacyHitSampleInfo>
|
||||||
{
|
{
|
||||||
public readonly int CustomSampleBank;
|
public readonly int CustomSampleBank;
|
||||||
|
|
||||||
@ -492,9 +492,16 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
public LegacyHitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<int> volume = default, Optional<int> customSampleBank = default,
|
public LegacyHitSampleInfo With(Optional<string> name = default, Optional<string?> bank = default, Optional<int> volume = default, Optional<int> customSampleBank = default,
|
||||||
Optional<bool> isLayered = default)
|
Optional<bool> isLayered = default)
|
||||||
=> new LegacyHitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), volume.GetOr(Volume), customSampleBank.GetOr(CustomSampleBank), isLayered.GetOr(IsLayered));
|
=> new LegacyHitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), volume.GetOr(Volume), customSampleBank.GetOr(CustomSampleBank), isLayered.GetOr(IsLayered));
|
||||||
|
|
||||||
|
public bool Equals(LegacyHitSampleInfo? other)
|
||||||
|
=> base.Equals(other) && CustomSampleBank == other.CustomSampleBank && IsLayered == other.IsLayered;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj) => Equals((LegacyHitSampleInfo?)obj);
|
||||||
|
|
||||||
|
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank, IsLayered);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FileHitSampleInfo : LegacyHitSampleInfo
|
private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo>
|
||||||
{
|
{
|
||||||
public readonly string Filename;
|
public readonly string Filename;
|
||||||
|
|
||||||
@ -517,6 +524,14 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
|||||||
|
|
||||||
public FileHitSampleInfo With(Optional<string> filename = default, Optional<int> volume = default)
|
public FileHitSampleInfo With(Optional<string> filename = default, Optional<int> volume = default)
|
||||||
=> new FileHitSampleInfo(filename.GetOr(Filename), volume.GetOr(Volume));
|
=> new FileHitSampleInfo(filename.GetOr(Filename), volume.GetOr(Volume));
|
||||||
|
|
||||||
|
public bool Equals(FileHitSampleInfo? other)
|
||||||
|
=> base.Equals(other) && Filename == other.Filename;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
=> Equals((FileHitSampleInfo?)obj);
|
||||||
|
|
||||||
|
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
Loading…
Reference in New Issue
Block a user