-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1958 from andy840119/remove-lyric-auto-generator-…
…change-handler Separate the auto-generate logic in the LyricAutoGenerateChangeHandler.
- Loading branch information
Showing
37 changed files
with
786 additions
and
774 deletions.
There are no files selected for viewing
403 changes: 0 additions & 403 deletions
403
...Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandlerTest.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator; | ||
using osu.Game.Rulesets.Karaoke.Edit.Utils; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Screens.Edit; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; | ||
|
||
public partial class LyricNotesChangeHandlerTest : LyricPropertyChangeHandlerTest<LyricNotesChangeHandler> | ||
{ | ||
protected override bool IncludeAutoGenerator => true; | ||
|
||
#region Note | ||
|
||
[Test] | ||
public void TestAutoGenerateNotes() | ||
{ | ||
PrepareHitObject(() => new Lyric | ||
{ | ||
Text = "カラオケ", | ||
TimeTags = new[] | ||
{ | ||
new TimeTag(new TextIndex(0), 0), | ||
new TimeTag(new TextIndex(1), 1000), | ||
new TimeTag(new TextIndex(2), 2000), | ||
new TimeTag(new TextIndex(3), 3000), | ||
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), | ||
} | ||
}); | ||
|
||
TriggerHandlerChanged(c => c.AutoGenerate()); | ||
|
||
AssertSelectedHitObject(h => | ||
{ | ||
var actualNotes = getMatchedNotes(h); | ||
Assert.AreEqual(4, actualNotes.Length); | ||
|
||
Assert.AreEqual("カ", actualNotes[0].Text); | ||
Assert.AreEqual("ラ", actualNotes[1].Text); | ||
Assert.AreEqual("オ", actualNotes[2].Text); | ||
Assert.AreEqual("ケ", actualNotes[3].Text); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestAutoGenerateNotesWithNonSupportedLyric() | ||
{ | ||
PrepareHitObject(() => new Lyric | ||
{ | ||
Text = "カラオケ", | ||
}); | ||
|
||
TriggerHandlerChangedWithException<GeneratorNotSupportedException>(c => c.AutoGenerate()); | ||
} | ||
|
||
private Note[] getMatchedNotes(Lyric lyric) | ||
{ | ||
var editorBeatmap = Dependencies.Get<EditorBeatmap>(); | ||
return EditorBeatmapUtils.GetNotesByLyric(editorBeatmap, lyric).ToArray(); | ||
} | ||
|
||
#endregion | ||
} |
140 changes: 140 additions & 0 deletions
140
....Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Globalization; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; | ||
|
||
/// <summary> | ||
/// This test is focus on make sure that: | ||
/// If the <see cref="Lyric.ReferenceLyric"/> in the <see cref="Lyric"/> is not empty. | ||
/// <see cref="ILyricPropertyAutoGenerateChangeHandler"/> should be able to change the property. | ||
/// </summary> | ||
/// <typeparam name="TChangeHandler"></typeparam> | ||
[TestFixture(typeof(LyricReferenceChangeHandler))] | ||
[TestFixture(typeof(LyricLanguageChangeHandler))] | ||
[TestFixture(typeof(LyricRubyTagsChangeHandler))] | ||
[TestFixture(typeof(LyricRomajiTagsChangeHandler))] | ||
[TestFixture(typeof(LyricTimeTagsChangeHandler))] | ||
[TestFixture(typeof(LyricNotesChangeHandler))] | ||
public partial class LyricPropertyAutoGenerateChangeHandlerTest<TChangeHandler> : LyricPropertyChangeHandlerTest<TChangeHandler> | ||
where TChangeHandler : LyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler, new() | ||
{ | ||
protected override bool IncludeAutoGenerator => true; | ||
|
||
# region With reference lyric | ||
|
||
[Test] | ||
public void TestCanGenerateWithReferenceLyric() | ||
{ | ||
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler(); | ||
|
||
if (lyricReferenceChangeHandler) | ||
{ | ||
PrepareHitObject(() => new Lyric | ||
{ | ||
Text = "karaoke" | ||
}, false); | ||
} | ||
|
||
PrepareLyricWithSyncConfig(new Lyric | ||
{ | ||
Text = "karaoke", | ||
Language = new CultureInfo(17), // for auto-generate ruby and romaji. | ||
TimeTags = new[] // for auto-generate notes. | ||
{ | ||
new TimeTag(new TextIndex(0), 0), | ||
new TimeTag(new TextIndex(1), 1000), | ||
new TimeTag(new TextIndex(2), 2000), | ||
new TimeTag(new TextIndex(3), 3000), | ||
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), | ||
} | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
Assert.AreEqual(lyricReferenceChangeHandler, c.CanGenerate()); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestGeneratorNotSupportedLyricsWithReferenceLyric() | ||
{ | ||
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler(); | ||
|
||
if (lyricReferenceChangeHandler) | ||
{ | ||
PrepareHitObject(() => new Lyric | ||
{ | ||
Text = "karaoke" | ||
}, false); | ||
} | ||
|
||
PrepareLyricWithSyncConfig(new Lyric | ||
{ | ||
Text = "karaoke", | ||
Language = new CultureInfo(17), // for auto-generate ruby and romaji. | ||
TimeTags = new[] // for auto-generate notes. | ||
{ | ||
new TimeTag(new TextIndex(0), 0), | ||
new TimeTag(new TextIndex(1), 1000), | ||
new TimeTag(new TextIndex(2), 2000), | ||
new TimeTag(new TextIndex(3), 3000), | ||
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), | ||
} | ||
}); | ||
|
||
TriggerHandlerChanged(c => | ||
{ | ||
bool hasNotSupportedLyrics = c.GetGeneratorNotSupportedLyrics().Any(); | ||
Assert.AreEqual(lyricReferenceChangeHandler, !hasNotSupportedLyrics); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TestAutoGenerate() | ||
{ | ||
bool lyricReferenceChangeHandler = isLyricReferenceChangeHandler(); | ||
|
||
if (lyricReferenceChangeHandler) | ||
{ | ||
PrepareHitObject(() => new Lyric | ||
{ | ||
Text = "karaoke" | ||
}, false); | ||
} | ||
|
||
PrepareLyricWithSyncConfig(new Lyric | ||
{ | ||
Text = "karaoke", | ||
Language = new CultureInfo(17), // for auto-generate ruby and romaji. | ||
TimeTags = new[] // for auto-generate notes. | ||
{ | ||
new TimeTag(new TextIndex(0), 0), | ||
new TimeTag(new TextIndex(1), 1000), | ||
new TimeTag(new TextIndex(2), 2000), | ||
new TimeTag(new TextIndex(3), 3000), | ||
new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), | ||
} | ||
}); | ||
|
||
if (lyricReferenceChangeHandler) | ||
{ | ||
TriggerHandlerChanged(c => c.AutoGenerate()); | ||
} | ||
else | ||
{ | ||
TriggerHandlerChangedWithChangeForbiddenException(c => c.AutoGenerate()); | ||
} | ||
} | ||
|
||
private bool isLyricReferenceChangeHandler() | ||
=> typeof(TChangeHandler) == typeof(LyricReferenceChangeHandler); | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.