1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 08:07:24 +08:00

Merge pull request #1474 from miterosan/null_check

Add null check in parameters.
This commit is contained in:
Dan Balasescu 2017-11-09 19:21:22 +09:00 committed by GitHub
commit 91ccb1bffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 110 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Lists;
@ -85,6 +86,9 @@ namespace osu.Game.Beatmaps.ControlPoints
private T binarySearch<T>(SortedList<T> list, double time, T prePoint = null)
where T : ControlPoint, new()
{
if (list == null)
throw new ArgumentNullException(nameof(list));
if (list.Count == 0)
return new T();

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
@ -12,6 +13,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapBackgroundSprite(WorkingBeatmap working)
{
if (working == null)
throw new ArgumentNullException(nameof(working));
this.working = working;
}

View File

@ -72,6 +72,11 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapManager manager)
{
if (beatmapSet == null)
throw new ArgumentNullException(nameof(beatmapSet));
if (manager == null)
throw new ArgumentNullException(nameof(manager));
BeatmapSet = beatmapSet;
WorkingBeatmap beatmap = manager.GetWorkingBeatmap(BeatmapSet.Beatmaps.FirstOrDefault());

View File

@ -73,6 +73,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapPanel(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
Beatmap = beatmap;
Height *= 0.60f;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
@ -12,6 +13,9 @@ namespace osu.Game.Beatmaps.Drawables
private readonly BeatmapSetInfo set;
public BeatmapSetCover(BeatmapSetInfo set)
{
if (set == null)
throw new ArgumentNullException(nameof(set));
this.set = set;
}

View File

@ -36,6 +36,9 @@ namespace osu.Game.Beatmaps.Drawables
public BeatmapSetHeader(WorkingBeatmap beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
Children = new Drawable[]
@ -88,6 +91,9 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
title.Current = localisation.GetUnicodePreference(beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title);
artist.Current = localisation.GetUnicodePreference(beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist);
}
@ -154,6 +160,9 @@ namespace osu.Game.Beatmaps.Drawables
public void AddDifficultyIcons(IEnumerable<BeatmapPanel> panels)
{
if (panels == null)
throw new ArgumentNullException(nameof(panels));
foreach (var p in panels)
difficultyIcons.Add(new DifficultyIcon(p.Beatmap));
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
@ -23,6 +24,9 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader]
private void load(OsuColour palette)
{
if (palette == null)
throw new ArgumentNullException(nameof(palette));
this.palette = palette;
AccentColour = getColour(beatmap);
}
@ -39,6 +43,9 @@ namespace osu.Game.Beatmaps.Drawables
private DifficultyRating getDifficultyRating(BeatmapInfo beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
var rating = beatmap.StarDifficulty;
if (rating < 1.5) return DifficultyRating.Easy;

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
@ -15,6 +16,9 @@ namespace osu.Game.Beatmaps.Drawables
public DifficultyIcon(BeatmapInfo beatmap) : base(beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
Size = new Vector2(20);
}

View File

@ -18,6 +18,9 @@ namespace osu.Game.Beatmaps.Formats
public static BeatmapDecoder GetDecoder(StreamReader stream)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
string line;
do { line = stream.ReadLine()?.Trim(); }
while (line != null && line.Length == 0);

View File

@ -70,6 +70,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleGeneral(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
@ -129,6 +134,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleEditor(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
switch (pair.Key)
@ -153,6 +163,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleMetadata(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var metadata = beatmap.BeatmapInfo.Metadata;
@ -194,6 +209,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleDifficulty(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
@ -226,6 +246,9 @@ namespace osu.Game.Beatmaps.Formats
/// <param name="line">The line which may contains variables.</param>
private void decodeVariables(ref string line)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
while (line.IndexOf('$') >= 0)
{
string origLine = line;
@ -244,6 +267,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleEvents(Beatmap beatmap, string line, ref StoryboardSprite storyboardSprite, ref CommandTimelineGroup timelineGroup)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
var depth = 0;
while (line.StartsWith(" ") || line.StartsWith("_"))
{
@ -469,6 +497,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleTimingPoints(Beatmap beatmap, string line)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
string[] split = line.Split(',');
double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo);
@ -555,6 +588,11 @@ namespace osu.Game.Beatmaps.Formats
private void handleColours(Beatmap beatmap, string line, ref bool hasCustomColours)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, ':');
string[] split = pair.Value.Split(',');
@ -587,6 +625,9 @@ namespace osu.Game.Beatmaps.Formats
private void handleVariables(string line)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
var pair = splitKeyVal(line, '=');
variables[pair.Key] = pair.Value;
}
@ -603,6 +644,11 @@ namespace osu.Game.Beatmaps.Formats
protected override void ParseFile(StreamReader stream, Beatmap beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
if (stream == null)
throw new ArgumentNullException(nameof(stream));
beatmap.BeatmapInfo.BeatmapVersion = beatmapVersion;
Section section = Section.None;
@ -679,6 +725,9 @@ namespace osu.Game.Beatmaps.Formats
private KeyValuePair<string, string> splitKeyVal(string line, char separator)
{
if (line == null)
throw new ArgumentNullException(nameof(line));
var split = line.Trim().Split(new[] { separator }, 2);
return new KeyValuePair<string, string>

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -25,6 +26,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));
Texture texture = null;
if (user != null && user.Id > 1) texture = textures.Get($@"https://a.ppy.sh/{user.Id}");
if (texture == null) texture = textures.Get(@"Online/avatar-guest");

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -45,6 +46,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore ts)
{
if (ts == null)
throw new ArgumentNullException(nameof(ts));
textures = ts;
sprite.Texture = textures.Get($@"Flags/{flagName}");
}

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
@ -19,6 +20,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (textures == null)
throw new ArgumentNullException(nameof(textures));
if (!string.IsNullOrEmpty(user.CoverUrl))
Texture = textures.Get(user.CoverUrl);
}

View File

@ -38,6 +38,9 @@ namespace osu.Game.Users
public UserPanel(User user)
{
if (user == null)
throw new ArgumentNullException(nameof(user));
this.user = user;
Height = height - status_height;
@ -173,6 +176,9 @@ namespace osu.Game.Users
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, UserProfileOverlay profile)
{
if (colours == null)
throw new ArgumentNullException(nameof(colours));
Status.ValueChanged += displayStatus;
Status.ValueChanged += status => statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);