Skip to content

Commit

Permalink
Merge pull request #273 from andy840119/clean-up-code
Browse files Browse the repository at this point in the history
Clean up code
  • Loading branch information
andy840119 authored Nov 29, 2020
2 parents cff3a17 + d61d9c9 commit 14286a2
Show file tree
Hide file tree
Showing 32 changed files with 69 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void TestCreateRubyTagsWithRubyAsKatakana(string text, string[] ruby)
RunRubyCheckTest(text, ruby, config);
}

[TestCase("はなび", new string[] { "はな", "び" })]
[TestCase("ハナビ", new string[] { "はなび" })]
[TestCase("はなび", new[] { "はな", "び" })]
[TestCase("ハナビ", new[] { "はなび" })]
public void TestCreateRubyTagsWithEnableDuplicatedRuby(string text, string[] ruby)
{
var config = generatorConfig(nameof(JaRubyTagGeneratorConfig.EnableDuplicatedRuby));
Expand All @@ -46,6 +46,7 @@ protected void RunRubyCheckTest(string text, string[] ruby, JaRubyTagGeneratorCo
var rubyTags = generator.CreateRubyTags(lyric);

Assert.AreEqual(rubyTags.Length, ruby.Length);

foreach (var rubyTag in rubyTags)
{
Assert.IsTrue(ruby.Contains(rubyTag.Text));
Expand Down
28 changes: 15 additions & 13 deletions osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneImportLyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void TestGoToStep() => Schedule(() =>
Child = screen = new TestImportLyricScreen(new FileInfo(temp));

var steps = (ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep));

foreach (var step in steps)
{
AddStep($"go to step {Enum.GetName(typeof(ImportLyricStep), step)}", () => { screen.GoToStep(step); });
Expand All @@ -77,20 +78,21 @@ public TestImportLyricScreen(FileInfo fileInfo)

public void GoToStep(ImportLyricStep step)
{
if (ScreenStack.CurrentScreen is IImportLyricSubScreen lyricSubScreen)
if (!(ScreenStack.CurrentScreen is IImportLyricSubScreen lyricSubScreen))
return;

if (step == lyricSubScreen.Step)
return;

if (step <= lyricSubScreen.Step)
return;

var totalSteps = ((ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep))).Where(x => x > lyricSubScreen.Step && x <= step);

foreach (var gotoStep in totalSteps)
{
if (step == lyricSubScreen.Step)
return;

if (step <= lyricSubScreen.Step)
return;

var totalSteps = ((ImportLyricStep[])Enum.GetValues(typeof(ImportLyricStep))).Where(x => x > lyricSubScreen.Step && x <= step);
foreach (var gotoStep in totalSteps)
{
ScreenStack.Push(gotoStep);
}
}
ScreenStack.Push(gotoStep);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CultureInfoConverterTest
[TestCase(null, "null")]
public void TestSerialize(int? calId, string json)
{
var language = calId != null ? new CultureInfo(calId.Value) : default(CultureInfo);
var language = calId != null ? new CultureInfo(calId.Value) : default;
var result = JsonConvert.SerializeObject(language, createSettings());
Assert.AreEqual(result, json);
}
Expand All @@ -33,14 +33,15 @@ public void TestDeserialize(string json, int? calId)
public void TestAllCultureInfo()
{
var cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures);

foreach (var cultureInfo in cultureInfos)
{
// this weird cultureInfo will let test case failed.
if (cultureInfo.LCID == 4096)
continue;

var json = JsonConvert.SerializeObject(cultureInfo, createSettings());
var deserializedCultureInfo = JsonConvert.DeserializeObject<CultureInfo>(json, createSettings());
var deserializedCultureInfo = JsonConvert.DeserializeObject<CultureInfo>(json, createSettings());
Assert.AreEqual(deserializedCultureInfo, cultureInfo);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void TestSerialize()
{
var rowTimeTag = new[]
{
TimeTagsUtils.Create(new TimeTagIndex(0, TimeTagIndex.IndexState.Start), 1000d),
TimeTagsUtils.Create(new TimeTagIndex(0), 1000d),
TimeTagsUtils.Create(new TimeTagIndex(0, TimeTagIndex.IndexState.End), 1100d),
TimeTagsUtils.Create(new TimeTagIndex(0, TimeTagIndex.IndexState.End), 1200d),
};
Expand All @@ -35,6 +35,7 @@ public void TestDeserialize()
const string json_string = "[\r\n \"0,0,1000\",\r\n \"0,1,1100\",\r\n \"0,1,1200\"\r\n]";
var result = JsonConvert.DeserializeObject<Tuple<TimeTagIndex, double?>[]>(json_string, createSettings());

Assert.IsNotNull(result);
Assert.AreEqual(result.Length, 3);
Assert.AreEqual(result[0].Item1.Index, 0);
Assert.AreEqual(result[0].Item1.State, TimeTagIndex.IndexState.Start);
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/CharUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class CharUtilsTest
[TestCase('1', false)]
public void TestIsKana(char c, bool match)
{
var isKaka = CharUtils.IsKana(c);
Assert.AreEqual(isKaka, match);
var isKana = CharUtils.IsKana(c);
Assert.AreEqual(isKana, match);
}

[TestCase('A', true)]
Expand All @@ -43,7 +43,7 @@ public void TestIsLatin(char c, bool match)
[TestCase('#', true)]
[TestCase('@', true)]
[TestCase('A', false)]
public void TestIsASCIISymbol(char c, bool match)
public void TestIsAsciiSymbol(char c, bool match)
{
var isAsciiSymbol = CharUtils.IsAsciiSymbol(c);
Assert.AreEqual(isAsciiSymbol, match);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void RemoveSinger(Singer singer)
throw new NullReferenceException("Singer cannot be null.");

if (!Singers.Contains(singer))
throw new ArgumentOutOfRangeException("Singer is not in the list.");
throw new ArgumentOutOfRangeException(nameof(singer));

// Remove sub singers.
var subSingers = GetSubSingers(singer);
Expand Down Expand Up @@ -63,7 +63,7 @@ public void RemoveSubSinger(SubSinger subSinger)
throw new NullReferenceException("Sub singer cannot be null.");

if (!singers.Contains(subSinger))
throw new ArgumentOutOfRangeException("Sub singer is not in the list");
throw new ArgumentOutOfRangeException(nameof(subSinger));

singers.Remove(subSinger);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Rulesets.Karaoke.Objects;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Languages
{
Expand All @@ -15,6 +15,7 @@ public class LanguageDetector
public LanguageDetector(LanguageDetectorConfig config)
{
var targetLanguages = config?.AcceptLanguage?.Where(x => x != null).ToList() ?? new List<CultureInfo>();

if (targetLanguages.Any())
{
detector.AddLanguages(targetLanguages.Select(x => x.Name).ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public override RubyTag[] CreateRubyTags(Lyric lyric)

// Convert to Hiragana as default.
var hiragana = JpStringUtils.ToHiragana(katakana);

if (!Config.EnableDuplicatedRuby)
{
// Not add deplicated ruby if same as parent.
// Not add duplicated ruby if same as parent.
var parentText = text.Substring(offsetAtt.StartOffset, offsetAtt.EndOffset - offsetAtt.StartOffset);
if (parentText == katakana || parentText == hiragana)
continue;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Edit/Import/ImportManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics;
using System.IO;
using System.Linq;
using osu.Framework.Graphics;

namespace osu.Game.Rulesets.Karaoke.Edit.Import
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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 osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.AssignLanguage
{
Expand All @@ -13,7 +13,7 @@ public UseLanguageDetectorPopupDialog(Action<bool> okAction = null)
{
Icon = FontAwesome.Solid.Globe;
HeaderText = "Language detector";
BodyText = $"Would you like to use language detector to auto assign each lyric's language?";
BodyText = "Would you like to use language detector to auto assign each lyric's language?";
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// 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.IO;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
Expand All @@ -9,11 +14,6 @@
using osu.Game.Rulesets.Karaoke.Edit.ImportLyric.DragFile.Components;
using osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog;
using osuTK;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.DragFile
{
Expand Down Expand Up @@ -133,10 +133,7 @@ private PopupDialog createUnknownExceptionDialog()
};

private PopupDialog createCompleteDialog()
=> new OkPopupDialog(ok =>
{
Complete();
})
=> new OkPopupDialog(ok => { Complete(); })
{
Icon = FontAwesome.Regular.CheckCircle,
HeaderText = @"Import success",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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 osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.GenerateRuby
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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 osu.Framework.Graphics.Sprites;
using osu.Game.Overlays.Dialog;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric.GenerateTimeTag
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Graphics.Sprites;
using System;
using osu.Framework.Graphics.Sprites;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.IO;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Screens.Edit;
using System.IO;
using System.Linq;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down
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.IO;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
Expand All @@ -10,7 +11,6 @@
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Karaoke.Edit.ImportLyric.DragFile;
using osu.Game.Screens.Edit;
using System.IO;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Screens;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Push(ImportLyricStep step)
throw new ScreenNotCurrentException("Cannot push same screen.");

if (step <= lyricSubScreen.Step)
throw new ScreenNotCurrentException("Cannot push pervious then current screen.");
throw new ScreenNotCurrentException("Cannot push previous then current screen.");

if (step != ImportLyricStep.GenerateRuby && step - lyricSubScreen.Step > 1)
throw new ScreenNotCurrentException("Only generate ruby step can be skipped.");
Expand Down
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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -9,7 +10,6 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Graphics.Shapes;
using System;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down Expand Up @@ -151,7 +151,7 @@ protected virtual void UpdateState(NavigationState value)
throw new IndexOutOfRangeException("Should not goes to here");
}

// Force change stype if this step is able to hext step.
// Force change style if this step is able to go to next step.
if (AbleToNextStep(value))
{
button.Icon = FontAwesome.Regular.ArrowAltCircleRight;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Game.Overlays.Dialog;
using System;
using osu.Game.Overlays.Dialog;

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

using osu.Game.Overlays.Dialog;
using System;
using osu.Game.Overlays.Dialog;

namespace osu.Game.Rulesets.Karaoke.Edit.ImportLyric
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/Layout/LayoutPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public KaraokeLayout PreviewLayout

internal class LayoutPreviewArea : Container
{
private OsuSpriteText widthRatioText;
private OsuSpriteText heightRatioText;
private readonly OsuSpriteText widthRatioText;
private readonly OsuSpriteText heightRatioText;

private readonly Box background;
private readonly Container content;
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class LyricEditor : Container
[Resolved]
private EditorBeatmap beatmap { get; set; }

private KaraokeLyricEditorSkin skin;
private LyricRearrangeableListContainer container;
private readonly KaraokeLyricEditorSkin skin;
private readonly LyricRearrangeableListContainer container;

public LyricEditor()
{
Expand Down
Loading

0 comments on commit 14286a2

Please sign in to comment.