// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Utils; namespace osu.Game.Audio { /// /// Describes a gameplay hit sample. /// [Serializable] public class HitSampleInfo : ISampleInfo, IEquatable { public const string HIT_NORMAL = @"hitnormal"; public const string HIT_WHISTLE = @"hitwhistle"; public const string HIT_FINISH = @"hitfinish"; public const string HIT_CLAP = @"hitclap"; public const string BANK_NORMAL = @"normal"; public const string BANK_SOFT = @"soft"; public const string BANK_DRUM = @"drum"; // new sample used exclusively by taiko for now. public const string HIT_FLOURISH = "hitflourish"; // new bank used exclusively by taiko for now. public const string BANK_STRONG = @"strong"; /// /// All valid sample addition constants. /// public static IEnumerable AllAdditions => new[] { HIT_WHISTLE, HIT_FINISH, HIT_CLAP }; /// /// All valid bank constants. /// public static IEnumerable AllBanks => new[] { BANK_NORMAL, BANK_SOFT, BANK_DRUM }; /// /// The name of the sample to load. /// public readonly string Name; /// /// The bank to load the sample from. /// public readonly string Bank; /// /// An optional suffix to provide priority lookup. Falls back to non-suffixed . /// public readonly string? Suffix; /// /// The sample volume. /// public int Volume { get; } /// /// Whether this sample should automatically assign the bank of the normal sample whenever it is set in the editor. /// public bool EditorAutoBank { get; } public HitSampleInfo(string name, string bank = SampleControlPoint.DEFAULT_BANK, string? suffix = null, int volume = 100, bool editorAutoBank = true) { Name = name; Bank = bank; Suffix = suffix; Volume = volume; EditorAutoBank = editorAutoBank; } /// /// Retrieve all possible filenames that can be used as a source, returned in order of preference (highest first). /// [JsonIgnore] public virtual IEnumerable LookupNames { get { if (!string.IsNullOrEmpty(Suffix)) yield return $"Gameplay/{Bank}-{Name}{Suffix}"; yield return $"Gameplay/{Bank}-{Name}"; yield return $"Gameplay/{Name}"; } } /// /// Creates a new with overridden values. /// /// An optional new sample name. /// An optional new sample bank. /// An optional new lookup suffix. /// An optional new volume. /// An optional new editor auto bank flag. /// The new . public virtual HitSampleInfo With(Optional newName = default, Optional newBank = default, Optional newSuffix = default, Optional newVolume = default, Optional newEditorAutoBank = default) => new HitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newSuffix.GetOr(Suffix), newVolume.GetOr(Volume), newEditorAutoBank.GetOr(EditorAutoBank)); public virtual bool Equals(HitSampleInfo? other) => other != null && Name == other.Name && Bank == other.Bank && Suffix == other.Suffix; public override bool Equals(object? obj) => obj is HitSampleInfo other && Equals(other); public override int GetHashCode() => HashCode.Combine(Name, Bank, Suffix); } }