1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 13:03:21 +08:00

Merge pull request #25343 from peppy/spinner-max-sample

Continue to play spinner bonus sounds when MAX display occurs
This commit is contained in:
Bartłomiej Dach 2023-11-09 13:34:29 +01:00 committed by GitHub
commit 5180fa669b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
@ -36,6 +37,12 @@ namespace osu.Game.Rulesets.Osu.Tests
AddSliderStep("Spin rate", 0.5, 5, 1, val => spinRate.Value = val);
}
[SetUpSteps]
public void SetUpSteps()
{
AddStep("Reset rate", () => spinRate.Value = 1);
}
[TestCase(true)]
[TestCase(false)]
public void TestVariousSpinners(bool autoplay)
@ -46,6 +53,36 @@ namespace osu.Game.Rulesets.Osu.Tests
AddStep($"{term} Small", () => SetContents(_ => testSingle(7, autoplay)));
}
[Test]
public void TestSpinnerNoBonus()
{
AddStep("Set high spin rate", () => spinRate.Value = 5);
Spinner spinner;
AddStep("add spinner", () => SetContents(_ =>
{
spinner = new Spinner
{
StartTime = Time.Current,
EndTime = Time.Current + 750,
Samples = new List<HitSampleInfo>
{
new HitSampleInfo(HitSampleInfo.HIT_NORMAL)
}
};
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { OverallDifficulty = 0 });
return drawableSpinner = new TestDrawableSpinner(spinner, true, spinRate)
{
Anchor = Anchor.Centre,
Depth = depthIndex++,
Scale = new Vector2(0.75f)
};
}));
}
[Test]
public void TestSpinningSamplePitchShift()
{
@ -153,7 +190,7 @@ namespace osu.Game.Rulesets.Osu.Tests
{
base.Update();
if (auto)
RotationTracker.AddRotation((float)(Clock.ElapsedFrameTime * spinRate.Value));
RotationTracker.AddRotation((float)Math.Min(180, Clock.ElapsedFrameTime * spinRate.Value));
}
}
}

View File

@ -4,6 +4,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
@ -45,6 +46,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private const float spinning_sample_initial_frequency = 1.0f;
private const float spinning_sample_modulated_base_frequency = 0.5f;
private SkinnableSound maxBonusSample;
/// <summary>
/// The amount of bonus score gained from spinning after the required number of spins, for display purposes.
/// </summary>
@ -109,6 +112,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
Looping = true,
Frequency = { Value = spinning_sample_initial_frequency }
},
maxBonusSample = new SkinnableSound
{
MinimumSampleVolume = MINIMUM_SAMPLE_VOLUME,
}
});
@ -128,6 +135,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
base.OnFree();
spinningSample.ClearSamples();
maxBonusSample.ClearSamples();
}
protected override void LoadSamples()
@ -136,6 +144,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
spinningSample.Samples = HitObject.CreateSpinningSamples().Cast<ISampleInfo>().ToArray();
spinningSample.Frequency.Value = spinning_sample_initial_frequency;
maxBonusSample.Samples = new ISampleInfo[] { new SpinnerBonusMaxSampleInfo(HitObject.CreateHitSampleInfo()) };
}
private void updateSpinningSample(ValueChangedEvent<bool> tracking)
@ -157,6 +167,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
base.StopAllSamples();
spinningSample?.Stop();
maxBonusSample?.Stop();
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)
@ -322,10 +333,38 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
var tick = ticks.FirstOrDefault(t => !t.Result.HasResult);
// tick may be null if we've hit the spin limit.
tick?.TriggerResult(true);
if (tick == null)
{
// we still want to play a sound. this will probably be a new sound in the future, but for now let's continue playing the bonus sound.
// TODO: this doesn't concurrency. i can't figure out how to make it concurrency. samples are bad and need a refactor.
maxBonusSample.Play();
}
else
tick.TriggerResult(true);
completedFullSpins.Value++;
}
}
public class SpinnerBonusMaxSampleInfo : HitSampleInfo
{
public override IEnumerable<string> LookupNames
{
get
{
foreach (string name in base.LookupNames)
yield return name;
foreach (string name in base.LookupNames)
yield return name.Replace("-max", string.Empty);
}
}
public SpinnerBonusMaxSampleInfo(HitSampleInfo sampleInfo)
: base("spinnerbonus-max", sampleInfo.Bank, sampleInfo.Suffix, sampleInfo.Volume)
{
}
}
}
}