Handle type/strength changes from samples changes

This commit is contained in:
Dean Herbert 2020-09-23 18:09:40 +09:00
parent 8f3eb9a422
commit 9a0e5ac154
5 changed files with 43 additions and 21 deletions

View File

@ -89,9 +89,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private SkinnableSound slidingSample; private SkinnableSound slidingSample;
protected override void LoadSamples() protected override void LoadSamples(bool changed)
{ {
base.LoadSamples(); base.LoadSamples(changed);
slidingSample?.Expire(); slidingSample?.Expire();
slidingSample = null; slidingSample = null;

View File

@ -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_initial_frequency = 1.0f;
private const float spinning_sample_modulated_base_frequency = 0.5f; 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?.Expire();
spinningSample = null; spinningSample = null;

View File

@ -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() 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; bool isRimType = HitObject.Type == HitType.Rim;
if (isRimType != rimSamples.Any()) if (isRimType != samples.Any())
{ {
if (isRimType) if (isRimType)
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_CLAP }); HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_CLAP });
else else
{ {
foreach (var sample in rimSamples) foreach (var sample in samples)
HitObject.Samples.Remove(sample); HitObject.Samples.Remove(sample);
} }
} }

View File

@ -1,19 +1,19 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Input.Bindings;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -152,17 +152,27 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
RecreatePieces(); 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() 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) if (isStrong.Value)
HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH }); HitObject.Samples.Add(new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH });
else else
{ {
foreach (var sample in strongSamples) foreach (var sample in samples)
HitObject.Samples.Remove(sample); HitObject.Samples.Remove(sample);
} }
} }
@ -174,8 +184,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
MainPiece?.Expire(); MainPiece?.Expire();
Content.Add(MainPiece = CreateMainPiece()); Content.Add(MainPiece = CreateMainPiece());
LoadSamples();
} }
protected override void AddNestedHitObject(DrawableHitObject hitObject) protected override void AddNestedHitObject(DrawableHitObject hitObject)

View File

@ -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(false);
} }
protected override void LoadAsyncComplete() protected override void LoadAsyncComplete()
@ -145,7 +145,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
} }
samplesBindable = HitObject.SamplesBindable.GetBoundCopy(); samplesBindable = HitObject.SamplesBindable.GetBoundCopy();
samplesBindable.CollectionChanged += (_, __) => LoadSamples(); samplesBindable.CollectionChanged += (_, __) => LoadSamples(true);
apply(HitObject); apply(HitObject);
} }
@ -157,7 +157,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
updateState(ArmedState.Idle, true); 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) if (Samples != null)
{ {