mirror of
https://github.com/ppy/osu
synced 2025-01-11 08:39:31 +00:00
Handle type/strength changes from samples changes
This commit is contained in:
parent
8f3eb9a422
commit
9a0e5ac154
@ -89,9 +89,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
|
||||
private SkinnableSound slidingSample;
|
||||
|
||||
protected override void LoadSamples()
|
||||
protected override void LoadSamples(bool changed)
|
||||
{
|
||||
base.LoadSamples();
|
||||
base.LoadSamples(changed);
|
||||
|
||||
slidingSample?.Expire();
|
||||
slidingSample = null;
|
||||
|
@ -88,9 +88,9 @@ 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;
|
||||
|
||||
protected override void LoadSamples()
|
||||
protected override void LoadSamples(bool changed)
|
||||
{
|
||||
base.LoadSamples();
|
||||
base.LoadSamples(changed);
|
||||
|
||||
spinningSample?.Expire();
|
||||
spinningSample = null;
|
||||
|
@ -61,19 +61,29 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
});
|
||||
}
|
||||
|
||||
private HitSampleInfo[] rimSamples => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE).ToArray();
|
||||
|
||||
protected override void LoadSamples(bool changed)
|
||||
{
|
||||
base.LoadSamples(changed);
|
||||
|
||||
if (changed)
|
||||
type.Value = rimSamples.Any() ? HitType.Rim : HitType.Centre;
|
||||
}
|
||||
|
||||
private void updateSamplesFromTypeChange()
|
||||
{
|
||||
var rimSamples = HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE).ToArray();
|
||||
var samples = rimSamples;
|
||||
|
||||
bool isRimType = HitObject.Type == HitType.Rim;
|
||||
|
||||
if (isRimType != rimSamples.Any())
|
||||
if (isRimType != samples.Any())
|
||||
{
|
||||
if (isRimType)
|
||||
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_CLAP });
|
||||
else
|
||||
{
|
||||
foreach (var sample in rimSamples)
|
||||
foreach (var sample in samples)
|
||||
HitObject.Samples.Remove(sample);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osuTK;
|
||||
using System.Linq;
|
||||
using osu.Game.Audio;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
{
|
||||
@ -152,17 +152,27 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
RecreatePieces();
|
||||
}
|
||||
|
||||
private HitSampleInfo[] strongSamples => HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_FINISH).ToArray();
|
||||
|
||||
protected override void LoadSamples(bool changed)
|
||||
{
|
||||
base.LoadSamples(changed);
|
||||
|
||||
if (changed)
|
||||
isStrong.Value = strongSamples.Any();
|
||||
}
|
||||
|
||||
private void updateSamplesFromStrong()
|
||||
{
|
||||
var strongSamples = HitObject.Samples.Where(s => s.Name == HitSampleInfo.HIT_FINISH).ToArray();
|
||||
var samples = strongSamples;
|
||||
|
||||
if (isStrong.Value != strongSamples.Any())
|
||||
if (isStrong.Value != samples.Any())
|
||||
{
|
||||
if (isStrong.Value)
|
||||
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH });
|
||||
else
|
||||
{
|
||||
foreach (var sample in strongSamples)
|
||||
foreach (var sample in samples)
|
||||
HitObject.Samples.Remove(sample);
|
||||
}
|
||||
}
|
||||
@ -174,8 +184,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
||||
|
||||
MainPiece?.Expire();
|
||||
Content.Add(MainPiece = CreateMainPiece());
|
||||
|
||||
LoadSamples();
|
||||
}
|
||||
|
||||
protected override void AddNestedHitObject(DrawableHitObject hitObject)
|
||||
|
@ -126,7 +126,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
if (Result == null)
|
||||
throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
|
||||
|
||||
LoadSamples();
|
||||
LoadSamples(false);
|
||||
}
|
||||
|
||||
protected override void LoadAsyncComplete()
|
||||
@ -145,7 +145,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
}
|
||||
|
||||
samplesBindable = HitObject.SamplesBindable.GetBoundCopy();
|
||||
samplesBindable.CollectionChanged += (_, __) => LoadSamples();
|
||||
samplesBindable.CollectionChanged += (_, __) => LoadSamples(true);
|
||||
|
||||
apply(HitObject);
|
||||
}
|
||||
@ -157,7 +157,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
updateState(ArmedState.Idle, true);
|
||||
}
|
||||
|
||||
protected virtual void LoadSamples()
|
||||
/// <summary>
|
||||
/// Called to perform sample-related logic.
|
||||
/// </summary>
|
||||
/// <param name="changed">True if triggered from a post-load change to samples.</param>
|
||||
protected virtual void LoadSamples(bool changed)
|
||||
{
|
||||
if (Samples != null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user