Remove EffectiveXBindable (setting Value was not handled)

And use orthogonal `OriginalXBindable` and `XOffsetBindable`.
This commit is contained in:
ekrctb 2020-12-14 13:39:07 +09:00
parent 0ad256a762
commit 5b5e883904
4 changed files with 29 additions and 40 deletions

View File

@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Catch.Tests
private void attemptCatch(Fruit fruit) private void attemptCatch(Fruit fruit)
{ {
fruit.OriginalX += catcher.X; fruit.X = fruit.OriginalX + catcher.X;
fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty fruit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty
{ {
CircleSize = circleSize CircleSize = circleSize

View File

@ -4,7 +4,6 @@
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Catch.UI; using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
@ -21,46 +20,40 @@ namespace osu.Game.Rulesets.Catch.Objects
/// <summary> /// <summary>
/// The horizontal position of the hit object between 0 and <see cref="CatchPlayfield.WIDTH"/>. /// The horizontal position of the hit object between 0 and <see cref="CatchPlayfield.WIDTH"/>.
/// </summary> /// </summary>
/// <remarks> public float X
/// This value is the original value specified in the beatmap, not affected by beatmap processing.
/// It should be used instead of <see cref="EffectiveX"/> when working on a beatmap, not a gameplay.
/// </remarks>
public float OriginalX
{ {
get => OriginalXBindable.Value;
set => OriginalXBindable.Value = value; set => OriginalXBindable.Value = value;
} }
float IHasXPosition.X => OriginalX; float IHasXPosition.X => OriginalXBindable.Value;
public readonly Bindable<float> XOffsetBindable = new Bindable<float>();
/// <summary> /// <summary>
/// An alias of <see cref="OriginalX"/> setter. /// A random offset applied to the horizontal position, set by the beatmap processing.
/// </summary> /// </summary>
public float X public float XOffset
{ {
set => OriginalX = value; set => XOffsetBindable.Value = value;
} }
public readonly Bindable<float> EffectiveXBindable = new Bindable<float>(); /// <summary>
/// The horizontal position of the hit object between 0 and <see cref="CatchPlayfield.WIDTH"/>.
/// </summary>
/// <remarks>
/// This value is the original <see cref="X"/> value specified in the beatmap, not affected by the beatmap processing.
/// Use <see cref="EffectiveX"/> for a gameplay.
/// </remarks>
public float OriginalX => OriginalXBindable.Value;
/// <summary> /// <summary>
/// The effective horizontal position of the hit object between 0 and <see cref="CatchPlayfield.WIDTH"/>. /// The effective horizontal position of the hit object between 0 and <see cref="CatchPlayfield.WIDTH"/>.
/// </summary> /// </summary>
public float EffectiveX => EffectiveXBindable.Value; /// <remarks>
/// This value is the original <see cref="X"/> value plus the offset applied by the beatmap processing.
private float xOffset; /// Use <see cref="OriginalX"/> if a value not affected by the offset is desired.
/// </remarks>
/// <summary> public float EffectiveX => OriginalXBindable.Value + XOffsetBindable.Value;
/// A random offset applied to the horizontal position, set by the <see cref="CatchBeatmapProcessor"/>.
/// </summary>
internal float XOffset
{
set
{
xOffset = value;
EffectiveXBindable.Value = OriginalX + xOffset;
}
}
public double TimePreempt = 1000; public double TimePreempt = 1000;
@ -127,10 +120,5 @@ namespace osu.Game.Rulesets.Catch.Objects
} }
protected override HitWindows CreateHitWindows() => HitWindows.Empty; protected override HitWindows CreateHitWindows() => HitWindows.Empty;
protected CatchHitObject()
{
OriginalXBindable.BindValueChanged(change => EffectiveXBindable.Value = change.NewValue + xOffset);
}
} }
} }

View File

@ -15,7 +15,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
public abstract class DrawableCatchHitObject : DrawableHitObject<CatchHitObject> public abstract class DrawableCatchHitObject : DrawableHitObject<CatchHitObject>
{ {
public readonly Bindable<float> EffectiveXBindable = new Bindable<float>(); public readonly Bindable<float> OriginalXBindable = new Bindable<float>();
public readonly Bindable<float> XOffsetBindable = new Bindable<float>();
protected override double InitialLifetimeOffset => HitObject.TimePreempt; protected override double InitialLifetimeOffset => HitObject.TimePreempt;
@ -38,14 +39,16 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
base.OnApply(); base.OnApply();
EffectiveXBindable.BindTo(HitObject.EffectiveXBindable); OriginalXBindable.BindTo(HitObject.OriginalXBindable);
XOffsetBindable.BindTo(HitObject.XOffsetBindable);
} }
protected override void OnFree() protected override void OnFree()
{ {
base.OnFree(); base.OnFree();
EffectiveXBindable.UnbindFrom(HitObject.EffectiveXBindable); OriginalXBindable.UnbindFrom(HitObject.OriginalXBindable);
XOffsetBindable.UnbindFrom(HitObject.XOffsetBindable);
} }
public Func<CatchHitObject, bool> CheckPosition; public Func<CatchHitObject, bool> CheckPosition;

View File

@ -55,10 +55,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
EffectiveXBindable.BindValueChanged(x => OriginalXBindable.BindValueChanged(_ => X = OriginalXBindable.Value + XOffsetBindable.Value);
{ XOffsetBindable.BindValueChanged(_ => X = OriginalXBindable.Value + XOffsetBindable.Value, true);
X = x.NewValue;
}, true);
ScaleBindable.BindValueChanged(scale => ScaleBindable.BindValueChanged(scale =>
{ {