mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Expose balance and sample loading methods in DrawableHitObject
This commit is contained in:
@ -126,7 +126,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
if (Result == null)
|
if (Result == null)
|
||||||
throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
|
throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
|
||||||
|
|
||||||
loadSamples();
|
LoadSamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -145,14 +145,14 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
}
|
}
|
||||||
|
|
||||||
samplesBindable = HitObject.SamplesBindable.GetBoundCopy();
|
samplesBindable = HitObject.SamplesBindable.GetBoundCopy();
|
||||||
samplesBindable.CollectionChanged += (_, __) => loadSamples();
|
samplesBindable.CollectionChanged += (_, __) => LoadSamples();
|
||||||
|
|
||||||
apply(HitObject);
|
apply(HitObject);
|
||||||
|
|
||||||
updateState(ArmedState.Idle, true);
|
updateState(ArmedState.Idle, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSamples()
|
protected virtual void LoadSamples()
|
||||||
{
|
{
|
||||||
if (Samples != null)
|
if (Samples != null)
|
||||||
{
|
{
|
||||||
@ -353,17 +353,32 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private GameplayClock gameplayClock { get; set; }
|
private GameplayClock gameplayClock { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate the position to be used for sample playback at a specified X position (0..1).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">The lookup X position. Generally should be <see cref="SamplePlaybackPosition"/>.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected double CalculateSamplePlaybackBalance(double position)
|
||||||
|
{
|
||||||
|
const float balance_adjust_amount = 0.4f;
|
||||||
|
|
||||||
|
return balance_adjust_amount * (userPositionalHitSounds.Value ? position - 0.5f : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether samples should currently be playing. Will be false during seek operations.
|
||||||
|
/// </summary>
|
||||||
|
protected bool ShouldPlaySamples => gameplayClock?.IsSeeking != true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plays all the hit sounds for this <see cref="DrawableHitObject"/>.
|
/// Plays all the hit sounds for this <see cref="DrawableHitObject"/>.
|
||||||
/// This is invoked automatically when this <see cref="DrawableHitObject"/> is hit.
|
/// This is invoked automatically when this <see cref="DrawableHitObject"/> is hit.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void PlaySamples()
|
public virtual void PlaySamples()
|
||||||
{
|
{
|
||||||
const float balance_adjust_amount = 0.4f;
|
if (Samples != null && ShouldPlaySamples)
|
||||||
|
|
||||||
if (Samples != null && gameplayClock?.IsSeeking != true)
|
|
||||||
{
|
{
|
||||||
Samples.Balance.Value = balance_adjust_amount * (userPositionalHitSounds.Value ? SamplePlaybackPosition - 0.5f : 0);
|
Samples.Balance.Value = CalculateSamplePlaybackBalance(SamplePlaybackPosition);
|
||||||
Samples.Play();
|
Samples.Play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user