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

Fix CI reported warnings

This commit is contained in:
Dean Herbert 2022-01-12 22:34:07 +09:00
parent 08da948afc
commit 51251e3204
25 changed files with 123 additions and 65 deletions

View File

@ -174,7 +174,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
pointGrid.Content = points;
if (score.HitEvents == null || score.HitEvents.Count == 0)
if (score.HitEvents.Count == 0)
return;
// Todo: This should probably not be done like this.

View File

@ -31,7 +31,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
{
var beatmap = decodeAsJson(normal);
var meta = beatmap.BeatmapInfo.Metadata;
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineID);
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet?.OnlineID);
Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);

View File

@ -56,7 +56,7 @@ namespace osu.Game.Tests.Beatmaps.IO
var meta = beatmap.Metadata;
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet.OnlineID);
Assert.AreEqual(241526, beatmap.BeatmapInfo.BeatmapSet?.OnlineID);
Assert.AreEqual("Soleily", meta.Artist);
Assert.AreEqual("Soleily", meta.ArtistUnicode);
Assert.AreEqual("03. Renatus - Soleily 192kbps.mp3", meta.AudioFile);

View File

@ -7,6 +7,7 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
@ -30,7 +31,13 @@ namespace osu.Game.Tests.Beatmaps
AddStep("add beatmap", () =>
{
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.HitObjectAdded += h => addedObject = h;
});
@ -49,7 +56,14 @@ namespace osu.Game.Tests.Beatmaps
EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () =>
{
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
editorBeatmap.HitObjectRemoved += h => removedObject = h;
});
AddStep("remove hitobject", () => editorBeatmap.Remove(editorBeatmap.HitObjects.First()));
@ -71,7 +85,14 @@ namespace osu.Game.Tests.Beatmaps
{
EditorBeatmap editorBeatmap;
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
editorBeatmap.HitObjectUpdated += h => changedObject = h;
});
@ -91,7 +112,13 @@ namespace osu.Game.Tests.Beatmaps
AddStep("add beatmap", () =>
{
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.HitObjectUpdated += h => changedObject = h;
});
@ -111,7 +138,14 @@ namespace osu.Game.Tests.Beatmaps
public void TestRemovedHitObjectStartTimeChangeEvent()
{
var hitCircle = new HitCircle();
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects = { hitCircle }
});
HitObject changedObject = null;
editorBeatmap.HitObjectUpdated += h => changedObject = h;
@ -131,6 +165,10 @@ namespace osu.Game.Tests.Beatmaps
{
var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects =
{
new HitCircle(),
@ -156,6 +194,10 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
HitObjects =
{
new HitCircle(),
@ -185,7 +227,13 @@ namespace osu.Game.Tests.Beatmaps
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
for (int i = 0; i < 10; i++)
{
@ -220,7 +268,13 @@ namespace osu.Game.Tests.Beatmaps
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo,
},
});
editorBeatmap.Add(new HitCircle());
});

View File

@ -9,11 +9,9 @@ using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.IO.Archives;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
@ -151,12 +149,8 @@ namespace osu.Game.Tests.Scores.IO
public static async Task<ScoreInfo> LoadScoreIntoOsu(OsuGameBase osu, ScoreInfo score, ArchiveReader archive = null)
{
var beatmapManager = osu.Dependencies.Get<BeatmapManager>();
// clone to avoid attaching the input score to realm.
score = score.DeepClone();
score.BeatmapInfo ??= beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First();
score.Ruleset ??= new OsuRuleset().RulesetInfo;
var scoreManager = osu.Dependencies.Get<ScoreManager>();
await scoreManager.Import(score, archive);

View File

@ -70,7 +70,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
var beatmap = new BeatmapInfo
{
Ruleset = rulesets.GetRuleset(i % 4),
Ruleset = rulesets.GetRuleset(i % 4) ?? throw new InvalidOperationException(),
OnlineID = beatmapId,
Length = length,
BPM = bpm,

View File

@ -67,7 +67,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{
AddStep("set beatmap", () => advancedStats.BeatmapInfo = new BeatmapInfo
{
Ruleset = rulesets.GetRuleset(3),
Ruleset = rulesets.GetRuleset(3) ?? throw new InvalidOperationException(),
BaseDifficulty = new BeatmapDifficulty
{
CircleSize = 5,

View File

@ -81,7 +81,7 @@ namespace osu.Game.Tournament
ladder ??= new LadderInfo();
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value?.ShortName)
ladder.Ruleset.Value = RulesetStore.GetRuleset(ladder.Ruleset.Value.ShortName)
?? RulesetStore.AvailableRulesets.First();
bool addedInfo = false;

View File

@ -86,7 +86,7 @@ namespace osu.Game.Online.API.Requests.Responses
/// <returns></returns>
public ScoreInfo CreateScoreInfo(RulesetStore rulesets, BeatmapInfo beatmap = null)
{
var ruleset = rulesets.GetRuleset(RulesetID);
var ruleset = rulesets.GetRuleset(RulesetID) ?? throw new InvalidOperationException();
var rulesetInstance = ruleset.CreateInstance();
@ -99,7 +99,7 @@ namespace osu.Game.Online.API.Requests.Responses
{
TotalScore = TotalScore,
MaxCombo = MaxCombo,
BeatmapInfo = beatmap,
BeatmapInfo = beatmap ?? new BeatmapInfo(),
User = User,
Accuracy = Accuracy,
OnlineID = OnlineID,

View File

@ -73,7 +73,7 @@ namespace osu.Game.Online.Rooms
TotalScore = TotalScore,
MaxCombo = MaxCombo,
BeatmapInfo = beatmap,
Ruleset = rulesets.GetRuleset(playlistItem.RulesetID),
Ruleset = rulesets.GetRuleset(playlistItem.RulesetID) ?? throw new InvalidOperationException(),
Statistics = Statistics,
User = User,
Accuracy = Accuracy,

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
@ -131,9 +132,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2),
Children = Score.Mods.Select(mod => new ModIcon(rulesets.GetRuleset(Score.RulesetID).CreateInstance().CreateModFromAcronym(mod.Acronym))
Children = Score.Mods.Select(mod =>
{
Scale = new Vector2(0.35f)
var ruleset = rulesets.GetRuleset(Score.RulesetID) ?? throw new InvalidOperationException();
return new ModIcon(ruleset.CreateInstance().CreateModFromAcronym(mod.Acronym))
{
Scale = new Vector2(0.35f)
};
}).ToList(),
}
}

View File

@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Edit.Checks
else if (texture.Width < low_width || texture.Height < low_height)
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet?.GetPathForFile(backgroundFile);
using (Stream stream = context.WorkingBeatmap.GetStream(storagePath))
{

View File

@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Edit.Checks
}
// If the file is set, also make sure it still exists.
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
string storagePath = context.Beatmap.BeatmapInfo.BeatmapSet?.GetPathForFile(filename);
if (storagePath != null)
yield break;

View File

@ -30,32 +30,35 @@ namespace osu.Game.Rulesets.Edit.Checks
{
var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;
foreach (var file in beatmapSet.Files)
if (beatmapSet != null)
{
using (Stream data = context.WorkingBeatmap.GetStream(file.File.GetStoragePath()))
foreach (var file in beatmapSet.Files)
{
if (data == null)
continue;
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Prescan, fileCallbacks.Callbacks, fileCallbacks.Handle);
if (decodeStream == 0)
using (Stream data = context.WorkingBeatmap.GetStream(file.File.GetStoragePath()))
{
// If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
// Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))
yield return new IssueTemplateBadFormat(this).Create(file.Filename);
if (data == null)
continue;
continue;
var fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(data));
int decodeStream = Bass.CreateStream(StreamSystem.NoBuffer, BassFlags.Decode | BassFlags.Prescan, fileCallbacks.Callbacks, fileCallbacks.Handle);
if (decodeStream == 0)
{
// If the file is not likely to be properly parsed by Bass, we don't produce Error issues about it.
// Image files and audio files devoid of audio data both fail, for example, but neither would be issues in this check.
if (hasAudioExtension(file.Filename) && probablyHasAudioData(data))
yield return new IssueTemplateBadFormat(this).Create(file.Filename);
continue;
}
long length = Bass.ChannelGetLength(decodeStream);
double ms = Bass.ChannelBytes2Seconds(decodeStream, length) * 1000;
// Extremely short audio files do not play on some soundcards, resulting in nothing being heard in-game for some users.
if (ms > 0 && ms < ms_threshold)
yield return new IssueTemplateTooShort(this).Create(file.Filename, ms);
}
long length = Bass.ChannelGetLength(decodeStream);
double ms = Bass.ChannelBytes2Seconds(decodeStream, length) * 1000;
// Extremely short audio files do not play on some soundcards, resulting in nothing being heard in-game for some users.
if (ms > 0 && ms < ms_threshold)
yield return new IssueTemplateTooShort(this).Create(file.Filename, ms);
}
}
}

View File

@ -21,12 +21,15 @@ namespace osu.Game.Rulesets.Edit.Checks
{
var beatmapSet = context.Beatmap.BeatmapInfo.BeatmapSet;
foreach (var file in beatmapSet.Files)
if (beatmapSet != null)
{
using (Stream data = context.WorkingBeatmap.GetStream(file.File.GetStoragePath()))
foreach (var file in beatmapSet.Files)
{
if (data?.Length == 0)
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
using (Stream data = context.WorkingBeatmap.GetStream(file.File.GetStoragePath()))
{
if (data?.Length == 0)
yield return new IssueTemplateZeroBytes(this).Create(file.Filename);
}
}
}
}

View File

@ -76,9 +76,6 @@ namespace osu.Game.Rulesets.Mods
var difficulty = beatmap.Value.BeatmapInfo.BaseDifficulty;
if (difficulty == null)
return;
// generally should always be implemented, else the slider will have a zero default.
if (difficultyBindable.ReadCurrentFromDifficulty == null)
return;

View File

@ -13,7 +13,7 @@ namespace osu.Game.Screens.Edit.Components.Menus
public BeatmapInfo BeatmapInfo { get; }
public DifficultyMenuItem(BeatmapInfo beatmapInfo, bool selected, Action<BeatmapInfo> difficultyChangeFunc)
: base(beatmapInfo.DifficultyName ?? "(unnamed)", null)
: base(string.IsNullOrEmpty(beatmapInfo.DifficultyName) ? "(unnamed)" : beatmapInfo.DifficultyName, null)
{
BeatmapInfo = beatmapInfo;
State.Value = selected;

View File

@ -40,7 +40,7 @@ namespace osu.Game.Screens.Edit.Compose
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
ruleset = parent.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo.Ruleset?.CreateInstance();
ruleset = parent.Get<IBindable<WorkingBeatmap>>().Value.BeatmapInfo.Ruleset.CreateInstance();
composer = ruleset?.CreateHitObjectComposer();
// make the composer available to the timeline and other components in this screen.

View File

@ -599,7 +599,8 @@ namespace osu.Game.Screens.Edit
if (isNewBeatmap)
{
// confirming exit without save means we should delete the new beatmap completely.
beatmapManager.Delete(playableBeatmap.BeatmapInfo.BeatmapSet);
if (playableBeatmap.BeatmapInfo.BeatmapSet != null)
beatmapManager.Delete(playableBeatmap.BeatmapInfo.BeatmapSet);
// eagerly clear contents before restoring default beatmap to prevent value change callbacks from firing.
ClearInternal();

View File

@ -102,7 +102,7 @@ namespace osu.Game.Screens.Edit
if (beatmapSkin is Skin skin)
BeatmapSkin = new EditorBeatmapSkin(skin);
beatmapProcessor = playableBeatmap.BeatmapInfo.Ruleset?.CreateInstance().CreateBeatmapProcessor(PlayableBeatmap);
beatmapProcessor = playableBeatmap.BeatmapInfo.Ruleset.CreateInstance().CreateBeatmapProcessor(PlayableBeatmap);
foreach (var obj in HitObjects)
trackStartTime(obj);

View File

@ -33,7 +33,7 @@ namespace osu.Game.Screens.Edit.Setup
new DesignSection(),
};
var rulesetSpecificSection = beatmap.BeatmapInfo.Ruleset?.CreateInstance().CreateEditorSetupSection();
var rulesetSpecificSection = beatmap.BeatmapInfo.Ruleset.CreateInstance().CreateEditorSetupSection();
if (rulesetSpecificSection != null)
sectionsEnumerable.Add(rulesetSpecificSection);

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -13,7 +12,6 @@ using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Placeholders;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osuTK;
@ -76,7 +74,7 @@ namespace osu.Game.Screens.Ranking.Statistics
if (newScore == null)
return;
if (newScore.HitEvents == null || newScore.HitEvents.Count == 0)
if (newScore.HitEvents.Count == 0)
{
content.Add(new FillFlowContainer
{
@ -104,7 +102,7 @@ namespace osu.Game.Screens.Ranking.Statistics
// Todo: The placement of this is temporary. Eventually we'll both generate the playable beatmap _and_ run through it in a background task to generate the hit events.
Task.Run(() =>
{
playableBeatmap = beatmapManager.GetWorkingBeatmap(newScore.BeatmapInfo).GetPlayableBeatmap(newScore.Ruleset, newScore.Mods ?? Array.Empty<Mod>());
playableBeatmap = beatmapManager.GetWorkingBeatmap(newScore.BeatmapInfo).GetPlayableBeatmap(newScore.Ruleset, newScore.Mods);
}, loadCancellation.Token).ContinueWith(t => Schedule(() =>
{
var rows = new FillFlowContainer

View File

@ -324,7 +324,7 @@ namespace osu.Game.Screens.Select
});
// no difficulty means it can't have a status to show
if (beatmapInfo.DifficultyName == null)
if (string.IsNullOrEmpty(beatmapInfo.DifficultyName))
StatusPill.Hide();
addInfoLabels();

View File

@ -53,7 +53,7 @@ namespace osu.Game.Screens.Select
if (!maximumStars.IsDefault)
criteria.UserStarDifficulty.Max = maximumStars.Value;
criteria.RulesetCriteria = ruleset.Value.CreateInstance()?.CreateRulesetFilterCriteria();
criteria.RulesetCriteria = ruleset.Value.CreateInstance().CreateRulesetFilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
return criteria;

View File

@ -98,6 +98,8 @@ namespace osu.Game.Tests.Beatmaps
userSkinInfo.Files.Clear();
userSkinInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = userFile }, userFile));
Debug.Assert(beatmapInfo.BeatmapSet != null);
beatmapInfo.BeatmapSet.Files.Clear();
beatmapInfo.BeatmapSet.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = beatmapFile }, beatmapFile));