1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:47:52 +08:00

Avoid bindable feedback causing overwrites

This commit is contained in:
Dean Herbert 2021-05-26 13:24:22 +09:00
parent 9223d85f37
commit 912748b428
3 changed files with 26 additions and 41 deletions

View File

@ -1,45 +1,10 @@
// 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 System.Linq;
using osu.Game.Audio;
namespace osu.Game.Rulesets.Taiko.Objects
{
public class Hit : TaikoStrongableHitObject
{
protected override void UpdateTypeFromSamples()
{
base.UpdateTypeFromSamples();
Type = getRimSamples().Any() ? HitType.Rim : HitType.Centre;
}
protected override void UpdateSamplesFromType()
{
base.UpdateSamplesFromType();
var rimSamples = getRimSamples();
bool isRimType = Type == HitType.Rim;
if (isRimType != rimSamples.Any())
{
if (isRimType)
Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_CLAP));
else
{
foreach (var sample in rimSamples)
Samples.Remove(sample);
}
}
}
/// <summary>
/// Returns an array of any samples which would cause this object to be a "rim" type hit.
/// </summary>
private HitSampleInfo[] getRimSamples() => Samples.Where(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE).ToArray();
protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit { StartTime = startTime };
public class StrongNestedHit : StrongNestedHitObject

View File

@ -1,7 +1,9 @@
// 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 System.Linq;
using osu.Framework.Bindables;
using osu.Game.Audio;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
@ -35,15 +37,35 @@ namespace osu.Game.Rulesets.Taiko.Objects
protected TaikoHitObject()
{
SamplesBindable.BindCollectionChanged((_, __) => UpdateTypeFromSamples());
TypeBindable.BindValueChanged(_ => UpdateSamplesFromType());
TypeBindable.BindValueChanged(_ => updateSamplesFromType());
}
protected virtual void UpdateSamplesFromType()
private void updateSamplesFromType()
{
var rimSamples = getRimSamples();
bool isRimType = Type == HitType.Rim;
if (isRimType != rimSamples.Any())
{
if (isRimType)
Samples.Add(new HitSampleInfo(HitSampleInfo.HIT_CLAP));
else
{
foreach (var sample in rimSamples)
Samples.Remove(sample);
}
}
}
protected virtual void UpdateTypeFromSamples()
{
Type = getRimSamples().Any() ? HitType.Rim : HitType.Centre;
}
/// <summary>
/// Returns an array of any samples which would cause this object to be a "rim" type hit.
/// </summary>
private HitSampleInfo[] getRimSamples() => Samples.Where(s => s.Name == HitSampleInfo.HIT_CLAP || s.Name == HitSampleInfo.HIT_WHISTLE).ToArray();
}
}

View File

@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Taiko.Objects
protected TaikoStrongableHitObject()
{
IsStrongBindable.BindValueChanged(_ => UpdateSamplesFromType());
IsStrongBindable.BindValueChanged(_ => updateSamplesFromType());
}
protected override void UpdateTypeFromSamples()
@ -48,10 +48,8 @@ namespace osu.Game.Rulesets.Taiko.Objects
IsStrong = getStrongSamples().Any();
}
protected override void UpdateSamplesFromType()
private void updateSamplesFromType()
{
base.UpdateSamplesFromType();
var strongSamples = getStrongSamples();
if (IsStrongBindable.Value != strongSamples.Any())