1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +08:00

update DrawableHitCircle.ApplyResult to pass this to its callback

This commit is contained in:
Chandler Stowell 2024-01-25 11:25:41 -05:00
parent d2775680e6
commit 93bd3ce5ae
26 changed files with 120 additions and 87 deletions

View File

@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.EmptyFreeform.Objects.Drawables
{
if (timeOffset >= 0)
// todo: implement judgement logic
ApplyResult(static r => r.Type = HitResult.Perfect);
ApplyResult(static (r, hitObject) => r.Type = HitResult.Perfect);
}
protected override void UpdateHitStateTransforms(ArmedState state)

View File

@ -50,10 +50,10 @@ namespace osu.Game.Rulesets.Pippidon.Objects.Drawables
{
if (timeOffset >= 0)
{
ApplyResult(static (r, isHovered) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = isHovered ? HitResult.Perfect : HitResult.Miss;
}, IsHovered);
r.Type = hitObject.IsHovered ? HitResult.Perfect : HitResult.Miss;
});
}
}

View File

@ -24,7 +24,7 @@ namespace osu.Game.Rulesets.EmptyScrolling.Objects.Drawables
{
if (timeOffset >= 0)
// todo: implement judgement logic
ApplyResult(static r => r.Type = HitResult.Perfect);
ApplyResult(static (r, hitObject) => r.Type = HitResult.Perfect);
}
protected override void UpdateHitStateTransforms(ArmedState state)

View File

@ -50,10 +50,11 @@ namespace osu.Game.Rulesets.Pippidon.Objects.Drawables
{
if (timeOffset >= 0)
{
ApplyResult(static (r, pippidonHitObject) =>
ApplyResult(static (r, hitObject) =>
{
var pippidonHitObject = (DrawablePippidonHitObject)hitObject;
r.Type = pippidonHitObject.currentLane.Value == pippidonHitObject.HitObject.Lane ? HitResult.Perfect : HitResult.Miss;
}, this);
});
}
}

View File

@ -64,10 +64,11 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
if (timeOffset >= 0 && Result != null)
{
ApplyResult(static (r, state) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = state.CheckPosition.Invoke(state.HitObject) ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, this);
var catchHitObject = (DrawableCatchHitObject)hitObject;
r.Type = catchHitObject.CheckPosition!.Invoke(catchHitObject.HitObject) ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
}

View File

@ -265,7 +265,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
if (Tail.AllJudged)
{
if (Tail.IsHit)
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
else
MissForcefully();
}

View File

@ -11,6 +11,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
public override bool DisplayResult => false;
private bool hit;
public DrawableHoldNoteBody()
: this(null)
{
@ -25,7 +27,12 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
if (AllJudged) return;
ApplyResult(static (r, hit) => r.Type = hit ? r.Judgement.MaxResult : r.Judgement.MinResult, hit);
this.hit = hit;
ApplyResult(static (r, hitObject) =>
{
var holdNoteBody = (DrawableHoldNoteBody)hitObject;
r.Type = holdNoteBody.hit ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
}
}

View File

@ -87,7 +87,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
/// <summary>
/// Causes this <see cref="DrawableManiaHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public virtual void MissForcefully() => ApplyResult(static r => r.Type = r.Judgement.MinResult);
public virtual void MissForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
}
public abstract partial class DrawableManiaHitObject<TObject> : DrawableManiaHitObject

View File

@ -38,6 +38,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
private Drawable headPiece;
private HitResult hitResult;
public DrawableNote()
: this(null)
{
@ -89,18 +91,22 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
var result = HitObject.HitWindows.ResultFor(timeOffset);
if (result == HitResult.None)
hitResult = HitObject.HitWindows.ResultFor(timeOffset);
if (hitResult == HitResult.None)
return;
result = GetCappedResult(result);
hitResult = GetCappedResult(hitResult);
ApplyResult(static (r, result) => r.Type = result, result);
ApplyResult(static (r, hitObject) =>
{
var note = (DrawableNote)hitObject;
r.Type = note.hitResult;
});
}
/// <summary>

View File

@ -136,7 +136,7 @@ namespace osu.Game.Rulesets.Osu.Tests
if (auto && !userTriggered && timeOffset > hitOffset && CheckHittable?.Invoke(this, Time.Current, HitResult.Great) == ClickAction.Hit)
{
// force success
ApplyResult(r => r.Type = HitResult.Great);
ApplyResult(static (r, _) => r.Type = HitResult.Great);
}
else
base.CheckForResult(userTriggered, timeOffset);

View File

@ -208,7 +208,7 @@ namespace osu.Game.Rulesets.Osu.Tests
if (shouldHit && !userTriggered && timeOffset >= 0)
{
// force success
ApplyResult(r => r.Type = HitResult.Great);
ApplyResult(static (r, _) => r.Type = HitResult.Great);
}
else
base.CheckForResult(userTriggered, timeOffset);

View File

@ -44,6 +44,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private Container scaleContainer;
private InputManager inputManager;
private HitResult hitResult;
public DrawableHitCircle()
: this(null)
@ -155,34 +156,34 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
var result = ResultFor(timeOffset);
var clickAction = CheckHittable?.Invoke(this, Time.Current, result);
hitResult = ResultFor(timeOffset);
var clickAction = CheckHittable?.Invoke(this, Time.Current, hitResult);
if (clickAction == ClickAction.Shake)
Shake();
if (result == HitResult.None || clickAction != ClickAction.Hit)
if (hitResult == HitResult.None || clickAction != ClickAction.Hit)
return;
ApplyResult(static (r, state) =>
ApplyResult(static (r, hitObject) =>
{
var (hitCircle, hitResult) = state;
var hitCircle = (DrawableHitCircle)hitObject;
var circleResult = (OsuHitCircleJudgementResult)r;
// Todo: This should also consider misses, but they're a little more interesting to handle, since we don't necessarily know the position at the time of a miss.
if (hitResult.IsHit())
if (hitCircle.hitResult.IsHit())
{
var localMousePosition = hitCircle.ToLocalSpace(hitCircle.inputManager.CurrentState.Mouse.Position);
circleResult.CursorPositionAtHit = hitCircle.HitObject.StackedPosition + (localMousePosition - hitCircle.DrawSize / 2);
}
circleResult.Type = hitResult;
}, (this, result));
circleResult.Type = hitCircle.hitResult;
});
}
/// <summary>

View File

@ -100,12 +100,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get hit, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void HitForcefully() => ApplyResult(static r => r.Type = r.Judgement.MaxResult);
public void HitForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully() => ApplyResult(static r => r.Type = r.Judgement.MinResult);
public void MissForcefully() => ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
private RectangleF parentScreenSpaceRectangle => ((DrawableOsuHitObject)ParentHitObject)?.parentScreenSpaceRectangle ?? Parent!.ScreenSpaceDrawQuad.AABBFloat;

View File

@ -292,10 +292,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (HitObject.ClassicSliderBehaviour)
{
// Classic behaviour means a slider is judged proportionally to the number of nested hitobjects hit. This is the classic osu!stable scoring.
ApplyResult(static (r, nestedHitObjects) =>
ApplyResult(static (r, hitObject) =>
{
int totalTicks = nestedHitObjects.Count;
int hitTicks = nestedHitObjects.Count(h => h.IsHit);
int totalTicks = hitObject.NestedHitObjects.Count;
int hitTicks = hitObject.NestedHitObjects.Count(h => h.IsHit);
if (hitTicks == totalTicks)
r.Type = HitResult.Great;
@ -306,16 +306,16 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
double hitFraction = (double)hitTicks / totalTicks;
r.Type = hitFraction >= 0.5 ? HitResult.Ok : HitResult.Meh;
}
}, NestedHitObjects);
});
}
else
{
// If only the nested hitobjects are judged, then the slider's own judgement is ignored for scoring purposes.
// But the slider needs to still be judged with a reasonable hit/miss result for visual purposes (hit/miss transforms, etc).
ApplyResult(static (r, nestedHitObjects) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = nestedHitObjects.Any(h => h.Result.IsHit) ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, NestedHitObjects);
r.Type = hitObject.NestedHitObjects.Any(h => h.Result.IsHit) ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
}

View File

@ -258,8 +258,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
foreach (var tick in ticks.Where(t => !t.Result.HasResult))
tick.TriggerResult(false);
ApplyResult(static (r, spinner) =>
ApplyResult(static (r, hitObject) =>
{
var spinner = (DrawableSpinner)hitObject;
if (spinner.Progress >= 1)
r.Type = HitResult.Great;
else if (spinner.Progress > .9)
@ -268,7 +269,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
r.Type = HitResult.Meh;
else if (spinner.Time.Current >= spinner.HitObject.EndTime)
r.Type = r.Judgement.MinResult;
}, this);
});
}
protected override void Update()

View File

@ -11,6 +11,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public override bool DisplayResult => false;
private bool hit;
public DrawableSpinnerTick()
: this(null)
{
@ -35,6 +37,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
/// Apply a judgement result.
/// </summary>
/// <param name="hit">Whether this tick was reached.</param>
internal void TriggerResult(bool hit) => ApplyResult(static (r, hit) => r.Type = hit ? r.Judgement.MaxResult : r.Judgement.MinResult, hit);
internal void TriggerResult(bool hit)
{
this.hit = hit;
ApplyResult(static (r, hitObject) =>
{
var spinnerTick = (DrawableSpinnerTick)hitObject;
r.Type = spinnerTick.hit ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
}
}

View File

@ -143,7 +143,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (timeOffset < 0)
return;
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
protected override void UpdateHitStateTransforms(ArmedState state)
@ -192,10 +192,10 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!ParentHitObject.Judged)
return;
ApplyResult(static (r, parentHitObject) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = parentHitObject.IsHit ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, ParentHitObject);
r.Type = hitObject.IsHit ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e) => false;

View File

@ -49,14 +49,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!userTriggered)
{
if (timeOffset > HitObject.HitWindow)
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
if (Math.Abs(timeOffset) > HitObject.HitWindow)
return;
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
public override void OnKilled()
@ -64,7 +64,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
base.OnKilled();
if (Time.Current > HitObject.GetEndTime() && !Judged)
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
}
protected override void UpdateHitStateTransforms(ArmedState state)
@ -105,10 +105,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!ParentHitObject.Judged)
return;
ApplyResult(static (r, parentHitObject) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = parentHitObject.IsHit ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, ParentHitObject);
var nestedHit = (StrongNestedHit)hitObject;
r.Type = nestedHit.ParentHitObject!.IsHit ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e) => false;

View File

@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
protected override void LoadComplete()
{
base.LoadComplete();
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
protected override void LoadSamples()

View File

@ -37,6 +37,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private double? lastPressHandleTime;
private HitResult hitResult;
private readonly Bindable<HitType> type = new Bindable<HitType>();
public DrawableHit()
@ -99,18 +101,24 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!userTriggered)
{
if (!HitObject.HitWindows.CanBeHit(timeOffset))
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
var result = HitObject.HitWindows.ResultFor(timeOffset);
if (result == HitResult.None)
hitResult = HitObject.HitWindows.ResultFor(timeOffset);
if (hitResult == HitResult.None)
return;
if (!validActionPressed)
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
else
ApplyResult(static (r, result) => r.Type = result, result);
{
ApplyResult(static (r, hitObject) =>
{
var drawableHit = (DrawableHit)hitObject;
r.Type = drawableHit.hitResult;
});
}
}
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e)
@ -209,19 +217,19 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!ParentHitObject.Result.IsHit)
{
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
if (!userTriggered)
{
if (timeOffset - ParentHitObject.Result.TimeOffset > SECOND_HIT_WINDOW)
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
return;
}
if (Math.Abs(timeOffset - ParentHitObject.Result.TimeOffset) <= SECOND_HIT_WINDOW)
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
public override bool OnPressed(KeyBindingPressEvent<TaikoAction> e)

View File

@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
// it can happen that the hit window of the nested strong hit extends past the lifetime of the parent object.
// this is a safety to prevent such cases from causing the nested hit to never be judged and as such prevent gameplay from completing.
if (!Judged && Time.Current > ParentHitObject?.HitObject.GetEndTime())
ApplyResult(static r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
}
}
}

View File

@ -41,6 +41,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private double? lastPressHandleTime;
private int numHits;
public override bool DisplayResult => false;
public DrawableSwell()
@ -192,7 +194,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
nextTick?.TriggerResult(true);
int numHits = ticks.Count(r => r.IsHit);
numHits = ticks.Count(r => r.IsHit);
float completion = (float)numHits / HitObject.RequiredHits;
@ -206,14 +208,14 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);
if (numHits == HitObject.RequiredHits)
ApplyResult(static r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
else
{
if (timeOffset < 0)
return;
int numHits = 0;
numHits = 0;
foreach (var tick in ticks)
{
@ -227,11 +229,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
tick.TriggerResult(false);
}
ApplyResult(static (r, state) =>
ApplyResult(static (r, hitObject) =>
{
var (numHits, hitObject) = state;
r.Type = numHits == hitObject.RequiredHits ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, (numHits, HitObject));
var swell = (DrawableSwell)hitObject;
r.Type = swell.numHits == swell.HitObject.RequiredHits ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
}

View File

@ -15,6 +15,8 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{
public override bool DisplayResult => false;
private bool hit;
public DrawableSwellTick()
: this(null)
{
@ -29,11 +31,13 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public void TriggerResult(bool hit)
{
this.hit = hit;
HitObject.StartTime = Time.Current;
ApplyResult(static (r, hit) =>
ApplyResult(static (r, hitObject) =>
{
r.Type = hit ? r.Judgement.MaxResult : r.Judgement.MinResult;
}, hit);
var swellTick = (DrawableSwellTick)hitObject;
r.Type = swellTick.hit ? r.Judgement.MaxResult : r.Judgement.MinResult;
});
}
protected override void CheckForResult(bool userTriggered, double timeOffset)

View File

@ -216,7 +216,7 @@ namespace osu.Game.Tests.Gameplay
LifetimeStart = LIFETIME_ON_APPLY;
}
public void MissForcefully() => ApplyResult(r => r.Type = HitResult.Miss);
public void MissForcefully() => ApplyResult(static (r, _) => r.Type = HitResult.Miss);
protected override void UpdateHitStateTransforms(ArmedState state)
{

View File

@ -431,7 +431,7 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override void CheckForResult(bool userTriggered, double timeOffset)
{
if (timeOffset > HitObject.Duration)
ApplyResult(r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
protected override void UpdateHitStateTransforms(ArmedState state)
@ -468,7 +468,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public override void OnKilled()
{
base.OnKilled();
ApplyResult(r => r.Type = r.Judgement.MinResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MinResult);
}
}
@ -547,7 +547,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.CheckForResult(userTriggered, timeOffset);
if (timeOffset >= 0)
ApplyResult(r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
}
@ -596,7 +596,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
base.CheckForResult(userTriggered, timeOffset);
if (timeOffset >= 0)
ApplyResult(r => r.Type = r.Judgement.MaxResult);
ApplyResult(static (r, _) => r.Type = r.Judgement.MaxResult);
}
}

View File

@ -687,14 +687,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// the <see cref="ScoreProcessor"/> of the <see cref="JudgementResult"/>.
/// </summary>
/// <param name="application">The callback that applies changes to the <see cref="JudgementResult"/>.</param>
/// <param name="state">The state passed to the callback.</param>
/// <typeparam name="TState">The type of the state information that is passed to the callback method.</typeparam>
protected void ApplyResult<TState>(Action<JudgementResult, TState> application, TState state)
protected void ApplyResult(Action<JudgementResult, DrawableHitObject> application)
{
if (Result.HasResult)
throw new InvalidOperationException("Cannot apply result on a hitobject that already has a result.");
application?.Invoke(Result, state);
application?.Invoke(Result, this);
if (!Result.HasResult)
throw new InvalidOperationException($"{GetType().ReadableName()} applied a {nameof(JudgementResult)} but did not update {nameof(JudgementResult.Type)}.");
@ -716,13 +714,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
OnNewResult?.Invoke(this, Result);
}
/// <summary>
/// Applies the <see cref="Result"/> of this <see cref="DrawableHitObject"/>, notifying responders such as
/// the <see cref="ScoreProcessor"/> of the <see cref="JudgementResult"/>.
/// </summary>
/// <param name="application">The callback that applies changes to the <see cref="JudgementResult"/>.</param>
protected void ApplyResult(Action<JudgementResult> application) => ApplyResult<object>((r, _) => application?.Invoke(r), null);
/// <summary>
/// Processes this <see cref="DrawableHitObject"/>, checking if a scoring result has occurred.
/// </summary>