Allow multiple ducks with same parameters

This commit is contained in:
Dean Herbert 2024-07-08 13:52:40 +09:00
parent aa36a844be
commit 3650f3c479
No known key found for this signature in database
2 changed files with 39 additions and 3 deletions

View File

@ -56,6 +56,45 @@ public void TestMultipleDucks()
AddUntilStep("wait for restore to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume).Within(0.01));
}
[Test]
public void TestMultipleDucksSameParameters()
{
var duckParameters = new DuckParameters
{
DuckVolumeTo = 0.5,
};
IDisposable duckOp1 = null!;
IDisposable duckOp2 = null!;
double normalVolume = 1;
AddStep("get initial volume", () =>
{
normalVolume = Game.Audio.Tracks.AggregateVolume.Value;
});
AddStep("duck one", () =>
{
duckOp1 = Game.MusicController.Duck(duckParameters);
});
AddUntilStep("wait for duck to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume * 0.5f).Within(0.01));
AddStep("duck two", () =>
{
duckOp2 = Game.MusicController.Duck(duckParameters);
});
AddUntilStep("wait for duck to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume * 0.5f).Within(0.01));
AddStep("restore two", () => duckOp2.Dispose());
AddUntilStep("wait for restore to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume * 0.5f).Within(0.01));
AddStep("restore one", () => duckOp1.Dispose());
AddUntilStep("wait for restore to complete", () => Game.Audio.Tracks.AggregateVolume.Value, () => Is.EqualTo(normalVolume).Within(0.01));
}
[Test]
public void TestMultipleDucksReverseOrder()
{

View File

@ -268,9 +268,6 @@ public IDisposable Duck(DuckParameters? parameters = null)
{
parameters ??= new DuckParameters();
if (duckOperations.Contains(parameters))
throw new ArgumentException("Ducking has already been applied for the provided parameters.", nameof(parameters));
duckOperations.Add(parameters);
DuckParameters volumeOperation = duckOperations.MinBy(p => p.DuckVolumeTo)!;