Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings caught by R# code inspector #130

Merged
merged 4 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions osu.Game.Rulesets.Rush.Tests/Visual/TestSceneRushPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Shane Woolcock. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Game.Tests.Visual;

Expand All @@ -15,7 +13,6 @@ namespace osu.Game.Rulesets.Rush.Tests.Visual
[TestFixture]
public class TestSceneRushPlayer : PlayerTestScene
{
private Checkbox pauseCheckbox;
private readonly BindableBool pausedBindable = new BindableBool();

protected new RushPlayer Player => (RushPlayer)base.Player;
Expand All @@ -27,7 +24,7 @@ public class TestSceneRushPlayer : PlayerTestScene
[BackgroundDependencyLoader]
private void load()
{
Add(pauseCheckbox = new OsuCheckbox
Add(new OsuCheckbox
{
LabelText = "Pause",
RelativeSizeAxes = Axes.None,
Expand All @@ -36,7 +33,7 @@ private void load()
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Margin = new MarginPadding { Top = 40f, Left = 10f },
Depth = Single.NegativeInfinity,
Depth = float.NegativeInfinity,
Current = { BindTarget = pausedBindable }
});

Expand Down
27 changes: 12 additions & 15 deletions osu.Game.Rulesets.Rush/Beatmaps/RushGeneratedBeatmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class RushGeneratedBeatmapConverter : BeatmapConverter<RushHitObject>
private LanedHitLane? previousLane;
private Vector2? previousSourcePosition;
private double previousSourceTime;
private HitObjectFlags previousFlags;
swoolcock marked this conversation as resolved.
Show resolved Hide resolved

private readonly Dictionary<LanedHitLane, StarSheet> currentStarSheets = new Dictionary<LanedHitLane, StarSheet>();

Expand Down Expand Up @@ -86,32 +85,31 @@ private void reset()

protected override IEnumerable<RushHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
{
void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
void updatePrevious(LanedHitLane? newLane)
{
previousLane = newLane;
previousSourceTime = original.GetEndTime();
previousSourcePosition = (original as IHasPosition)?.Position;
previousFlags = newFlags;
}

// if it's definitely a spinner, return a miniboss
if (original is IHasDuration && !(original is IHasDistance))
{
yield return createMiniBoss(original);

updatePrevious(null, HitObjectFlags.None);
updatePrevious(null);
yield break;
}

// otherwise do some flag magic
Random random = new Random((int)original.StartTime);

HitObjectFlags flags = flagsForHitObject(original, beatmap);
HitObjectFlags flags = flagsForHitObject(original);

// if no flags, completely skip this object
if (flags == HitObjectFlags.None)
{
updatePrevious(previousLane, HitObjectFlags.None);
updatePrevious(previousLane);
yield break;
}

Expand Down Expand Up @@ -192,7 +190,7 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
yield return currentStarSheets[otherLane];
}

updatePrevious(sheetLane, flags);
updatePrevious(sheetLane);
yield break;
}

Expand All @@ -206,7 +204,7 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
// if it's low probability, potentially skip this object
if (flags.HasFlagFast(HitObjectFlags.LowProbability) && random.NextDouble() < skip_probability)
{
updatePrevious(lane ?? previousLane, flags);
updatePrevious(lane ?? previousLane);
yield break;
}

Expand All @@ -219,7 +217,7 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
nextDualHitTime = original.StartTime + min_dualhit_time;
yield return createDualHit(original);

updatePrevious(null, flags);
updatePrevious(null);
yield break;
}

Expand All @@ -233,6 +231,9 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
? LanedHitLane.Ground
: (LanedHitLane?)null;

// ReSharper disable once MergeSequentialChecks
// weirdness, merging both checks result in IOE warning
// for accessing nullable value, just disable it for now.
if (blockedLane != null && finalLane == blockedLane)
finalLane = blockedLane.Value.Opposite();

Expand All @@ -256,10 +257,6 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
// if the new sawblade is too close to the previous hit in the same lane, skip it
var tooCloseToSameLane = previousLane == null || previousLane == sawbladeLane && original.StartTime - previousSourceTime < sawblade_same_lane_safety_time;

// if a ground sawblade is too far from the previous hit in the air lane, skip it (as the player may not have time to jump upon landing)
var canFallOntoSawblade = previousLane == LanedHitLane.Air && sawbladeLane == LanedHitLane.Ground && original.StartTime - previousSourceTime > sawblade_fall_safety_near_time
swoolcock marked this conversation as resolved.
Show resolved Hide resolved
&& original.StartTime - previousSourceTime < sawblade_fall_safety_far_time;

// air sawblades may only appear in a kiai section, and not too close to a hit in the same lane (or laneless)
// also need to account for a gap where the player may fall onto the blade
if (sawbladeLane != blockedLane
Expand Down Expand Up @@ -287,7 +284,7 @@ void updatePrevious(LanedHitLane? newLane, HitObjectFlags newFlags)
if (finalLane != blockedLane && !tooCloseToLastSawblade && (!sawbladeAdded || !flags.HasFlagFast(HitObjectFlags.AllowSawbladeReplace)))
yield return createNormalHit(original, finalLane);

updatePrevious(finalLane, flags);
updatePrevious(finalLane);
}

private LanedHit createNormalHit(HitObject original, LanedHitLane lane, IList<HitSampleInfo> samples = null, double? time = null)
Expand Down Expand Up @@ -350,7 +347,7 @@ private Sawblade createSawblade(HitObject original, LanedHitLane lane) =>
private LanedHitLane? laneForHitObject(HitObject hitObject) =>
hitObject is IHasYPosition hasYPosition ? (LanedHitLane?)(hasYPosition.Y < half_height ? LanedHitLane.Air : LanedHitLane.Ground) : null;

private HitObjectFlags flagsForHitObject(HitObject hitObject, IBeatmap beatmap)
private HitObjectFlags flagsForHitObject(HitObject hitObject)
{
HitObjectFlags flags = HitObjectFlags.None;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Rush.Objects.Drawables.Pieces;
using osu.Game.Rulesets.Rush.UI;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public abstract class DrawableStarSheetCap<TObject> : DrawableLanedHit<TObject>
{
protected abstract RushSkinComponents Component { get; }

private readonly Drawable capPiece;

protected readonly DrawableStarSheet StarSheet;

[Resolved]
Expand All @@ -38,7 +36,7 @@ protected DrawableStarSheetCap(DrawableStarSheet starSheet, TObject hitObject)
Size = new Vector2(DrawableStarSheet.NOTE_SHEET_SIZE * 1.1f);
Origin = Anchor.Centre;

Content.Child = capPiece = new SkinnableDrawable(new RushSkinComponent(Component), _ => new StarSheetCapStarPiece())
Content.Child = new SkinnableDrawable(new RushSkinComponent(Component), _ => new StarSheetCapStarPiece())
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Expand Down
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Rush/Objects/StarSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ protected override void CreateNestedHitObjects(CancellationToken cancellationTok

private void updateNestedSamples()
{
if (NodeSamples.Count == 0) return;
if (NodeSamples.Count == 0)
return;

Head.Samples = NodeSamples.First();
Tail.Samples = NodeSamples.Last();
}
Expand Down