1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:43:05 +08:00

Take in IBindables and tidy up multiplier handling

This commit is contained in:
Dean Herbert 2023-10-18 17:39:11 +09:00
parent 161890292f
commit 9907adc337
No known key found for this signature in database

View File

@ -12,19 +12,39 @@ namespace osu.Game.Rulesets.Mods
/// </summary> /// </summary>
public class RateAdjustModHelper : IApplicableToTrack public class RateAdjustModHelper : IApplicableToTrack
{ {
private readonly BindableNumber<double> speedChange; public readonly IBindableNumber<double> SpeedChange;
private IAdjustableAudioComponent? track; private IAdjustableAudioComponent? track;
private BindableBool? adjustPitch; private BindableBool? adjustPitch;
/// <summary>
/// The score multiplier for the current <see cref="SpeedChange"/>.
/// </summary>
public double ScoreMultiplier
{
get
{
// Round to the nearest multiple of 0.1.
double value = (int)(SpeedChange.Value * 10) / 10.0;
// Offset back to 0.
value -= 1;
if (SpeedChange.Value >= 1)
value /= 5;
return 1 + value;
}
}
/// <summary> /// <summary>
/// Construct a new <see cref="RateAdjustModHelper"/>. /// Construct a new <see cref="RateAdjustModHelper"/>.
/// </summary> /// </summary>
/// <param name="speedChange">The main speed adjust parameter which is exposed to the user.</param> /// <param name="speedChange">The main speed adjust parameter which is exposed to the user.</param>
public RateAdjustModHelper(BindableNumber<double> speedChange) public RateAdjustModHelper(IBindableNumber<double> speedChange)
{ {
this.speedChange = speedChange; SpeedChange = speedChange;
} }
/// <summary> /// <summary>
@ -39,8 +59,8 @@ namespace osu.Game.Rulesets.Mods
// When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale. // When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale.
adjustPitch.BindValueChanged(adjustPitchSetting => adjustPitch.BindValueChanged(adjustPitchSetting =>
{ {
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), speedChange); track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), speedChange); track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue) AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo; => adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
@ -60,25 +80,5 @@ namespace osu.Game.Rulesets.Mods
this.track = track; this.track = track;
adjustPitch.TriggerChange(); adjustPitch.TriggerChange();
} }
/// <summary>
/// The score multiplier for the current <see cref="speedChange"/>.
/// </summary>
public double ScoreMultiplier
{
get
{
// Round to the nearest multiple of 0.1.
double value = (int)(speedChange.Value * 10) / 10.0;
// Offset back to 0.
value -= 1;
if (speedChange.Value >= 1)
value /= 5;
return 1 + value;
}
}
} }
} }