2019-06-30 12:58:30 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-12-01 09:09:28 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2020-12-01 06:37:51 +00:00
|
|
|
|
using osu.Game.Utils;
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Audio
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Describes a gameplay hit sample.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
2020-12-01 06:44:16 +00:00
|
|
|
|
public class HitSampleInfo : ISampleInfo, IEquatable<HitSampleInfo>
|
2019-06-30 12:58:30 +00:00
|
|
|
|
{
|
2022-07-19 13:36:07 +00:00
|
|
|
|
public const string HIT_NORMAL = @"hitnormal";
|
2019-06-30 12:58:30 +00:00
|
|
|
|
public const string HIT_WHISTLE = @"hitwhistle";
|
|
|
|
|
public const string HIT_FINISH = @"hitfinish";
|
|
|
|
|
public const string HIT_CLAP = @"hitclap";
|
|
|
|
|
|
2020-09-25 08:30:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// All valid sample addition constants.
|
|
|
|
|
/// </summary>
|
2022-07-19 13:36:07 +00:00
|
|
|
|
public static IEnumerable<string> AllAdditions => new[] { HIT_WHISTLE, HIT_FINISH, HIT_CLAP };
|
2020-09-25 08:30:31 +00:00
|
|
|
|
|
2019-06-30 12:58:30 +00:00
|
|
|
|
/// <summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
/// The name of the sample to load.
|
2019-06-30 12:58:30 +00:00
|
|
|
|
/// </summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
public readonly string Name;
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
/// The bank to load the sample from.
|
2019-06-30 12:58:30 +00:00
|
|
|
|
/// </summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
public readonly string? Bank;
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An optional suffix to provide priority lookup. Falls back to non-suffixed <see cref="Name"/>.
|
|
|
|
|
/// </summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
public readonly string? Suffix;
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The sample volume.
|
|
|
|
|
/// </summary>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
public int Volume { get; }
|
|
|
|
|
|
2020-12-01 09:09:28 +00:00
|
|
|
|
public HitSampleInfo(string name, string? bank = null, string? suffix = null, int volume = 0)
|
2020-12-01 06:37:51 +00:00
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Bank = bank;
|
|
|
|
|
Suffix = suffix;
|
|
|
|
|
Volume = volume;
|
|
|
|
|
}
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Retrieve all possible filenames that can be used as a source, returned in order of preference (highest first).
|
|
|
|
|
/// </summary>
|
2020-12-01 09:08:59 +00:00
|
|
|
|
[JsonIgnore]
|
2019-06-30 12:58:30 +00:00
|
|
|
|
public virtual IEnumerable<string> LookupNames
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(Suffix))
|
2020-10-29 07:32:20 +00:00
|
|
|
|
yield return $"Gameplay/{Bank}-{Name}{Suffix}";
|
2019-06-30 12:58:30 +00:00
|
|
|
|
|
2020-10-29 07:32:20 +00:00
|
|
|
|
yield return $"Gameplay/{Bank}-{Name}";
|
2019-06-30 12:58:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 06:37:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new <see cref="HitSampleInfo"/> with overridden values.
|
|
|
|
|
/// </summary>
|
2020-12-02 01:55:48 +00:00
|
|
|
|
/// <param name="newName">An optional new sample name.</param>
|
|
|
|
|
/// <param name="newBank">An optional new sample bank.</param>
|
|
|
|
|
/// <param name="newSuffix">An optional new lookup suffix.</param>
|
|
|
|
|
/// <param name="newVolume">An optional new volume.</param>
|
2020-12-01 06:37:51 +00:00
|
|
|
|
/// <returns>The new <see cref="HitSampleInfo"/>.</returns>
|
2020-12-02 01:55:48 +00:00
|
|
|
|
public virtual HitSampleInfo With(Optional<string> newName = default, Optional<string?> newBank = default, Optional<string?> newSuffix = default, Optional<int> newVolume = default)
|
|
|
|
|
=> new HitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newSuffix.GetOr(Suffix), newVolume.GetOr(Volume));
|
2020-12-01 06:44:16 +00:00
|
|
|
|
|
|
|
|
|
public bool Equals(HitSampleInfo? other)
|
|
|
|
|
=> other != null && Name == other.Name && Bank == other.Bank && Suffix == other.Suffix;
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
2020-12-01 09:09:21 +00:00
|
|
|
|
=> obj is HitSampleInfo other && Equals(other);
|
2020-12-01 06:44:16 +00:00
|
|
|
|
|
|
|
|
|
public override int GetHashCode() => HashCode.Combine(Name, Bank, Suffix);
|
2019-06-30 12:58:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|