1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-10 06:52:54 +08:00

Separate asymmetric CatchHitObject.X to EffectiveX and OriginalX

This commit is contained in:
ekrctb 2020-12-09 17:46:36 +09:00
parent 94d737e51b
commit 8da502da44
2 changed files with 16 additions and 13 deletions

View File

@ -16,23 +16,27 @@ namespace osu.Game.Rulesets.Catch.Objects
{ {
public const float OBJECT_RADIUS = 64; public const float OBJECT_RADIUS = 64;
// This value is after XOffset applied. public readonly Bindable<float> OriginalXBindable = new Bindable<float>();
public readonly Bindable<float> XBindable = new Bindable<float>();
// This value is before XOffset applied. public float OriginalX
private float originalX; {
get => OriginalXBindable.Value;
set => OriginalXBindable.Value = value;
}
/// <summary> /// <summary>
/// The horizontal position of the fruit between 0 and <see cref="CatchPlayfield.WIDTH"/>. /// The horizontal position of the fruit between 0 and <see cref="CatchPlayfield.WIDTH"/>.
/// </summary> /// </summary>
public float X public float X
{ {
// TODO: I don't like this asymmetry. get => EffectiveX;
get => XBindable.Value; set => OriginalXBindable.Value = value;
// originalX is set by `XBindable.BindValueChanged`
set => XBindable.Value = value + xOffset;
} }
public readonly Bindable<float> EffectiveXBindable = new Bindable<float>();
public float EffectiveX => EffectiveXBindable.Value;
private float xOffset; private float xOffset;
/// <summary> /// <summary>
@ -40,11 +44,10 @@ namespace osu.Game.Rulesets.Catch.Objects
/// </summary> /// </summary>
internal float XOffset internal float XOffset
{ {
get => xOffset;
set set
{ {
xOffset = value; xOffset = value;
XBindable.Value = originalX + xOffset; EffectiveXBindable.Value = OriginalX + xOffset;
} }
} }
@ -116,7 +119,7 @@ namespace osu.Game.Rulesets.Catch.Objects
protected CatchHitObject() protected CatchHitObject()
{ {
XBindable.BindValueChanged(x => originalX = x.NewValue - xOffset); OriginalXBindable.BindValueChanged(change => EffectiveXBindable.Value = change.NewValue + xOffset);
} }
} }
} }

View File

@ -38,14 +38,14 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
{ {
base.OnApply(); base.OnApply();
XBindable.BindTo(HitObject.XBindable); XBindable.BindTo(HitObject.EffectiveXBindable);
} }
protected override void OnFree() protected override void OnFree()
{ {
base.OnFree(); base.OnFree();
XBindable.UnbindFrom(HitObject.XBindable); XBindable.UnbindFrom(HitObject.EffectiveXBindable);
} }
public Func<CatchHitObject, bool> CheckPosition; public Func<CatchHitObject, bool> CheckPosition;