Use early return for if-pattern-matching.

This commit is contained in:
Huo Yaoyuan 2019-11-22 00:02:40 +08:00
parent 20f01ff3e9
commit 4cd7d67fe4
5 changed files with 47 additions and 51 deletions

View File

@ -263,15 +263,13 @@ private Pattern generate()
/// <returns></returns>
private IList<HitSampleInfo> sampleInfoListAt(double time)
{
if (HitObject is IHasCurve curveData)
{
double segmentTime = (curveData.EndTime - HitObject.StartTime) / curveData.SpanCount();
if (!(HitObject is IHasCurve curveData))
return HitObject.Samples;
int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
return curveData.NodeSamples[index];
}
double segmentTime = (curveData.EndTime - HitObject.StartTime) / curveData.SpanCount();
return HitObject.Samples;
int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
return curveData.NodeSamples[index];
}
}
}

View File

@ -474,15 +474,13 @@ private Pattern generateHoldAndNormalNotes(double startTime)
/// <returns></returns>
private IList<HitSampleInfo> sampleInfoListAt(double time)
{
if (HitObject is IHasCurve curveData)
{
double segmentTime = (EndTime - HitObject.StartTime) / spanCount;
if (!(HitObject is IHasCurve curveData))
return HitObject.Samples;
int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
return curveData.NodeSamples[index];
}
double segmentTime = (EndTime - HitObject.StartTime) / spanCount;
return HitObject.Samples;
int index = (int)(segmentTime == 0 ? 0 : (time - HitObject.StartTime) / segmentTime);
return curveData.NodeSamples[index];
}
/// <summary>

View File

@ -380,25 +380,25 @@ private Drawable createDrawable(Slider slider, float circleSize, double speedMul
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{
if (judgedObject is DrawableOsuHitObject osuObject)
if (!(judgedObject is DrawableOsuHitObject osuObject))
return;
OsuSpriteText text;
Add(text = new OsuSpriteText
{
OsuSpriteText text;
Add(text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = result.IsHit ? "Hit!" : "Miss!",
Colour = result.IsHit ? Color4.Green : Color4.Red,
Font = OsuFont.GetFont(size: 30),
Position = osuObject.HitObject.StackedEndPosition + judgementOffsetDirection * new Vector2(0, 45)
});
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = result.IsHit ? "Hit!" : "Miss!",
Colour = result.IsHit ? Color4.Green : Color4.Red,
Font = OsuFont.GetFont(size: 30),
Position = osuObject.HitObject.StackedEndPosition + judgementOffsetDirection * new Vector2(0, 45)
});
text.Delay(150)
.Then().FadeOut(200)
.Then().Expire();
text.Delay(150)
.Then().FadeOut(200)
.Then().Expire();
judgementOffsetDirection *= -1;
}
judgementOffsetDirection *= -1;
}
}
}

View File

@ -22,17 +22,17 @@ public void ApplyToHitObject(HitObject hitObject)
osuObject.Position = new Vector2(osuObject.Position.X, OsuPlayfield.BASE_SIZE.Y - osuObject.Y);
if (hitObject is Slider slider)
{
slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
if (!(hitObject is Slider slider))
return;
var newControlPoints = new Vector2[slider.Path.ControlPoints.Length];
for (int i = 0; i < slider.Path.ControlPoints.Length; i++)
newControlPoints[i] = new Vector2(slider.Path.ControlPoints[i].X, -slider.Path.ControlPoints[i].Y);
slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
}
var newControlPoints = new Vector2[slider.Path.ControlPoints.Length];
for (int i = 0; i < slider.Path.ControlPoints.Length; i++)
newControlPoints[i] = new Vector2(slider.Path.ControlPoints[i].X, -slider.Path.ControlPoints[i].Y);
slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
}
}
}

View File

@ -125,20 +125,20 @@ private ScrollState scrollState
foreach (var c in Children)
{
if (c is ScrollingTeam stc)
if (!(c is ScrollingTeam stc))
continue;
if (closest == null)
{
if (closest == null)
{
closest = stc;
continue;
}
float o = Math.Abs(c.Position.X + c.DrawWidth / 2f - DrawWidth / 2f);
float lastOffset = Math.Abs(closest.Position.X + closest.DrawWidth / 2f - DrawWidth / 2f);
if (o < lastOffset)
closest = stc;
closest = stc;
continue;
}
float o = Math.Abs(c.Position.X + c.DrawWidth / 2f - DrawWidth / 2f);
float lastOffset = Math.Abs(closest.Position.X + closest.DrawWidth / 2f - DrawWidth / 2f);
if (o < lastOffset)
closest = stc;
}
Trace.Assert(closest != null, "closest != null");