Skip to content

Commit

Permalink
Merge pull request #1428 from andy840119/clean-up-the-fucking-code
Browse files Browse the repository at this point in the history
Clean some bad code.
  • Loading branch information
andy840119 authored Jul 8, 2022
2 parents d1fd36a + 42c0d12 commit 6a87ad4
Show file tree
Hide file tree
Showing 52 changed files with 134 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ private void selectBeatmap(IBeatmap b, string fileName)
{
BeatmapInfoWedge.WedgeInfoText infoBefore = null!;

AddStep($"select {b.Metadata.Title ?? fileName} beatmap", () =>
string title = string.IsNullOrEmpty(b.Metadata.Title) ? fileName : b.Metadata.Title;
AddStep($"select {title} beatmap", () =>
{
infoBefore = infoWedge.Info;
infoWedge.Beatmap = Beatmap.Value = b == null ? Beatmap.Default : CreateWorkingBeatmap(b);
infoWedge.Beatmap = Beatmap.Value = CreateWorkingBeatmap(b);
});

AddUntilStep("wait for async load", () => infoWedge.Info != infoBefore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator
public abstract class BaseDetectorTest<TDetector, TObject, TConfig>
where TDetector : class, ILyricPropertyDetector<TObject> where TConfig : new()
{
protected static TConfig GeneratorConfig(params string[] properties)
protected static TConfig GeneratorConfig(params string?[] properties)
{
var config = new TConfig();
if (properties == null)
return config;

foreach (string propertyName in properties)
foreach (string? propertyName in properties)
{
if (propertyName == null)
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static TimeTagCaretPosition createCaretPosition(IEnumerable<Lyric> lyric
var lyric = lyrics.ElementAtOrDefault(lyricIndex);
var timeTag = timeTagIndex == not_exist_tag
? new TimeTag(new TextIndex(not_exist_tag))
: lyric?.TimeTags?.ElementAtOrDefault(timeTagIndex);
: lyric?.TimeTags.ElementAtOrDefault(timeTagIndex);

if (lyric == null || timeTag == null)
throw new ArgumentNullException();
Expand Down
2 changes: 0 additions & 2 deletions osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneEditor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Karaoke.Edit.Checks.Components;
using osu.Game.Rulesets.Karaoke.Edit.Components.Cursor;
Expand All @@ -18,7 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor
[TestFixture]
public class TestSceneInvalidLyricToolTip : OsuTestScene
{
private InvalidLyricToolTip toolTip;
private InvalidLyricToolTip toolTip = null!;

[SetUp]
public void SetUp() => Schedule(() =>
Expand Down Expand Up @@ -101,7 +100,7 @@ public void TestRubyTagInvalidLyric()
{
StartIndex = 2,
EndIndex = 3,
Text = null,
Text = string.Empty,
}
}
}
Expand Down Expand Up @@ -153,7 +152,7 @@ public void TestRomajiTagInvalidLyric()
{
StartIndex = 2,
EndIndex = 3,
Text = null,
Text = string.Empty,
}
}
}
Expand Down Expand Up @@ -197,9 +196,9 @@ public void TestTimeTagInvalidLyric()
}
}));

setTooltip("missing start time-tag", new TestTimeTagIssue(null, true));
setTooltip("missing end time-tag", new TestTimeTagIssue(null, false, true));
setTooltip("missing start and end time-tag", new TestTimeTagIssue(null, true, true));
setTooltip("missing start time-tag", new TestTimeTagIssue(new Dictionary<TimeTagInvalid, TimeTag[]>(), true));
setTooltip("missing end time-tag", new TestTimeTagIssue(new Dictionary<TimeTagInvalid, TimeTag[]>(), false, true));
setTooltip("missing start and end time-tag", new TestTimeTagIssue(new Dictionary<TimeTagInvalid, TimeTag[]>(), true, true));
}

[Test]
Expand Down Expand Up @@ -281,34 +280,54 @@ private void setTooltip(string testName, params Issue[] issues)
});
}

internal class Check : ICheck
{
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
throw new System.NotImplementedException();
}

public CheckMetadata Metadata { get; } = null!;

public IEnumerable<IssueTemplate> PossibleTemplates { get; } = null!;
}

internal class TestIssueTemplate : IssueTemplate
{
public TestIssueTemplate()
: base(new Check(), IssueType.Error, string.Empty)
{
}
}

internal class TestLyricTimeIssue : LyricTimeIssue
{
public TestLyricTimeIssue(TimeInvalid[] invalidLyricTime)
: base(new Lyric(), null, invalidLyricTime)
: base(new Lyric(), new TestIssueTemplate(), invalidLyricTime)
{
}
}

internal class TestRubyTagIssue : RubyTagIssue
{
public TestRubyTagIssue(Dictionary<RubyTagInvalid, RubyTag[]> invalidRubyTags)
: base(new Lyric(), null, invalidRubyTags)
: base(new Lyric(), new TestIssueTemplate(), invalidRubyTags)
{
}
}

internal class TestRomajiTagIssue : RomajiTagIssue
{
public TestRomajiTagIssue(Dictionary<RomajiTagInvalid, RomajiTag[]> invalidRomajiTags)
: base(new Lyric(), null, invalidRomajiTags)
: base(new Lyric(), new TestIssueTemplate(), invalidRomajiTags)
{
}
}

internal class TestTimeTagIssue : TimeTagIssue
{
public TestTimeTagIssue(Dictionary<TimeTagInvalid, TimeTag[]> invalidTimeTags, bool missingStartTimeTag = false, bool missingEndTimeTag = false)
: base(new Lyric(), null, invalidTimeTags, missingStartTimeTag, missingEndTimeTag)
: base(new Lyric(), new TestIssueTemplate(), invalidTimeTags, missingStartTimeTag, missingEndTimeTag)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. 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.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -31,8 +29,8 @@ public class TestSceneKaraokeEditor : ScreenTestScene<KaraokeEditor>

protected override KaraokeEditor CreateScreen() => new();

private DialogOverlay dialogOverlay;
private LyricCheckerManager lyricCheckerManager;
private DialogOverlay dialogOverlay = null!;
private LyricCheckerManager lyricCheckerManager = null!;

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

#nullable disable

using System;
using System.Collections.Generic;
using NUnit.Framework;
Expand All @@ -19,7 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor
public class TestSceneLayoutToolTip : OsuTestScene
{
private readonly ISkin skin = new DefaultKaraokeSkin(null);
private LayoutToolTip toolTip;
private LayoutToolTip toolTip = null!;

[SetUp]
public void SetUp() => Schedule(() =>
Expand Down Expand Up @@ -60,7 +58,7 @@ private void setTooltip(string testName, Action<Lyric> callBack)
{
Text = "karaoke!"
};
callBack?.Invoke(singer);
callBack.Invoke(singer);
toolTip.SetContent(singer);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -31,9 +29,9 @@ public class TestSceneLyricEditorScreen : KaraokeEditorScreenTestScene<LyricEdit

protected override LyricEditorScreen CreateEditorScreen() => new();

private DialogOverlay dialogOverlay;
private LyricsProvider lyricsProvider;
private LyricCheckerManager lyricCheckManager;
private DialogOverlay dialogOverlay = null!;
private LyricsProvider lyricsProvider = null!;
private LyricCheckerManager lyricCheckManager = null!;

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

#nullable disable

using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -39,7 +37,7 @@ protected override TestLyricImporter CreateScreen()
return new TestLyricImporter(new FileInfo(temp));
}

private DialogOverlay dialogOverlay;
private DialogOverlay dialogOverlay = null!;

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

#nullable disable

using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -64,9 +62,9 @@ protected override KaraokeBeatmap CreateBeatmap()
return karaokeBeatmap;
}

private DialogOverlay dialogOverlay;
private LyricsProvider lyricsProvider;
private KaraokeBeatmapResourcesProvider karaokeBeatmapResourcesProvider;
private DialogOverlay dialogOverlay = null!;
private LyricsProvider lyricsProvider = null!;
private KaraokeBeatmapResourcesProvider karaokeBeatmapResourcesProvider = null!;

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

#nullable disable

using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
Expand All @@ -15,7 +13,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor
[TestFixture]
public class TestSceneTimeTagTooltip : OsuTestScene
{
private TimeTagTooltip toolTip;
private TimeTagTooltip toolTip = null!;

[SetUp]
public void SetUp() => Schedule(() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. 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.Globalization;
using NUnit.Framework;
Expand Down Expand Up @@ -37,8 +35,8 @@ protected override KaraokeBeatmap CreateBeatmap()
return karaokeBeatmap;
}

private DialogOverlay dialogOverlay;
private LyricsProvider lyricsProvider;
private DialogOverlay dialogOverlay = null!;
private LyricsProvider lyricsProvider = null!;

[BackgroundDependencyLoader]
private void load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static Lyric ParseLyric(string? str)
TimeTags = new[]
{
new TimeTag(new TextIndex(0), startTime),
new TimeTag(new TextIndex((text?.Length ?? 0) - 1, TextIndex.IndexState.End), endTime)
new TimeTag(new TextIndex(text.Length - 1, TextIndex.IndexState.End), endTime)
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ protected override void ParseStreamInto(LineBufferedReader stream, Beatmap outpu
{
// because of json serializer contains object reference issue with serialize/deserialize the beatmap.
// so should re-assign the lyric instance.
note.ParentLyric = lyrics.FirstOrDefault(x => x.ID == note.ParentLyric.ID);

if (note.ParentLyric == null)
throw new InvalidOperationException();
note.ParentLyric = lyrics.FirstOrDefault(x => x.ID == note.ParentLyric.ID) ?? throw new InvalidOperationException();
}

hitObject.ApplyDefaults(output.ControlPointInfo, output.Difficulty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private IEnumerable<string> encodeNote(Beatmap output)
string noteGroupStr = string.Join(",", noteGroup.Select(x =>
{
if (x.Count() == 1)
return convertNote(x.FirstOrDefault());
return convertNote(x.First());

return "(" + string.Join("|", x.Select(convertNote)) + ")";
}));
Expand Down
3 changes: 0 additions & 3 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ static LrcParser.Model.TextIndex convertTextIndex(TextIndex textIndex)
internal static IReadOnlyDictionary<TextIndex, double> ToDictionary(IList<TimeTag> timeTags, bool applyFix = true, GroupCheck other = GroupCheck.Asc,
SelfCheck self = SelfCheck.BasedOnStart)
{
if (timeTags == null)
return new Dictionary<TextIndex, double>();

// sorted value
var sortedTimeTags = applyFix ? TimeTagsUtils.FixOverlapping(timeTags, other, self) : TimeTagsUtils.Sort(timeTags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace osu.Game.Rulesets.Karaoke.Beatmaps
{
public interface IKaraokeBeatmapResourcesProvider
{
Texture GetSingerAvatar(ISinger singer);
Texture? GetSingerAvatar(ISinger singer);
}
}
Loading

0 comments on commit 6a87ad4

Please sign in to comment.