Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply NRT to osu.Game.Beatmaps.Formats namespace #24568

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions osu.Game/Beatmaps/Formats/Decoder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using osu.Game.IO;
using osu.Game.Rulesets;

Expand Down Expand Up @@ -45,7 +42,7 @@ static Decoder()
/// Register dependencies for use with static decoder classes.
/// </summary>
/// <param name="rulesets">A store containing all available rulesets (used by <see cref="LegacyBeatmapDecoder"/>).</param>
public static void RegisterDependencies([NotNull] RulesetStore rulesets)
public static void RegisterDependencies(RulesetStore rulesets)
{
LegacyBeatmapDecoder.RulesetStore = rulesets ?? throw new ArgumentNullException(nameof(rulesets));
}
Expand All @@ -63,7 +60,7 @@ public static Decoder<T> GetDecoder<T>(LineBufferedReader stream)
throw new IOException(@"Unknown decoder type");

// start off with the first line of the file
string line = stream.PeekLine()?.Trim();
string? line = stream.PeekLine()?.Trim();

while (line != null && line.Length == 0)
{
Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Beatmaps/Formats/IHasComboColours.cs
Original file line number Diff line number Diff line change
@@ -1,8 +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.

#nullable disable

using System.Collections.Generic;
using osuTK.Graphics;

Expand All @@ -13,7 +11,7 @@ public interface IHasComboColours
/// <summary>
/// Retrieves the list of combo colours for presentation only.
/// </summary>
IReadOnlyList<Color4> ComboColours { get; }
IReadOnlyList<Color4>? ComboColours { get; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's kinda painful, but can't be easily eliminated, so I'm looking away for the time being...

The long term answer to this is probably interface separation or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, right now it's there with reason so I didn't touch it.


/// <summary>
/// The list of custom combo colours.
Expand Down
10 changes: 4 additions & 6 deletions osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +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.

#nullable disable

#pragma warning disable 618

using System;
Expand Down Expand Up @@ -36,11 +34,11 @@ public class LegacyBeatmapDecoder : LegacyDecoder<Beatmap>
/// </summary>
private const double control_point_leniency = 1;

internal static RulesetStore RulesetStore;
internal static RulesetStore? RulesetStore;

private Beatmap beatmap;
private Beatmap beatmap = null!;

private ConvertHitObjectParser parser;
private ConvertHitObjectParser? parser;

private LegacySampleBank defaultSampleBank;
private int defaultSampleVolume = 100;
Expand Down Expand Up @@ -222,7 +220,7 @@ private void handleGeneral(string line)
case @"Mode":
int rulesetID = Parsing.ParseInt(pair.Value);

beatmap.BeatmapInfo.Ruleset = RulesetStore.GetRuleset(rulesetID) ?? throw new ArgumentException("Ruleset is not available locally.");
beatmap.BeatmapInfo.Ruleset = RulesetStore?.GetRuleset(rulesetID) ?? throw new ArgumentException("Ruleset is not available locally.");

switch (rulesetID)
{
Expand Down
16 changes: 6 additions & 10 deletions osu.Game/Beatmaps/Formats/LegacyBeatmapEncoder.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// 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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using JetBrains.Annotations;
using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Legacy;
Expand All @@ -34,8 +31,7 @@ public class LegacyBeatmapEncoder

private readonly IBeatmap beatmap;

[CanBeNull]
private readonly ISkin skin;
private readonly ISkin? skin;

private readonly int onlineRulesetID;

Expand All @@ -44,7 +40,7 @@ public class LegacyBeatmapEncoder
/// </summary>
/// <param name="beatmap">The beatmap to encode.</param>
/// <param name="skin">The beatmap's skin, used for encoding combo colours.</param>
public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] ISkin skin)
public LegacyBeatmapEncoder(IBeatmap beatmap, ISkin? skin)
{
this.beatmap = beatmap;
this.skin = skin;
Expand Down Expand Up @@ -180,8 +176,8 @@ private void handleControlPoints(TextWriter writer)

writer.WriteLine("[TimingPoints]");

SampleControlPoint lastRelevantSamplePoint = null;
DifficultyControlPoint lastRelevantDifficultyPoint = null;
SampleControlPoint? lastRelevantSamplePoint = null;
DifficultyControlPoint? lastRelevantDifficultyPoint = null;

// In osu!taiko and osu!mania, a scroll speed is stored as "slider velocity" in legacy formats.
// In that case, a scrolling speed change is a global effect and per-hit object difficulty control points are ignored.
Expand Down Expand Up @@ -585,7 +581,7 @@ private LegacyHitSoundType toLegacyHitSoundType(IList<HitSampleInfo> samples)
return type;
}

private LegacySampleBank toLegacySampleBank(string sampleBank)
private LegacySampleBank toLegacySampleBank(string? sampleBank)
{
switch (sampleBank?.ToLowerInvariant())
{
Expand All @@ -603,7 +599,7 @@ private LegacySampleBank toLegacySampleBank(string sampleBank)
}
}

private int toLegacyCustomSampleBank(HitSampleInfo hitSampleInfo)
private int toLegacyCustomSampleBank(HitSampleInfo? hitSampleInfo)
{
if (hitSampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacy)
return legacy.CustomSampleBank;
Expand Down
8 changes: 3 additions & 5 deletions osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +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.

#nullable disable

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -19,10 +17,10 @@ namespace osu.Game.Beatmaps.Formats
{
public class LegacyStoryboardDecoder : LegacyDecoder<Storyboard>
{
private StoryboardSprite storyboardSprite;
private CommandTimelineGroup timelineGroup;
private StoryboardSprite? storyboardSprite;
private CommandTimelineGroup? timelineGroup;

private Storyboard storyboard;
private Storyboard storyboard = null!;

private readonly Dictionary<string, string> variables = new Dictionary<string, string>();

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/ArgonSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,6 @@ public ArgonSkin(SkinInfo skin, IStorageResourceProvider resources)
}

private static Color4 getComboColour(IHasComboColours source, int colourIndex)
=> source.ComboColours[colourIndex % source.ComboColours.Count];
=> source.ComboColours![colourIndex % source.ComboColours.Count];
}
}
2 changes: 1 addition & 1 deletion osu.Game/Skinning/TrianglesSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ public TrianglesSkin(SkinInfo skin, IStorageResourceProvider resources)
}

private static Color4 getComboColour(IHasComboColours source, int colourIndex)
=> source.ComboColours[colourIndex % source.ComboColours.Count];
=> source.ComboColours![colourIndex % source.ComboColours.Count];
}
}
Loading