Mark the property as nullable and add some assert check.

This commit is contained in:
為什麼 2022-07-10 23:47:57 +08:00 committed by andy840119
parent deb39bd330
commit 9134525111
7 changed files with 45 additions and 15 deletions

View File

@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.StateChanges;
using osu.Game.Graphics;
@ -28,16 +30,20 @@ namespace osu.Game.Rulesets.Osu.Mods
public bool RestartOnFail => false;
private OsuInputManager inputManager;
private OsuInputManager? inputManager;
private IFrameStableClock gameplayClock;
private IFrameStableClock? gameplayClock;
private List<OsuReplayFrame> replayFrames;
private List<OsuReplayFrame>? replayFrames;
private int currentFrame;
public void Update(Playfield playfield)
{
Debug.Assert(inputManager != null);
Debug.Assert(gameplayClock != null);
Debug.Assert(replayFrames != null);
if (currentFrame == replayFrames.Count - 1) return;
double time = gameplayClock.CurrentTime;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -31,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public override double ScoreMultiplier => UsesDefaultConfiguration ? 1.12 : 1;
public override Type[] IncompatibleMods => new[] { typeof(OsuModFlashlight) };
private DrawableOsuBlinds blinds;
private DrawableOsuBlinds? blinds;
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
@ -40,6 +41,8 @@ namespace osu.Game.Rulesets.Osu.Mods
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
{
Debug.Assert(blinds != null);
healthProcessor.Health.ValueChanged += health => { blinds.AnimateClosedness((float)health.NewValue); };
}

View File

@ -4,6 +4,7 @@
using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Events;
@ -51,14 +52,14 @@ namespace osu.Game.Rulesets.Osu.Mods
public override float DefaultFlashlightSize => 180;
private OsuFlashlight flashlight;
private OsuFlashlight? flashlight;
protected override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(this);
public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{
if (drawable is DrawableSlider s)
s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange;
s.Tracking.ValueChanged += flashlight.AsNonNull().OnSliderTrackingChange;
}
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
@ -26,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public override double ScoreMultiplier => 1;
public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax), typeof(OsuModRepel) };
private IFrameStableClock gameplayClock;
private IFrameStableClock? gameplayClock;
[SettingSource("Attraction strength", "How strong the pull is.", 0)]
public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f)
@ -74,6 +75,8 @@ namespace osu.Game.Rulesets.Osu.Mods
{
double dampLength = Interpolation.Lerp(3000, 40, AttractionStrength.Value);
Debug.Assert(gameplayClock != null);
float x = (float)Interpolation.DampContinuously(hitObject.X, destination.X, dampLength, gameplayClock.ElapsedFrameTime);
float y = (float)Interpolation.DampContinuously(hitObject.Y, destination.Y, dampLength, gameplayClock.ElapsedFrameTime);

View File

@ -4,6 +4,7 @@
using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{
public override string Description => "Where's the cursor?";
private PeriodTracker spinnerPeriods;
private PeriodTracker? spinnerPeriods;
[SettingSource(
"Hidden at combo",
@ -41,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public void Update(Playfield playfield)
{
bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.IsInAny(playfield.Clock.CurrentTime);
bool shouldAlwaysShowCursor = IsBreakTime.Value || spinnerPeriods.AsNonNull().IsInAny(playfield.Clock.CurrentTime);
float targetAlpha = shouldAlwaysShowCursor ? 1 : ComboBasedAlpha;
playfield.Cursor.Alpha = (float)Interpolation.Lerp(playfield.Cursor.Alpha, targetAlpha, Math.Clamp(playfield.Time.Elapsed / TRANSITION_DURATION, 0, 1));
}

View File

@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private bool isDownState;
private bool wasLeft;
private OsuInputManager osuInputManager;
private OsuInputManager? osuInputManager;
private ReplayState<OsuAction>? state;
private double lastStateChangeTime;
@ -44,6 +44,8 @@ namespace osu.Game.Rulesets.Osu.Mods
public void ApplyToPlayer(Player player)
{
Debug.Assert(osuInputManager != null);
if (osuInputManager.ReplayInputHandler != null)
{
hasReplay = true;
@ -132,6 +134,8 @@ namespace osu.Game.Rulesets.Osu.Mods
wasLeft = !wasLeft;
}
Debug.Assert(osuInputManager != null);
state?.Apply(osuInputManager.CurrentState, osuInputManager);
}
}

View File

@ -3,8 +3,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
@ -94,11 +96,11 @@ namespace osu.Game.Rulesets.Osu.Mods
#region Private Fields
private ControlPointInfo controlPointInfo;
private ControlPointInfo? controlPointInfo;
private List<OsuHitObject> originalHitObjects;
private List<OsuHitObject>? originalHitObjects;
private Random rng;
private Random? rng;
#endregion
@ -158,7 +160,7 @@ namespace osu.Game.Rulesets.Osu.Mods
circle.ApproachCircle.Hide();
}
using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.TimingPointAt(startTime).BeatLength - undim_duration))
using (circle.BeginAbsoluteSequence(startTime - controlPointInfo.AsNonNull().TimingPointAt(startTime).BeatLength - undim_duration))
circle.FadeColour(Color4.White, undim_duration);
}
@ -200,6 +202,8 @@ namespace osu.Game.Rulesets.Osu.Mods
private IEnumerable<double> generateBeats(IBeatmap beatmap)
{
Debug.Assert(originalHitObjects != null);
double startTime = originalHitObjects.First().StartTime;
double endTime = originalHitObjects.Last().GetEndTime();
@ -228,6 +232,8 @@ namespace osu.Game.Rulesets.Osu.Mods
private void addHitSamples(IEnumerable<OsuHitObject> hitObjects)
{
Debug.Assert(originalHitObjects != null);
foreach (var obj in hitObjects)
{
var samples = getSamplesAtTime(originalHitObjects, obj.StartTime);
@ -240,6 +246,8 @@ namespace osu.Game.Rulesets.Osu.Mods
private void fixComboInfo(List<OsuHitObject> hitObjects)
{
Debug.Assert(originalHitObjects != null);
// Copy combo indices from an original object at the same time or from the closest preceding object
// (Objects lying between two combos are assumed to belong to the preceding combo)
hitObjects.ForEach(newObj =>
@ -276,7 +284,7 @@ namespace osu.Game.Rulesets.Osu.Mods
{
if (hitObjects.Count == 0) return;
float nextSingle(float max = 1f) => (float)(rng.NextDouble() * max);
float nextSingle(float max = 1f) => (float)(rng.AsNonNull().NextDouble() * max);
const float two_pi = MathF.PI * 2;
@ -357,6 +365,8 @@ namespace osu.Game.Rulesets.Osu.Mods
/// <param name="time">The time to be checked.</param>=
private bool isInsideBreakPeriod(IEnumerable<BreakPeriod> breaks, double time)
{
Debug.Assert(originalHitObjects != null);
return breaks.Any(breakPeriod =>
{
var firstObjAfterBreak = originalHitObjects.First(obj => almostBigger(obj.StartTime, breakPeriod.EndTime));
@ -372,6 +382,8 @@ namespace osu.Game.Rulesets.Osu.Mods
int i = 0;
double currentTime = timingPoint.Time;
Debug.Assert(controlPointInfo != null);
while (!definitelyBigger(currentTime, mapEndTime) && ReferenceEquals(controlPointInfo.TimingPointAt(currentTime), timingPoint))
{
beats.Add(Math.Floor(currentTime));