1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Reword and reoganise logic

This commit is contained in:
Dean Herbert 2019-04-24 16:58:13 +09:00
parent 9890884726
commit 67382724f6

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{ {
private int trackingSliders; private int slidersCurrentlyTracking;
public OsuFlashlight() public OsuFlashlight()
{ {
@ -45,31 +45,24 @@ namespace osu.Game.Rulesets.Osu.Mods
public void OnSliderTrackingChange(ValueChangedEvent<bool> e) public void OnSliderTrackingChange(ValueChangedEvent<bool> e)
{ {
// If any sliders are in a tracking state, apply a dim to the entire playfield over a brief duration. // If any sliders are in a tracking state, a further dim should be applied to the (remaining) visible portion of the playfield over a brief duration.
if (e.NewValue) if (e.NewValue)
{ {
trackingSliders++; // The transform should only be applied when the first slider begins tracking.
// The fade should only be applied if tracking sliders is increasing from 0 to 1, and cannot be a result of a slider losing tracking. if (++slidersCurrentlyTracking == 1)
// As a result, this logic must be exclusive to when e.NewValue is true.
if (trackingSliders == 1)
{
this.TransformTo(nameof(FlashlightDim), 0.8f, 50); this.TransformTo(nameof(FlashlightDim), 0.8f, 50);
} }
}
else else
{ {
trackingSliders--; if (slidersCurrentlyTracking == 0)
throw new InvalidOperationException($"The number of {nameof(slidersCurrentlyTracking)} cannot be below 0.");
if (trackingSliders == 0) // The fade is restored after the last slider exits a tracked state.
{ if (--slidersCurrentlyTracking == 0)
this.TransformTo(nameof(FlashlightDim), 0.0f, 50); this.TransformTo(nameof(FlashlightDim), 0.0f, 50);
} }
} }
if (trackingSliders < 0)
throw new InvalidOperationException($"The number of {nameof(trackingSliders)} cannot be below 0.");
}
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
FlashlightPosition = e.MousePosition; FlashlightPosition = e.MousePosition;