Skip to content

Commit

Permalink
Use index and range expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Dec 15, 2019
1 parent cea3a66 commit c457571
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
#Style - C# 8 features
csharp_prefer_static_local_function = true:warning
csharp_prefer_simple_using_statement = true:silent
csharp_style_prefer_index_operator = false:none
csharp_style_prefer_range_operator = false:none
csharp_style_prefer_index_operator = true:warning
csharp_style_prefer_range_operator = true:warning
csharp_style_prefer_switch_expression = false:none

#Supressing roslyn built-in analyzers
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void computeDensity(double newNoteTime)
prevNoteTimes.RemoveAt(0);
prevNoteTimes.Add(newNoteTime);

density = (prevNoteTimes[prevNoteTimes.Count - 1] - prevNoteTimes[0]) / prevNoteTimes.Count;
density = (prevNoteTimes[^1] - prevNoteTimes[0]) / prevNoteTimes.Count;
}

private double lastTime;
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Osu.Tests/TestSceneSliderInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ public void TestTrackingReleasedValidKey()

private bool assertGreatJudge() => judgementResults.Last().Type == HitResult.Great;

private bool assertHeadMissTailTracked() => judgementResults[judgementResults.Count - 2].Type == HitResult.Great && judgementResults.First().Type == HitResult.Miss;
private bool assertHeadMissTailTracked() => judgementResults[^2].Type == HitResult.Great && judgementResults.First().Type == HitResult.Miss;

private bool assertMidSliderJudgements() => judgementResults[judgementResults.Count - 2].Type == HitResult.Great;
private bool assertMidSliderJudgements() => judgementResults[^2].Type == HitResult.Great;

private bool assertMidSliderJudgementFail() => judgementResults[judgementResults.Count - 2].Type == HitResult.Miss;
private bool assertMidSliderJudgementFail() => judgementResults[^2].Type == HitResult.Miss;

private ScoreAccessibleReplayPlayer currentPlayer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected override bool OnMouseUp(MouseUpEvent e)
protected override bool OnDoubleClick(DoubleClickEvent e)
{
// Todo: This should all not occur on double click, but rather if the previous control point is hovered.
segmentStart = HitObject.Path.ControlPoints[HitObject.Path.ControlPoints.Count - 1];
segmentStart = HitObject.Path.ControlPoints[^1];
segmentStart.Type.Value = PathType.Linear;

currentSegmentLength = 1;
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Osu/Replays/OsuAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ private void addHitObjectReplay(OsuHitObject h)
// TODO: Shouldn't the spinner always spin in the same direction?
if (h is Spinner)
{
calcSpinnerStartPosAndDirection(((OsuReplayFrame)Frames[Frames.Count - 1]).Position, out startPosition, out spinnerDirection);
calcSpinnerStartPosAndDirection(((OsuReplayFrame)Frames[^1]).Position, out startPosition, out spinnerDirection);

Vector2 spinCentreOffset = SPINNER_CENTRE - ((OsuReplayFrame)Frames[Frames.Count - 1]).Position;
Vector2 spinCentreOffset = SPINNER_CENTRE - ((OsuReplayFrame)Frames[^1]).Position;

if (spinCentreOffset.Length > SPIN_RADIUS)
{
Expand Down Expand Up @@ -230,7 +230,7 @@ private static void calcSpinnerStartPosAndDirection(Vector2 prevPos, out Vector2

private void moveToHitObject(OsuHitObject h, Vector2 targetPos, Easing easing)
{
OsuReplayFrame lastFrame = (OsuReplayFrame)Frames[Frames.Count - 1];
OsuReplayFrame lastFrame = (OsuReplayFrame)Frames[^1];

// Wait until Auto could "see and react" to the next note.
double waitTime = h.StartTime - Math.Max(0.0, h.TimePreempt - reactionTime);
Expand Down Expand Up @@ -363,7 +363,7 @@ private void addHitObjectClickFrames(OsuHitObject h, Vector2 startPosition, floa
}

// We only want to let go of our button if we are at the end of the current replay. Otherwise something is still going on after us so we need to keep the button pressed!
if (Frames[Frames.Count - 1].Time <= endFrame.Time)
if (Frames[^1].Time <= endFrame.Time)
AddFrameToReplay(endFrame);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public BeatContainer()

private TimingControlPoint getNextTimingPoint(TimingControlPoint current)
{
if (timingPoints[timingPoints.Count - 1] == current)
if (timingPoints[^1] == current)
return current;

int index = timingPoints.IndexOf(current); // -1 means that this is a "default beat"
Expand All @@ -169,7 +169,7 @@ private int calculateBeatCount(TimingControlPoint current)
{
if (timingPoints.Count == 0) return 0;

if (timingPoints[timingPoints.Count - 1] == current)
if (timingPoints[^1] == current)
return (int)Math.Ceiling((Beatmap.Value.Track.Length - current.Time) / current.BeatLength);

return (int)Math.Ceiling((getNextTimingPoint(current).Time - current.Time) / current.BeatLength);
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ private T binarySearch<T>(IReadOnlyList<T> list, double time)
if (time < list[0].Time)
return null;

if (time >= list[list.Count - 1].Time)
return list[list.Count - 1];
if (time >= list[^1].Time)
return list[^1];

int l = 0;
int r = list.Count - 2;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Beatmaps/Formats/LegacyDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void ParseStreamInto(LineBufferedReader stream, T output)

if (line.StartsWith(@"[", StringComparison.Ordinal) && line.EndsWith(@"]", StringComparison.Ordinal))
{
if (!Enum.TryParse(line.Substring(1, line.Length - 2), out section))
if (!Enum.TryParse(line[1..^1], out section))
{
Logger.Log($"Unknown section \"{line}\" in \"{output}\"");
section = Section.None;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Graphics/Containers/LinkFlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void AddLinks(string text, List<Link> links)

foreach (var link in links)
{
AddText(text.Substring(previousLinkEnd, link.Index - previousLinkEnd));
AddText(text[previousLinkEnd..link.Index]);
AddLink(text.Substring(link.Index, link.Length), link.Action, link.Argument ?? link.Url);
previousLinkEnd = link.Index + link.Length;
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public override HitObject Parse(string text)
result = CreateSlider(pos, combo, comboOffset, convertControlPoints(points, pathType), length, repeatCount, nodeSamples);

// The samples are played when the slider ends, which is the last node
result.Samples = nodeSamples[nodeSamples.Count - 1];
result.Samples = nodeSamples[^1];
}
else if (type.HasFlag(ConvertHitObjectType.Spinner))
{
Expand Down Expand Up @@ -279,7 +279,7 @@ private PathControlPoint[] convertControlPoints(Vector2[] vertices, PathType typ
{
if (vertices[i] == vertices[i - 1])
{
points[points.Count - 1].Type.Value = type;
points[^1].Type.Value = type;
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Rulesets/Objects/SliderPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public double Distance
get
{
ensureValid();
return cumulativeLength.Count == 0 ? 0 : cumulativeLength[cumulativeLength.Count - 1];
return cumulativeLength.Count == 0 ? 0 : cumulativeLength[^1];
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ private void calculateLength()
if (calculatedLength > expectedDistance)
{
// The path will be shortened further, in which case we should trim any more unnecessary lengths and their associated path segments
while (cumulativeLength.Count > 0 && cumulativeLength[cumulativeLength.Count - 1] >= expectedDistance)
while (cumulativeLength.Count > 0 && cumulativeLength[^1] >= expectedDistance)
{
cumulativeLength.RemoveAt(cumulativeLength.Count - 1);
calculatedPath.RemoveAt(pathEndIndex--);
Expand All @@ -269,7 +269,7 @@ private void calculateLength()
// The direction of the segment to shorten or lengthen
Vector2 dir = (calculatedPath[pathEndIndex] - calculatedPath[pathEndIndex - 1]).Normalized();

calculatedPath[pathEndIndex] = calculatedPath[pathEndIndex - 1] + dir * (float)(expectedDistance - cumulativeLength[cumulativeLength.Count - 1]);
calculatedPath[pathEndIndex] = calculatedPath[pathEndIndex - 1] + dir * (float)(expectedDistance - cumulativeLength[^1]);
cumulativeLength.Add(expectedDistance);
}
}
Expand Down
2 changes: 1 addition & 1 deletion osu.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseCollectionCountProperty/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInFormatString/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseFormatSpecifierInInterpolation/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseIndexFromEndExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNameofExpression/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternMatching/@EntryIndexedValue"></s:String>
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseNegatedPatternMatching/@EntryIndexRemoved">True</s:Boolean>
Expand Down

0 comments on commit c457571

Please sign in to comment.