Skip to content

Commit

Permalink
Merge pull request #2200 from andy840119/remove-remaining-nullable-an…
Browse files Browse the repository at this point in the history
…notation

Remove remaining nullable annotation.
  • Loading branch information
andy840119 authored Mar 24, 2024
2 parents 97f047a + 1894019 commit 58273d8
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 59 deletions.
10 changes: 3 additions & 7 deletions osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public static string GetTestLrcForImport(string name)

public static IStorageResourceProvider CreateSkinStorageResourceProvider(string skinName = "special-skin") => new TestStorageResourceProvider(skinName);

#nullable disable

private class TestStorageResourceProvider : IStorageResourceProvider
{
public TestStorageResourceProvider(string skinName)
Expand All @@ -55,13 +53,11 @@ public TestStorageResourceProvider(string skinName)

public IRenderer Renderer => new DummyRenderer();

public AudioManager AudioManager => null;
public AudioManager AudioManager => null!;
public IResourceStore<byte[]> Files { get; }
public IResourceStore<byte[]> Resources { get; }
public RealmAccess RealmAccess => null;
public RealmAccess RealmAccess => null!;

public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null!;
}

#nullable enable
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void OneTimeSetUp()
if (normalGlyph == null)
throw new ArgumentNullException(nameof(normalGlyph));

font = glyphStore.BitmapFont;
font = glyphStore.BitmapFont ?? throw new InvalidOperationException("Font should not be null in the test case.");
}

[TestCase("A", 1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BitmapFontImageGeneratorTest
{
private TestFntGlyphStore glyphStore = null!;

private BitmapFont font => glyphStore.BitmapFont;
private BitmapFont font = null!;

[OneTimeSetUp]
public void OneTimeSetUp()
Expand All @@ -31,6 +31,8 @@ public void OneTimeSetUp()
var normalGlyph = glyphStore.Get('a');
if (normalGlyph == null)
throw new ArgumentNullException(nameof(normalGlyph));

font = glyphStore.BitmapFont ?? throw new InvalidOperationException("Font should not be null in the test case.");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -22,7 +20,7 @@ public class CachedFontArchiveReader : ArchiveReader
private readonly Stream archiveStream;
private readonly ZipArchive archive;

public CachedFontArchiveReader(Stream archiveStream, string name = null)
public CachedFontArchiveReader(Stream archiveStream, string name)
: base(name)
{
this.archiveStream = archiveStream;
Expand Down
6 changes: 2 additions & 4 deletions osu.Game.Rulesets.Karaoke/IO/Stores/FntGlyphStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using SharpFNT;
Expand All @@ -11,9 +9,9 @@ namespace osu.Game.Rulesets.Karaoke.IO.Stores;

public class FntGlyphStore : GlyphStore
{
public BitmapFont BitmapFont => Font;
public BitmapFont? BitmapFont => Font;

public FntGlyphStore(ResourceStore<byte[]> store, string assetName = null, IResourceStore<TextureUpload> textureLoader = null)
public FntGlyphStore(ResourceStore<byte[]> store, string? assetName = null, IResourceStore<TextureUpload>? textureLoader = null)
: base(store, assetName, textureLoader)
{
}
Expand Down
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
Expand All @@ -25,7 +23,7 @@ public class KaraokeLocalFontStore : FontStore
/// <param name="renderer">The renderer to create textures with.</param>
/// <param name="store">The texture source.</param>
/// <param name="scaleAdjust">The raw pixel height of the font. Can be used to apply a global scale or metric to font usages.</param>
public KaraokeLocalFontStore(FontManager fontManager, IRenderer renderer, IResourceStore<TextureUpload> store = null, float scaleAdjust = 100)
public KaraokeLocalFontStore(FontManager fontManager, IRenderer renderer, IResourceStore<TextureUpload>? store = null, float scaleAdjust = 100)
: base(renderer, store, scaleAdjust)
{
this.fontManager = fontManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -33,12 +30,12 @@ public partial class DrawableBarLine : DrawableKaraokeScrollingHitObject<BarLine
/// <summary>
/// The visual line tracker.
/// </summary>
private Box line;
private Box line = null!;

/// <summary>
/// Container with triangles. Only visible for major lines.
/// </summary>
private Container triangleContainer;
private Container triangleContainer = null!;

private readonly Bindable<bool> major = new();

Expand All @@ -47,7 +44,7 @@ public DrawableBarLine()
{
}

public DrawableBarLine([CanBeNull] BarLine barLine)
public DrawableBarLine(BarLine? barLine)
: base(barLine)
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Karaoke.Judgements;
using osu.Game.Rulesets.Karaoke.Objects.Types;
Expand All @@ -12,8 +10,8 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Drawables;

public partial class DrawableKaraokeHitObject : DrawableHitObject<KaraokeHitObject>
{
protected DrawableKaraokeHitObject(KaraokeHitObject hitObject)
: base(hitObject)
protected DrawableKaraokeHitObject(KaraokeHitObject? hitObject)
: base(hitObject!)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -17,8 +15,8 @@ public abstract partial class DrawableKaraokeScrollingHitObject : DrawableHitObj

protected readonly IBindable<double> TimeRange = new Bindable<double>();

protected DrawableKaraokeScrollingHitObject(KaraokeHitObject hitObject)
: base(hitObject)
protected DrawableKaraokeScrollingHitObject(KaraokeHitObject? hitObject)
: base(hitObject!)
{
}

Expand Down Expand Up @@ -102,9 +100,9 @@ protected virtual void OnTimeRangeChanged(ValueChangedEvent<double> e)
public abstract partial class DrawableKaraokeScrollingHitObject<TObject> : DrawableKaraokeScrollingHitObject
where TObject : KaraokeHitObject
{
public new TObject HitObject => base.HitObject as TObject;
public new TObject HitObject => (TObject)base.HitObject;

protected DrawableKaraokeScrollingHitObject(TObject hitObject)
protected DrawableKaraokeScrollingHitObject(TObject? hitObject)
: base(hitObject)
{
}
Expand Down
22 changes: 9 additions & 13 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableLyric.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Globalization;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
Expand All @@ -24,11 +21,10 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Drawables;

public partial class DrawableLyric : DrawableKaraokeHitObject
{
private Container<DrawableKaraokeSpriteText> lyricPieces;
private OsuSpriteText translateText;
private Container<DrawableKaraokeSpriteText> lyricPieces = null!;
private OsuSpriteText translateText = null!;

[Resolved(canBeNull: true)]
private KaraokeRulesetConfigManager config { get; set; }
private KaraokeRulesetConfigManager? config { get; set; }

private readonly BindableBool useTranslateBindable = new();
private readonly Bindable<CultureInfo> preferLanguageBindable = new();
Expand All @@ -43,8 +39,8 @@ public partial class DrawableLyric : DrawableKaraokeHitObject
private readonly IBindableDictionary<Singer, SingerState[]> singersBindable = new BindableDictionary<Singer, SingerState[]>();
private readonly BindableDictionary<CultureInfo, string> translateTextBindable = new();

public event Action<DrawableLyric> OnLyricStart;
public event Action<DrawableLyric> OnLyricEnd;
public event Action<DrawableLyric>? OnLyricStart;
public event Action<DrawableLyric>? OnLyricEnd;

public new Lyric HitObject => (Lyric)base.HitObject;

Expand All @@ -53,13 +49,13 @@ public DrawableLyric()
{
}

public DrawableLyric([CanBeNull] Lyric hitObject)
public DrawableLyric(Lyric? hitObject)
: base(hitObject)
{
}

[BackgroundDependencyLoader(true)]
private void load([CanBeNull] KaraokeSessionStatics session)
private void load(KaraokeSessionStatics? session)
{
AutoSizeAxes = Axes.Both;

Expand Down Expand Up @@ -180,11 +176,11 @@ private void applyTranslate()

if (!needTranslate || language == null)
{
translateText.Text = (string)null;
translateText.Text = string.Empty;
}
else
{
if (translateTextBindable.TryGetValue(language, out string translate))
if (translateTextBindable.TryGetValue(language, out string? translate))
translateText.Text = translate;
}
}
Expand Down
9 changes: 3 additions & 6 deletions osu.Game.Rulesets.Karaoke/Objects/Drawables/DrawableNote.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -44,7 +41,7 @@ public partial class DrawableNote : DrawableKaraokeScrollingHitObject<Note>, IKe
private readonly IBindable<NotePositionCalculator> positionBindable = new Bindable<NotePositionCalculator>();

public readonly IBindable<string> TextBindable = new Bindable<string>();
public readonly IBindable<string> RubyTextBindable = new Bindable<string>();
public readonly IBindable<string?> RubyTextBindable = new Bindable<string?>();
public readonly IBindableDictionary<Singer, SingerState[]> SingersBindable = new BindableDictionary<Singer, SingerState[]>();
public readonly IBindable<bool> DisplayBindable = new Bindable<bool>();
public readonly IBindable<Tone> ToneBindable = new Bindable<Tone>();
Expand All @@ -54,7 +51,7 @@ public DrawableNote()
{
}

public DrawableNote([CanBeNull] Note hitObject)
public DrawableNote(Note? hitObject)
: base(hitObject)
{
AddRangeInternal(new Drawable[]
Expand All @@ -81,7 +78,7 @@ private void load(INotePositionInfo notePositionInfo)
TextBindable.BindValueChanged(_ => { changeText(HitObject); });
RubyTextBindable.BindValueChanged(_ => { changeText(HitObject); });
SingersBindable.BindCollectionChanged((_, _) => { ApplySkin(CurrentSkin, false); });
DisplayBindable.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement).Scorable = e.NewValue; });
DisplayBindable.BindValueChanged(e => { (Result.Judgement as KaraokeNoteJudgement)!.Scorable = e.NewValue; });
ToneBindable.BindValueChanged(_ => updateNotePositionAndHeight());

void updateNotePositionAndHeight()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <andy840119@gmail.com>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Audio;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Dummy;
Expand All @@ -23,9 +21,9 @@ public InternalSkinStorageResourceProvider(string skinName)

public IRenderer Renderer => new DummyRenderer();

public AudioManager AudioManager => null;
public AudioManager AudioManager => null!;
public IResourceStore<byte[]> Files { get; }
public IResourceStore<byte[]> Resources { get; }
public RealmAccess RealmAccess => null;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
public RealmAccess RealmAccess => null!;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null!;
}

0 comments on commit 58273d8

Please sign in to comment.