Make HitSampleInfo immutable

This commit is contained in:
smoogipoo
2020-12-01 15:37:51 +09:00
parent 76919a5772
commit 5760e1c1fc
19 changed files with 144 additions and 126 deletions

View File

@ -1,8 +1,11 @@
// 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.
#nullable enable
using System;
using System.Collections.Generic;
using osu.Game.Utils;
namespace osu.Game.Audio
{
@ -22,25 +25,33 @@ namespace osu.Game.Audio
/// </summary>
public static IEnumerable<string> AllAdditions => new[] { HIT_WHISTLE, HIT_CLAP, HIT_FINISH };
/// <summary>
/// The bank to load the sample from.
/// </summary>
public string Bank;
/// <summary>
/// The name of the sample to load.
/// </summary>
public string Name;
public readonly string Name;
/// <summary>
/// The bank to load the sample from.
/// </summary>
public readonly string? Bank;
/// <summary>
/// An optional suffix to provide priority lookup. Falls back to non-suffixed <see cref="Name"/>.
/// </summary>
public string Suffix;
public readonly string? Suffix;
/// <summary>
/// The sample volume.
/// </summary>
public int Volume { get; set; }
public int Volume { get; }
public HitSampleInfo(string name, string? bank = null, string? suffix = null, int volume = 100)
{
Name = name;
Bank = bank;
Suffix = suffix;
Volume = volume;
}
/// <summary>
/// Retrieve all possible filenames that can be used as a source, returned in order of preference (highest first).
@ -56,6 +67,15 @@ namespace osu.Game.Audio
}
}
public HitSampleInfo Clone() => (HitSampleInfo)MemberwiseClone();
/// <summary>
/// Creates a new <see cref="HitSampleInfo"/> with overridden values.
/// </summary>
/// <param name="name">An optional new sample name.</param>
/// <param name="bank">An optional new sample bank.</param>
/// <param name="suffix">An optional new lookup suffix.</param>
/// <param name="volume">An optional new volume.</param>
/// <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)
=> new HitSampleInfo(name.GetOr(Name), bank.GetOr(Bank), suffix.GetOr(Suffix), volume.GetOr(Volume));
}
}