Fix possible nullrefs

This commit is contained in:
smoogipoo 2021-09-30 17:54:56 +09:00
parent d2a8f35b4c
commit 4d8418e072
1 changed files with 19 additions and 5 deletions

View File

@ -5,9 +5,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
@ -21,6 +24,7 @@
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Screens.Play.HUD
{
@ -28,10 +32,12 @@ public class DefaultPerformancePointsCounter : RollingCounter<int>, ISkinnableDr
{
public bool UsesFixedAnchor { get; set; }
[Resolved]
[CanBeNull]
[Resolved(CanBeNull = true)]
private ScoreProcessor scoreProcessor { get; set; }
[Resolved]
[CanBeNull]
[Resolved(CanBeNull = true)]
private Player player { get; set; }
private DifficultyCalculator.TimedDifficultyAttributes[] timedAttributes;
@ -47,18 +53,26 @@ private void load(OsuColour colours)
{
Colour = colours.BlueLighter;
gameplayRuleset = player.GameplayRuleset;
timedAttributes = gameplayRuleset.CreateDifficultyCalculator(new GameplayWorkingBeatmap(player.GameplayBeatmap)).CalculateTimed(player.Mods.Value.ToArray()).ToArray();
if (player != null)
{
gameplayRuleset = player.GameplayRuleset;
timedAttributes = gameplayRuleset.CreateDifficultyCalculator(new GameplayWorkingBeatmap(player.GameplayBeatmap)).CalculateTimed(player.Mods.Value.ToArray()).ToArray();
}
}
protected override void LoadComplete()
{
base.LoadComplete();
scoreProcessor.NewJudgement += onNewJudgement;
if (scoreProcessor != null)
scoreProcessor.NewJudgement += onNewJudgement;
}
private void onNewJudgement(JudgementResult judgement)
{
if (player == null)
return;
var attribIndex = Array.BinarySearch(timedAttributes, 0, timedAttributes.Length, new DifficultyCalculator.TimedDifficultyAttributes(judgement.HitObject.GetEndTime(), null));
if (attribIndex < 0)
attribIndex = ~attribIndex - 1;