Skip to content

Commit

Permalink
Merge pull request #829 from andy840119/upgrade-to-csharp-9
Browse files Browse the repository at this point in the history
Upgrade to csharp 9
  • Loading branch information
andy840119 authored Aug 29, 2021
2 parents 98fb3df + c3bb488 commit 5b6fa31
Showing 161 changed files with 360 additions and 363 deletions.
13 changes: 6 additions & 7 deletions osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
@@ -31,7 +30,7 @@ public static RubyTag ParseRubyTag(string str)
var regex = new Regex("(?<start>[-0-9]+),(?<end>[-0-9]+)]:(?<ruby>.*$)");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

var startIndex = int.Parse(result.Groups["start"].Value);
var endIndex = int.Parse(result.Groups["end"].Value);
@@ -61,7 +60,7 @@ public static RomajiTag ParseRomajiTag(string str)
var regex = new Regex("(?<start>[-0-9]+),(?<end>[-0-9]+)]:(?<romaji>.*$)");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

var startIndex = int.Parse(result.Groups["start"].Value);
var endIndex = int.Parse(result.Groups["end"].Value);
@@ -91,7 +90,7 @@ public static TimeTag ParseTimeTag(string str)
var regex = new Regex("(?<index>[-0-9]+),(?<state>start|end)]:(?<time>[-0-9]+|s*|)");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

var index = int.Parse(result.Groups["index"].Value);
var state = result.Groups["state"].Value == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
@@ -117,7 +116,7 @@ public static TextIndex ParseTextIndex(string str)
var regex = new Regex("(?<index>[-0-9]+),(?<state>start|end)]");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

var index = int.Parse(result.Groups["index"].Value);
var state = result.Groups["state"].Value == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
@@ -141,7 +140,7 @@ public static Lyric ParseLyric(string str)
var regex = new Regex("(?<startTime>[-0-9]+),(?<endTime>[-0-9]+)]:(?<lyric>.*$)");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

var startTime = double.Parse(result.Groups["startTime"].Value);
var endTime = double.Parse(result.Groups["endTime"].Value);
@@ -206,7 +205,7 @@ public static Singer ParseSinger(string str)
var regex = new Regex("(?<id>[-0-9]+)]");
var result = regex.Match(str);
if (!result.Success)
throw new ArgumentException(null, nameof(str));
throw new RegexMatchTimeoutException(nameof(str));

// todo : implementation
var id = int.Parse(result.Groups["id"].Value);
Original file line number Diff line number Diff line change
@@ -15,6 +15,6 @@ public class TtfGlyphStoreTest : BaseGlyphStoreTest<TtfGlyphStore>
protected override string FontName => "OpenSans-Regular";

protected override TtfGlyphStore CreateFontStore(ResourceStore<byte[]> store, string assetName)
=> new TtfGlyphStore(store, assetName);
=> new(store, assetName);
}
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public void TestBeatmapMetadataGraph()
var ruleset = new KaraokeRuleset().RulesetInfo;
var originBeatmap = new TestKaraokeBeatmap(ruleset);
if (!(new KaraokeBeatmapConverter(originBeatmap, new KaraokeRuleset()).Convert() is KaraokeBeatmap karaokeBeatmap))
throw new ArgumentNullException(nameof(karaokeBeatmap));
throw new InvalidCastException(nameof(karaokeBeatmap));

karaokeBeatmap.Singers = createDefaultSinger();
createTest(new ScoreInfo(), karaokeBeatmap);
Original file line number Diff line number Diff line change
@@ -104,13 +104,13 @@ public void TestNoteStair()
private static bool checkMatching(ReplayFrame frame, Tone? tone)
{
if (!(frame is KaraokeReplayFrame karaokeReplayFrame))
throw new ArgumentException($"{nameof(frame)} is not karaoke replay frame.");
throw new InvalidCastException($"{nameof(frame)} is not karaoke replay frame.");

if (!karaokeReplayFrame.Sound)
return !tone.HasValue;

if (tone == null)
throw new ArgumentException($"{nameof(tone)} should not be null in compare.");
throw new ArgumentNullException(nameof(tone));

return karaokeReplayFrame.Scale == tone.Value.Scale + (tone.Value.Half ? 0.5f : 0);
}
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ static Tone convertTone(string tone)
}

if (!int.TryParse(tone, out int scale))
throw new ArgumentOutOfRangeException($"{tone} does not support in {nameof(KaraokeLegacyBeatmapDecoder)}");
throw new InvalidCastException($"{tone} does not support in {nameof(KaraokeLegacyBeatmapDecoder)}");

return new Tone
{
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public string Encode(Beatmap output)
}

private LyricLine encodeLyric(Lyric lyric) =>
new LyricLine
new()
{
Text = lyric.Text,
// Note : save to lyric will lost some tags with no value.
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Formats/NicoKaraDecoder.cs
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ protected override void ParseStreamInto(LineBufferedReader stream, KaraokeSkin o
});
}

static Vector2 convertShadowSlide(ShadowSlide side) => new Vector2(side.X, side.Y);
static Vector2 convertShadowSlide(ShadowSlide side) => new(side.X, side.Y);

static Anchor convertAnchor(HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment)
{
@@ -133,7 +133,7 @@ static BrushInfo convertBrushInfo(NicoKaraParser.Model.Font.Brush.BrushInfo info
BrushGradients = brushGradient
};

static Color4 convertColor(Color color) => new Color4(color.R, color.G, color.B, color.A);
static Color4 convertColor(Color color) => new(color.R, color.G, color.B, color.A);
}

static FontUsage convertFontInfo(FontInfo info)
9 changes: 5 additions & 4 deletions osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmap.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -13,9 +14,9 @@ namespace osu.Game.Rulesets.Karaoke.Beatmaps
{
public class KaraokeBeatmap : Beatmap<KaraokeHitObject>
{
public CultureInfo[] AvailableTranslates { get; set; } = { };
public CultureInfo[] AvailableTranslates { get; set; } = Array.Empty<CultureInfo>();

public Singer[] Singers { get; set; } = { };
public Singer[] Singers { get; set; } = Array.Empty<Singer>();

public int TotalColumns { get; set; } = 9;

@@ -26,13 +27,13 @@ public override IEnumerable<BeatmapStatistic> GetStatistics()

var defaultStatistic = new List<BeatmapStatistic>
{
new BeatmapStatistic
new()
{
Name = @"Singer",
Content = singers.ToString(),
CreateIcon = () => new SpriteIcon { Icon = FontAwesome.Solid.User }
},
new BeatmapStatistic
new()
{
Name = @"Lyric",
Content = lyrics.ToString(),
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Globalization;
using System.Linq;
using osu.Game.Beatmaps;
@@ -13,7 +14,7 @@ public static class KaraokeBeatmapExtension
{
public static bool IsScorable(this IBeatmap beatmap) => beatmap?.HitObjects.OfType<Note>().Any(x => x.Display) ?? false;

public static CultureInfo[] AvailableTranslates(this IBeatmap beatmap) => (beatmap as KaraokeBeatmap)?.AvailableTranslates ?? new CultureInfo[] { };
public static CultureInfo[] AvailableTranslates(this IBeatmap beatmap) => (beatmap as KaraokeBeatmap)?.AvailableTranslates ?? Array.Empty<CultureInfo>();

public static bool AnyTranslate(this IBeatmap beatmap) => beatmap?.AvailableTranslates()?.Any() ?? false;

2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Singer.cs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public Singer(int id)
public int ID { get; }

[JsonIgnore]
public readonly Bindable<int> OrderBindable = new Bindable<int>();
public readonly Bindable<int> OrderBindable = new();

/// <summary>
/// Order
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ protected BindableFontUsage SetDefault(KaraokeRulesetSetting setting, FontUsage
return bindableFontUsage;
}

public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
public override TrackedSettings CreateTrackedSettings() => new()
{
new TrackedSetting<double>(KaraokeRulesetSetting.ScrollTime, v => new SettingDescription(v, "Scroll Time", $"{v}ms"))
};
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Checker
/// </summary>
public class LyricCheckerManager : Component
{
public BindableDictionary<Lyric, Issue[]> BindableReports = new BindableDictionary<Lyric, Issue[]>();
public BindableDictionary<Lyric, Issue[]> BindableReports = new();

private LyricVerifier lyricVerifier;

Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Checks
{
public class CheckInvalidPropertyLyrics : ICheck
{
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.HitObjects, "Lyrics with invalid property.");
public CheckMetadata Metadata => new(CheckCategory.HitObjects, "Lyrics with invalid property.");

public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
@@ -47,7 +47,7 @@ public IssueTemplateNotFillLanguage(ICheck check)
}

public Issue Create(Lyric lyric)
=> new Issue(lyric, this);
=> new(lyric, this);
}

public class IssueTemplateNoText : IssueTemplate
@@ -58,7 +58,7 @@ public IssueTemplateNoText(ICheck check)
}

public Issue Create(Lyric lyric)
=> new Issue(lyric, this);
=> new(lyric, this);
}

public class IssueTemplateNoSinger : IssueTemplate
@@ -69,7 +69,7 @@ public IssueTemplateNoSinger(ICheck check)
}

public Issue Create(Lyric lyric)
=> new Issue(lyric, this);
=> new(lyric, this);
}
}
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Checks
{
public class CheckInvalidPropertyNotes : ICheck
{
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.HitObjects, "Notes with invalid property.");
public CheckMetadata Metadata => new(CheckCategory.HitObjects, "Notes with invalid property.");

public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
@@ -37,7 +37,7 @@ public IssueTemplateInvalidParentLyric(ICheck check)
}

public Issue Create(Note note)
=> new Issue(note, this);
=> new(note, this);
}
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public class CheckInvalidRubyRomajiLyrics : ICheck
{
private readonly LyricCheckerConfig config;

public CheckMetadata Metadata => new CheckMetadata(CheckCategory.HitObjects, "Lyrics with invalid ruby/romaji.");
public CheckMetadata Metadata => new(CheckCategory.HitObjects, "Lyrics with invalid ruby/romaji.");

public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public class CheckInvalidTimeLyrics : ICheck
{
private readonly LyricCheckerConfig config;

public CheckMetadata Metadata => new CheckMetadata(CheckCategory.HitObjects, "Lyrics with invalid time issue.");
public CheckMetadata Metadata => new(CheckCategory.HitObjects, "Lyrics with invalid time issue.");

public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
11 changes: 6 additions & 5 deletions osu.Game.Rulesets.Karaoke/Edit/Checks/CheckTranslate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@@ -16,7 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Checks
{
public class CheckTranslate : ICheck
{
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.HitObjects, "Unfinished translate language.");
public CheckMetadata Metadata => new(CheckCategory.HitObjects, "Unfinished translate language.");

public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
@@ -26,7 +27,7 @@ public class CheckTranslate : ICheck

public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
var languages = availableTranslateInBeatmap(context.Beatmap) ?? new CultureInfo[] { };
var languages = availableTranslateInBeatmap(context.Beatmap) ?? Array.Empty<CultureInfo>();

var lyrics = context.Beatmap.HitObjects.OfType<Lyric>().ToList();
if (lyrics.Count == 0)
@@ -79,7 +80,7 @@ public IssueTemplateMissingTranslate(ICheck check)
}

public Issue Create(IEnumerable<HitObject> hitObjects, CultureInfo cultureInfo)
=> new Issue(hitObjects, this, cultureInfo);
=> new(hitObjects, this, cultureInfo);
}

public class IssueTemplateMissingPartialTranslate : IssueTemplate
@@ -90,7 +91,7 @@ public IssueTemplateMissingPartialTranslate(ICheck check)
}

public Issue Create(IEnumerable<HitObject> hitObjects, CultureInfo cultureInfo)
=> new Issue(hitObjects, this, cultureInfo);
=> new(hitObjects, this, cultureInfo);
}

public class IssueTemplateContainsNotListedLanguage : IssueTemplate
@@ -101,7 +102,7 @@ public IssueTemplateContainsNotListedLanguage(ICheck check)
}

public Issue Create(IEnumerable<HitObject> hitObjects, CultureInfo cultureInfo)
=> new Issue(hitObjects, this, cultureInfo);
=> new(hitObjects, this, cultureInfo);
}
}
}
Original file line number Diff line number Diff line change
@@ -15,15 +15,13 @@ public class LyricCheckerConfig : IHasConfig<LyricCheckerConfig>

public TextTagsUtils.Sorting RomajiPositionSorting { get; set; }

public LyricCheckerConfig CreateDefaultConfig()
{
return new LyricCheckerConfig
public LyricCheckerConfig CreateDefaultConfig() =>
new()
{
TimeTagTimeGroupCheck = GroupCheck.Asc,
TimeTagTimeSelfCheck = SelfCheck.BasedOnStart,
RubyPositionSorting = TextTagsUtils.Sorting.Asc,
RomajiPositionSorting = TextTagsUtils.Sorting.Asc,
};
}
}
}
Loading

0 comments on commit 5b6fa31

Please sign in to comment.