1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 01:42:55 +08:00

Make HitSampleInfo.Bank non-nullable

This commit is contained in:
Dean Herbert 2023-05-16 16:29:24 +09:00
parent 267e63320f
commit 83dcd78826
10 changed files with 35 additions and 22 deletions

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osuTK; using osuTK;
@ -44,7 +43,7 @@ namespace osu.Game.Rulesets.Pippidon.Objects.Drawables
public override IEnumerable<HitSampleInfo> GetSamples() => new[] public override IEnumerable<HitSampleInfo> GetSamples() => new[]
{ {
new HitSampleInfo(HitSampleInfo.HIT_NORMAL, SampleControlPoint.DEFAULT_BANK) new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
}; };
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Pippidon.UI; using osu.Game.Rulesets.Pippidon.UI;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -44,7 +43,7 @@ namespace osu.Game.Rulesets.Pippidon.Objects.Drawables
public override IEnumerable<HitSampleInfo> GetSamples() => new[] public override IEnumerable<HitSampleInfo> GetSamples() => new[]
{ {
new HitSampleInfo(HitSampleInfo.HIT_NORMAL, SampleControlPoint.DEFAULT_BANK) new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
}; };
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)

View File

@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Catch.Tests
NewCombo = i % 8 == 0, NewCombo = i % 8 == 0,
Samples = new List<HitSampleInfo>(new[] Samples = new List<HitSampleInfo>(new[]
{ {
new HitSampleInfo(HitSampleInfo.HIT_NORMAL, "normal", volume: 100) new HitSampleInfo(HitSampleInfo.HIT_NORMAL, volume: 100)
}) })
}); });
} }

View File

@ -74,7 +74,7 @@ namespace osu.Game.Rulesets.Osu.Tests
EndTime = Time.Current + delay + length, EndTime = Time.Current + delay + length,
Samples = new List<HitSampleInfo> Samples = new List<HitSampleInfo>
{ {
new HitSampleInfo("hitnormal") new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
} }
}; };

View File

@ -42,7 +42,7 @@ namespace osu.Game.Tests.Visual.Editing
Position = (OsuPlayfield.BASE_SIZE - new Vector2(100, 0)) / 2, Position = (OsuPlayfield.BASE_SIZE - new Vector2(100, 0)) / 2,
Samples = new List<HitSampleInfo> Samples = new List<HitSampleInfo>
{ {
new HitSampleInfo(HitSampleInfo.HIT_NORMAL, "normal", volume: 80) new HitSampleInfo(HitSampleInfo.HIT_NORMAL, volume: 80)
} }
}); });

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Utils; using osu.Game.Utils;
namespace osu.Game.Audio namespace osu.Game.Audio
@ -32,7 +33,7 @@ namespace osu.Game.Audio
/// <summary> /// <summary>
/// The bank to load the sample from. /// The bank to load the sample from.
/// </summary> /// </summary>
public readonly string? Bank; public readonly string Bank;
/// <summary> /// <summary>
/// An optional suffix to provide priority lookup. Falls back to non-suffixed <see cref="Name"/>. /// An optional suffix to provide priority lookup. Falls back to non-suffixed <see cref="Name"/>.
@ -44,7 +45,7 @@ namespace osu.Game.Audio
/// </summary> /// </summary>
public int Volume { get; } public int Volume { get; }
public HitSampleInfo(string name, string? bank = null, string? suffix = null, int volume = 0) public HitSampleInfo(string name, string bank = SampleControlPoint.DEFAULT_BANK, string? suffix = null, int volume = 0)
{ {
Name = name; Name = name;
Bank = bank; Bank = bank;
@ -76,7 +77,7 @@ namespace osu.Game.Audio
/// <param name="newVolume">An optional new volume.</param> /// <param name="newVolume">An optional new volume.</param>
/// <returns>The new <see cref="HitSampleInfo"/>.</returns> /// <returns>The new <see cref="HitSampleInfo"/>.</returns>
public virtual HitSampleInfo With(Optional<string> newName = default, Optional<string?> newBank = default, Optional<string?> newSuffix = default, Optional<int> newVolume = default) 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)); => new HitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank) ?? Bank, newSuffix.GetOr(Suffix), newVolume.GetOr(Volume));
public bool Equals(HitSampleInfo? other) public bool Equals(HitSampleInfo? other)
=> other != null && Name == other.Name && Bank == other.Bank && Suffix == other.Suffix; => other != null && Name == other.Name && Bank == other.Bank && Suffix == other.Suffix;

View File

@ -69,7 +69,7 @@ namespace osu.Game.Beatmaps.ControlPoints
/// <param name="hitSampleInfo">The <see cref="HitSampleInfo"/>. This will not be modified.</param> /// <param name="hitSampleInfo">The <see cref="HitSampleInfo"/>. This will not be modified.</param>
/// <returns>The modified <see cref="HitSampleInfo"/>. This does not share a reference with <paramref name="hitSampleInfo"/>.</returns> /// <returns>The modified <see cref="HitSampleInfo"/>. This does not share a reference with <paramref name="hitSampleInfo"/>.</returns>
public virtual HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo) public virtual HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo)
=> hitSampleInfo.With(newBank: hitSampleInfo.Bank ?? SampleBank, newVolume: hitSampleInfo.Volume > 0 ? hitSampleInfo.Volume : SampleVolume); => hitSampleInfo.With(newBank: hitSampleInfo.Bank, newVolume: hitSampleInfo.Volume > 0 ? hitSampleInfo.Volume : SampleVolume);
public override bool IsRedundant(ControlPoint? existing) public override bool IsRedundant(ControlPoint? existing)
=> existing is SampleControlPoint existingSample => existing is SampleControlPoint existingSample

View File

@ -226,12 +226,16 @@ namespace osu.Game.Beatmaps.Formats
public override HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo) public override HitSampleInfo ApplyTo(HitSampleInfo hitSampleInfo)
{ {
var baseInfo = base.ApplyTo(hitSampleInfo); if (hitSampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacy)
{
return legacy.With(
newCustomSampleBank: legacy.CustomSampleBank > 0 ? legacy.CustomSampleBank : CustomSampleBank,
newVolume: hitSampleInfo.Volume > 0 ? hitSampleInfo.Volume : SampleVolume,
newBank: legacy.BankSpecified ? legacy.Bank : SampleBank
);
}
if (baseInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacy && legacy.CustomSampleBank == 0) return base.ApplyTo(hitSampleInfo);
return legacy.With(newCustomSampleBank: CustomSampleBank);
return baseInfo;
} }
public override bool IsRedundant(ControlPoint? existing) public override bool IsRedundant(ControlPoint? existing)

View File

@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Edit
HitObject = hitObject; HitObject = hitObject;
// adding the default hit sample should be the case regardless of the ruleset. // adding the default hit sample should be the case regardless of the ruleset.
HitObject.Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_NORMAL, SampleControlPoint.DEFAULT_BANK, volume: 100)); HitObject.Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_NORMAL, volume: 100));
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;

View File

@ -14,6 +14,7 @@ using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Legacy; using osu.Game.Beatmaps.Legacy;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Game.Utils; using osu.Game.Utils;
@ -446,9 +447,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
if (string.IsNullOrEmpty(bankInfo.Filename)) if (string.IsNullOrEmpty(bankInfo.Filename))
{ {
soundTypes.Add(new LegacyHitSampleInfo(HitSampleInfo.HIT_NORMAL, bankInfo.BankForNormal, bankInfo.Volume, bankInfo.CustomSampleBank, soundTypes.Add(new LegacyHitSampleInfo(HitSampleInfo.HIT_NORMAL, bankInfo.BankForNormal, bankInfo.Volume, bankInfo.CustomSampleBank,
// if the sound type doesn't have the Normal flag set, attach it anyway as a layered sample. // if the sound type doesn't have the Normal flag set, attach it anyway as a layered sample.
// None also counts as a normal non-layered sample: https://osu.ppy.sh/help/wiki/osu!_File_Formats/Osu_(file_format)#hitsounds // None also counts as a normal non-layered sample: https://osu.ppy.sh/help/wiki/osu!_File_Formats/Osu_(file_format)#hitsounds
type != LegacyHitSoundType.None && !type.HasFlagFast(LegacyHitSoundType.Normal))); type != LegacyHitSoundType.None && !type.HasFlagFast(LegacyHitSoundType.Normal)));
} }
else else
{ {
@ -479,12 +480,14 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// The bank identifier to use for the base ("hitnormal") sample. /// The bank identifier to use for the base ("hitnormal") sample.
/// Transferred to <see cref="HitSampleInfo.Bank"/> when appropriate. /// Transferred to <see cref="HitSampleInfo.Bank"/> when appropriate.
/// </summary> /// </summary>
[CanBeNull]
public string BankForNormal; public string BankForNormal;
/// <summary> /// <summary>
/// The bank identifier to use for additions ("hitwhistle", "hitfinish", "hitclap"). /// The bank identifier to use for additions ("hitwhistle", "hitfinish", "hitclap").
/// Transferred to <see cref="HitSampleInfo.Bank"/> when appropriate. /// Transferred to <see cref="HitSampleInfo.Bank"/> when appropriate.
/// </summary> /// </summary>
[CanBeNull]
public string BankForAdditions; public string BankForAdditions;
/// <summary> /// <summary>
@ -518,10 +521,17 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// </remarks> /// </remarks>
public readonly bool IsLayered; public readonly bool IsLayered;
/// <summary>
/// Whether a bank was specified locally to the relevant hitobject.
/// If <c>false</c>, a bank will be retrieved from the closest control point.
/// </summary>
public bool BankSpecified;
public LegacyHitSampleInfo(string name, string? bank = null, int volume = 0, int customSampleBank = 0, bool isLayered = false) public LegacyHitSampleInfo(string name, string? bank = null, int volume = 0, int customSampleBank = 0, bool isLayered = false)
: base(name, bank, customSampleBank >= 2 ? customSampleBank.ToString() : null, volume) : base(name, bank ?? SampleControlPoint.DEFAULT_BANK, customSampleBank >= 2 ? customSampleBank.ToString() : null, volume)
{ {
CustomSampleBank = customSampleBank; CustomSampleBank = customSampleBank;
BankSpecified = !string.IsNullOrEmpty(bank);
IsLayered = isLayered; IsLayered = isLayered;
} }
@ -531,7 +541,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
public virtual LegacyHitSampleInfo With(Optional<string> newName = default, Optional<string?> newBank = default, Optional<int> newVolume = default, public virtual LegacyHitSampleInfo With(Optional<string> newName = default, Optional<string?> newBank = default, Optional<int> newVolume = default,
Optional<int> newCustomSampleBank = default, Optional<int> newCustomSampleBank = default,
Optional<bool> newIsLayered = default) Optional<bool> newIsLayered = default)
=> new LegacyHitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newVolume.GetOr(Volume), newCustomSampleBank.GetOr(CustomSampleBank), newIsLayered.GetOr(IsLayered)); => new LegacyHitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank) ?? Bank, newVolume.GetOr(Volume), newCustomSampleBank.GetOr(CustomSampleBank), newIsLayered.GetOr(IsLayered));
public bool Equals(LegacyHitSampleInfo? other) public bool Equals(LegacyHitSampleInfo? other)
// The additions to equality checks here are *required* to ensure that pooling works correctly. // The additions to equality checks here are *required* to ensure that pooling works correctly.