diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs index 54d715ae64..ee58d934a4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlayer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Screens.Testing; using osu.Game.Beatmaps; @@ -38,7 +39,7 @@ namespace osu.Desktop.VisualTests.Tests WorkingBeatmap beatmap = null; - var beatmapInfo = db.Query().Where(b => b.Mode == PlayMode.Osu).FirstOrDefault(); + var beatmapInfo = db.Query().FirstOrDefault(b => b.Mode == PlayMode.Osu); if (beatmapInfo != null) beatmap = db.GetWorkingBeatmap(beatmapInfo); diff --git a/osu.Desktop.VisualTests/Tests/TestCaseReplay.cs b/osu.Desktop.VisualTests/Tests/TestCaseReplay.cs index c8c7e86fdd..f39da70a16 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseReplay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseReplay.cs @@ -3,11 +3,8 @@ using System; using System.IO; -using osu.Framework.Allocation; using osu.Framework.Input.Handlers; -using osu.Framework.Platform; using osu.Game.Beatmaps; -using osu.Game.Database; using osu.Game.Modes; using osu.Game.Screens.Play; @@ -20,16 +17,9 @@ namespace osu.Desktop.VisualTests.Tests private InputHandler replay; private Func getReplayStream; - private ScoreDatabase scoreDatabase; public override string Description => @"Testing replay playback."; - [BackgroundDependencyLoader] - private void load(Storage storage) - { - scoreDatabase = new ScoreDatabase(storage); - } - protected override Player CreatePlayer(WorkingBeatmap beatmap) { var player = base.CreatePlayer(beatmap); diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index e35616b51a..b93636331a 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -189,7 +189,7 @@ namespace osu.Desktop.Overlays private class UpdateProgressNotification : ProgressNotification { - protected override Notification CreateCompletionNotification() => new ProgressCompletionNotification(this) + protected override Notification CreateCompletionNotification() => new ProgressCompletionNotification() { Text = @"Update ready to install. Click to restart!", Activated = () => diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs index 67acc7cc7e..94c150bd3e 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs @@ -24,10 +24,11 @@ namespace osu.Game.Modes.Osu.Objects.Drawables private SliderBody body; private SliderBall ball; - private SliderBouncer bouncer1, bouncer2; + private SliderBouncer bouncer2; public DrawableSlider(Slider s) : base(s) { + SliderBouncer bouncer1; slider = s; Children = new Drawable[] @@ -124,8 +125,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables protected override void CheckJudgement(bool userTriggered) { - var j = Judgement as OsuJudgementInfo; - var sc = initialCircle.Judgement as OsuJudgementInfo; + var j = (OsuJudgementInfo)Judgement; + var sc = (OsuJudgementInfo)initialCircle.Judgement; if (!userTriggered && Time.Current >= HitObject.EndTime) { diff --git a/osu.Game.Modes.Osu/OsuAutoReplay.cs b/osu.Game.Modes.Osu/OsuAutoReplay.cs index 674ee10c19..953f131797 100644 --- a/osu.Game.Modes.Osu/OsuAutoReplay.cs +++ b/osu.Game.Modes.Osu/OsuAutoReplay.cs @@ -65,12 +65,13 @@ namespace osu.Game.Modes.Osu private double applyModsToTime(double v) => v; private double applyModsToRate(double v) => v; + public bool DelayedMovements; // ModManager.CheckActive(Mods.Relax2); + private void createAutoReplay() { int buttonIndex = 0; - bool delayedMovements = false;// ModManager.CheckActive(Mods.Relax2); - EasingTypes preferredEasing = delayedMovements ? EasingTypes.InOutCubic : EasingTypes.Out; + EasingTypes preferredEasing = DelayedMovements ? EasingTypes.InOutCubic : EasingTypes.Out; addFrameToReplay(new LegacyReplayFrame(-100000, 256, 500, LegacyButtonState.None)); addFrameToReplay(new LegacyReplayFrame(beatmap.HitObjects[0].StartTime - 1500, 256, 500, LegacyButtonState.None)); @@ -85,7 +86,7 @@ namespace osu.Game.Modes.Osu for (int i = 0; i < beatmap.HitObjects.Count; i++) { - OsuHitObject h = beatmap.HitObjects[i] as OsuHitObject; + OsuHitObject h = (OsuHitObject)beatmap.HitObjects[i]; //if (h.EndTime < InputManager.ReplayStartTime) //{ @@ -95,9 +96,9 @@ namespace osu.Game.Modes.Osu int endDelay = h is Spinner ? 1 : 0; - if (delayedMovements && i > 0) + if (DelayedMovements && i > 0) { - OsuHitObject last = beatmap.HitObjects[i - 1] as OsuHitObject; + OsuHitObject last = (OsuHitObject)beatmap.HitObjects[i - 1]; //Make the cursor stay at a hitObject as long as possible (mainly for autopilot). if (h.StartTime - h.HitWindowFor(OsuScoreResult.Miss) > last.EndTime + h.HitWindowFor(OsuScoreResult.Hit50) + 50) diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index ee5213cb48..b437b354d3 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Linq; using osu.Framework.Platform; using osu.Game.IO.Legacy; using osu.Game.IPC; @@ -18,6 +19,7 @@ namespace osu.Game.Database private const string replay_folder = @"replays"; + // ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised) private ScoreIPCChannel ipc; public ScoreDatabase(Storage storage, IIpcHost importHost = null, BeatmapDatabase beatmaps = null) @@ -45,7 +47,7 @@ namespace osu.Game.Database var version = sr.ReadInt32(); /* score.FileChecksum = */ var beatmapHash = sr.ReadString(); - score.Beatmap = beatmaps.Query().Where(b => b.Hash == beatmapHash).FirstOrDefault(); + score.Beatmap = beatmaps.Query().FirstOrDefault(b => b.Hash == beatmapHash); /* score.PlayerName = */ sr.ReadString(); /* var localScoreChecksum = */ diff --git a/osu.Game/IO/Legacy/SerializationReader.cs b/osu.Game/IO/Legacy/SerializationReader.cs index a1c103f052..6cab5c534d 100644 --- a/osu.Game/IO/Legacy/SerializationReader.cs +++ b/osu.Game/IO/Legacy/SerializationReader.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.Serialization; @@ -184,6 +185,9 @@ namespace osu.Game.IO.Legacy { if (formatter == null) initialize(); + + Debug.Assert(formatter != null, "formatter != null"); + return formatter.Deserialize(stream); } @@ -203,46 +207,39 @@ namespace osu.Game.IO.Legacy List tmpTypes = new List(); Type genType = null; - try + if (typeName.Contains("System.Collections.Generic") && typeName.Contains("[[")) { - if (typeName.Contains("System.Collections.Generic") && typeName.Contains("[[")) - { - string[] splitTyps = typeName.Split('['); + string[] splitTyps = typeName.Split('['); - foreach (string typ in splitTyps) + foreach (string typ in splitTyps) + { + if (typ.Contains("Version")) { - if (typ.Contains("Version")) - { - string asmTmp = typ.Substring(typ.IndexOf(',') + 1); - string asmName = asmTmp.Remove(asmTmp.IndexOf(']')).Trim(); - string typName = typ.Remove(typ.IndexOf(',')); - tmpTypes.Add(BindToType(asmName, typName)); - } - else if (typ.Contains("Generic")) - { - genType = BindToType(assemblyName, typ); - } + string asmTmp = typ.Substring(typ.IndexOf(',') + 1); + string asmName = asmTmp.Remove(asmTmp.IndexOf(']')).Trim(); + string typName = typ.Remove(typ.IndexOf(',')); + tmpTypes.Add(BindToType(asmName, typName)); } - if (genType != null && tmpTypes.Count > 0) + else if (typ.Contains("Generic")) { - return genType.MakeGenericType(tmpTypes.ToArray()); + genType = BindToType(assemblyName, typ); } } - - string toAssemblyName = assemblyName.Split(',')[0]; - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly a in assemblies) + if (genType != null && tmpTypes.Count > 0) { - if (a.FullName.Split(',')[0] == toAssemblyName) - { - typeToDeserialize = a.GetType(typeName); - break; - } + return genType.MakeGenericType(tmpTypes.ToArray()); } } - catch (Exception exception) + + string toAssemblyName = assemblyName.Split(',')[0]; + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly a in assemblies) { - throw exception; + if (a.FullName.Split(',')[0] == toAssemblyName) + { + typeToDeserialize = a.GetType(typeName); + break; + } } cache.Add(assemblyName + typeName, typeToDeserialize); diff --git a/osu.Game/IO/Legacy/SerializationWriter.cs b/osu.Game/IO/Legacy/SerializationWriter.cs index 571475b07c..7325129128 100644 --- a/osu.Game/IO/Legacy/SerializationWriter.cs +++ b/osu.Game/IO/Legacy/SerializationWriter.cs @@ -8,6 +8,8 @@ using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Text; +// ReSharper disable ConditionIsAlwaysTrueOrFalse (we're allowing nulls to be passed to the writer where the underlying class doesn't). +// ReSharper disable HeuristicUnreachableCode namespace osu.Game.IO.Legacy { diff --git a/osu.Game/IPC/BeatmapIPCChannel.cs b/osu.Game/IPC/BeatmapIPCChannel.cs index 1d0f4779be..2b98d5254f 100644 --- a/osu.Game/IPC/BeatmapIPCChannel.cs +++ b/osu.Game/IPC/BeatmapIPCChannel.cs @@ -19,7 +19,10 @@ namespace osu.Game.IPC MessageReceived += msg => { Debug.Assert(beatmaps != null); - ImportAsync(msg.Path); + ImportAsync(msg.Path).ContinueWith(t => + { + if (t.Exception != null) throw t.Exception; + }, TaskContinuationOptions.OnlyOnFaulted); }; } diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 1aac2a758c..33ff8a0810 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -129,10 +129,13 @@ namespace osu.Game.Modes.Objects.Drawables [BackgroundDependencyLoader] private void load(AudioManager audio) { - string hitType = ((HitObject.Sample?.Type ?? SampleType.None) == SampleType.None ? SampleType.Normal : HitObject.Sample.Type).ToString().ToLower(); - string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower(); + SampleType type = HitObject.Sample?.Type ?? SampleType.None; + if (type == SampleType.None) + type = SampleType.Normal; - Sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); + SampleSet sampleSet = HitObject.Sample?.Set ?? SampleSet.Normal; + + Sample = audio.Sample.Get($@"Gameplay/{sampleSet.ToString().ToLower()}-hit{type.ToString().ToLower()}"); } private List> nestedHitObjects; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index db792d4a7e..50c8aab5ef 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -50,6 +50,7 @@ namespace osu.Game { get { + // ReSharper disable once RedundantAssignment bool isDebug = false; // Debug.Assert conditions are only evaluated in debug mode Debug.Assert(isDebug = true); diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index d70aec28b2..1b4692f50e 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics; @@ -30,7 +31,7 @@ namespace osu.Game.Overlays { private MusicControllerBackground backgroundSprite; private DragBar progress; - private TextAwesome playButton, listButton; + private TextAwesome playButton; private SpriteText title, artist; private List playList; @@ -59,6 +60,8 @@ namespace osu.Game.Overlays protected override bool OnDrag(InputState state) { + Trace.Assert(state.Mouse.PositionMouseDown != null, "state.Mouse.PositionMouseDown != null"); + Vector2 change = state.Mouse.Position - state.Mouse.PositionMouseDown.Value; // Diminish the drag distance as we go further to simulate "rubber band" feeling. @@ -187,7 +190,7 @@ namespace osu.Game.Overlays Position = new Vector2(20, -30), Children = new Drawable[] { - listButton = new TextAwesome + new TextAwesome { TextSize = 15, Icon = FontAwesome.fa_bars, diff --git a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs index 492a948143..cd1ce56011 100644 --- a/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressCompletionNotification.cs @@ -10,11 +10,8 @@ namespace osu.Game.Overlays.Notifications { public class ProgressCompletionNotification : SimpleNotification { - private ProgressNotification progressNotification; - - public ProgressCompletionNotification(ProgressNotification progressNotification) + public ProgressCompletionNotification() { - this.progressNotification = progressNotification; Icon = FontAwesome.fa_check; } diff --git a/osu.Game/Overlays/Notifications/ProgressNotification.cs b/osu.Game/Overlays/Notifications/ProgressNotification.cs index 7d61a79af4..9dcee5c8af 100644 --- a/osu.Game/Overlays/Notifications/ProgressNotification.cs +++ b/osu.Game/Overlays/Notifications/ProgressNotification.cs @@ -90,7 +90,7 @@ namespace osu.Game.Overlays.Notifications private ProgressNotificationState state; - protected virtual Notification CreateCompletionNotification() => new ProgressCompletionNotification(this) + protected virtual Notification CreateCompletionNotification() => new ProgressCompletionNotification() { Activated = CompletionClickAction, Text = $"Task \"{Text}\" has completed!" diff --git a/osu.Game/Overlays/Notifications/SimpleNotification.cs b/osu.Game/Overlays/Notifications/SimpleNotification.cs index 0a33e2f416..b06994d61a 100644 --- a/osu.Game/Overlays/Notifications/SimpleNotification.cs +++ b/osu.Game/Overlays/Notifications/SimpleNotification.cs @@ -81,10 +81,8 @@ namespace osu.Game.Overlays.Notifications set { - if (base.Read = value) - Light.FadeOut(100); - else - Light.FadeIn(100); + base.Read = value; + Light.FadeTo(value ? 1 : 0, 100); } } } diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 04048dcf98..463f21bcdd 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -147,11 +147,8 @@ namespace osu.Game.Overlays var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); var next = sidebarButtons.SingleOrDefault(sb => sb.Section == bestCandidate); - if (next != null) - { - previous.Selected = false; - next.Selected = true; - } + if (next != null) next.Selected = true; + if (previous != null) previous.Selected = false; } } diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index a01c8eb177..79698a4f3e 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -30,7 +30,7 @@ namespace osu.Game.Overlays.Toolbar protected override bool BlockPassThroughInput => false; - private const int transition_time = 500; + private const double transition_time = 500; private const float alpha_hovering = 0.8f; private const float alpha_normal = 0.6f; diff --git a/osu.Game/Screens/GameScreenWhiteBox.cs b/osu.Game/Screens/GameScreenWhiteBox.cs index b4cbf5a622..f659d3681e 100644 --- a/osu.Game/Screens/GameScreenWhiteBox.cs +++ b/osu.Game/Screens/GameScreenWhiteBox.cs @@ -21,7 +21,7 @@ namespace osu.Game.Screens { private BackButton popButton; - private const int transition_time = 1000; + private const double transition_time = 1000; protected virtual IEnumerable PossibleChildren => null; diff --git a/osu.Game/Screens/Menu/Button.cs b/osu.Game/Screens/Menu/Button.cs index 023801b6fe..7af03d2f11 100644 --- a/osu.Game/Screens/Menu/Button.cs +++ b/osu.Game/Screens/Menu/Button.cs @@ -28,16 +28,11 @@ namespace osu.Game.Screens.Menu { private Container iconText; private Container box; - private Box boxColourLayer; private Box boxHoverLayer; - private Color4 colour; private TextAwesome icon; private string internalName; - private readonly FontAwesome symbol; private Action clickAction; - private readonly float extraWidth; private Key triggerKey; - private string text; private SampleChannel sampleClick; public override bool Contains(Vector2 screenSpacePos) @@ -48,12 +43,8 @@ namespace osu.Game.Screens.Menu public Button(string text, string internalName, FontAwesome symbol, Color4 colour, Action clickAction = null, float extraWidth = 0, Key triggerKey = Key.Unknown) { this.internalName = internalName; - this.symbol = symbol; - this.colour = colour; this.clickAction = clickAction; - this.extraWidth = extraWidth; this.triggerKey = triggerKey; - this.text = text; AutoSizeAxes = Axes.Both; Alpha = 0; @@ -80,7 +71,7 @@ namespace osu.Game.Screens.Menu Shear = new Vector2(ButtonSystem.WEDGE_WIDTH / boxSize.Y, 0), Children = new [] { - boxColourLayer = new Box + new Box { EdgeSmoothness = new Vector2(1.5f, 0), RelativeSizeAxes = Axes.Both, @@ -321,12 +312,12 @@ namespace osu.Game.Screens.Menu case ButtonState.Expanded: const int expand_duration = 500; box.ScaleTo(new Vector2(1, 1), expand_duration, EasingTypes.OutExpo); - FadeIn(expand_duration / 6); + FadeIn(expand_duration / 6f); break; case ButtonState.Exploded: const int explode_duration = 200; box.ScaleTo(new Vector2(2, 1), explode_duration, EasingTypes.OutExpo); - FadeOut(explode_duration / 4 * 3); + FadeOut(explode_duration / 4f * 3); break; } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 7f45e400f4..cb494ef79f 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -81,6 +81,9 @@ namespace osu.Game.Screens.Play if ((Beatmap?.Beatmap?.HitObjects.Count ?? 0) == 0) throw new Exception("No valid objects were found!"); + + if (Beatmap == null) + throw new Exception("Beatmap was not loaded"); } catch (Exception e) { diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index c2eb0cc2a8..98e08afdb9 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -167,7 +167,7 @@ namespace osu.Game.Screens.Play { new Sprite { - Texture = beatmap.Background, + Texture = beatmap?.Background, Origin = Anchor.Centre, Anchor = Anchor.Centre, FillMode = FillMode.Fill, @@ -176,7 +176,7 @@ namespace osu.Game.Screens.Play }, new OsuSpriteText { - Text = beatmap.BeatmapInfo?.Version, + Text = beatmap?.BeatmapInfo?.Version, TextSize = 26, Font = @"Exo2.0-MediumItalic", Origin = Anchor.TopCentre, diff --git a/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs b/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs index 6479aa3638..899c329be4 100644 --- a/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs +++ b/osu.Game/Screens/Tournament/ScrollingTeamContainer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -109,7 +110,11 @@ namespace osu.Game.Screens.Tournament break; case ScrollState.Stopped: // Find closest to center + if (!Children.Any()) + break; + Drawable closest = null; + foreach (var c in Children) { if (!(c is ScrollingTeam)) @@ -128,6 +133,8 @@ namespace osu.Game.Screens.Tournament closest = c; } + Trace.Assert(closest != null, "closest != null"); + offset += DrawWidth / 2f - (closest.Position.X + closest.DrawWidth / 2f); ScrollingTeam st = closest as ScrollingTeam; @@ -310,7 +317,7 @@ namespace osu.Game.Screens.Tournament public override void Apply(Drawable d) { base.Apply(d); - (d as ScrollingTeamContainer).speed = CurrentValue; + ((ScrollingTeamContainer)d).speed = CurrentValue; } }