diff --git a/osu.Framework.Font.Tests/Helper/TestCaseTagHelper.cs b/osu.Framework.Font.Tests/Helper/TestCaseTagHelper.cs
index 5076971..6637059 100644
--- a/osu.Framework.Font.Tests/Helper/TestCaseTagHelper.cs
+++ b/osu.Framework.Font.Tests/Helper/TestCaseTagHelper.cs
@@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
+using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using osu.Framework.Graphics.Sprites;
@@ -41,7 +42,35 @@ public static PositionText ParsePositionText(string str)
};
}
- public static PositionText[] ParseParsePositionTexts(string[] strings)
+ ///
+ /// Process test case time tag string format into
+ ///
+ ///
+ /// [0,start]:1000
+ ///
+ /// Time tag string format
+ /// Time tag object
+ public static Tuple ParseTimeTag(string str)
+ {
+ if (string.IsNullOrEmpty(str))
+ return new Tuple(new TextIndex(), 0);
+
+ var regex = new Regex("(?[-0-9]+),(?start|end)]:(?[-0-9]+|s*|)");
+ var result = regex.Match(str);
+ if (!result.Success)
+ throw new RegexMatchTimeoutException(nameof(str));
+
+ int index = int.Parse(result.Groups["index"].Value);
+ var state = result.Groups["state"].Value == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
+ double time = string.IsNullOrEmpty(result.Groups["time"].Value) ? 0 : double.Parse(result.Groups["time"].Value);
+
+ return new Tuple(new TextIndex(index, state), time);
+ }
+
+ public static PositionText[] ParseParsePositionTexts(IEnumerable strings)
=> strings?.Select(ParsePositionText).ToArray();
+
+ public static IReadOnlyDictionary ParseTimeTags(IEnumerable strings)
+ => strings?.Select(ParseTimeTag).ToDictionary(k => k.Item1, k => k.Item2);
}
}
diff --git a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs
index 400f9dd..88f1766 100644
--- a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs
+++ b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteText.cs
@@ -1,20 +1,17 @@
-// Copyright (c) karaoke.dev . Licensed under the MIT Licence.
+// Copyright (c) karaoke.dev . Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
-using System.Collections.Generic;
+using System.Linq;
using NUnit.Framework;
using osu.Framework.Font.Tests.Helper;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
-using osu.Framework.Timing;
-using osuTK;
using osuTK.Graphics;
namespace osu.Framework.Font.Tests.Visual.Sprites
{
public class TestSceneKaraokeSpriteText : TestScene
{
- private readonly ManualClock manualClock = new();
private readonly KaraokeSpriteText karaokeSpriteText;
public TestSceneKaraokeSpriteText()
@@ -22,201 +19,67 @@ public TestSceneKaraokeSpriteText()
Child = karaokeSpriteText = new KaraokeSpriteText
{
Text = "カラオケ!",
- Rubies = new[]
- {
- new PositionText
- {
- StartIndex = 0,
- EndIndex = 1,
- Text = "か"
- },
- new PositionText
- {
- StartIndex = 2,
- EndIndex = 3,
- Text = "お"
- }
- },
- Romajies = new[]
- {
- new PositionText
- {
- StartIndex = 1,
- EndIndex = 2,
- Text = "ra"
- },
- new PositionText
- {
- StartIndex = 3,
- EndIndex = 4,
- Text = "ke"
- }
- },
+ Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[2,3]:お" }),
+ Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[1,2]:ra", "[3,4]:ke" }),
LeftTextColour = Color4.Green,
RightTextColour = Color4.Red,
};
}
- [TestCase(false)]
- [TestCase(true)]
- public void TestKaraokeSpriteTextTimeTag(bool manualTime)
+ [TestCase(new[] { "[0,start]:500", "[1,start]:600", "[2,start]:1000", "[3,start]:1500", "[4,start]:2000" }, true)] // Normal time-tag.
+ [TestCase(new[] { "[0,start]:0", "[0,end]:100", "[1,start]:1000", "[1,end]:1100", "[2,start]:2000", "[2,end]:2100", "[3,start]:3000", "[3,end]:3100", "[4,start]:4000", "[4,end]:4100" }, true)]
+ [TestCase(new[] { "[-1,start]:0", "[0,start]:500", "[1,end]:600", "[2,start]:1000", "[3,end]:1500", "[4,end]:2000", "[8,end]:2500" }, true)] // Out-of-range time-tag, but it's acceptable now.
+ [TestCase(new[] { "[0,start]:500" }, true)] // Only one time-tag.
+ public void TestKaraokeSpriteTextTimeTags(string[] timeTags, bool boo)
{
- if (manualTime)
+ AddStep("Apply time-tags", () =>
{
- AddSliderStep("Here can adjust time", 0, 3000, 1000, time =>
- {
- manualClock.CurrentTime = time;
- });
- }
+ var startTime = Clock.CurrentTime;
- AddStep("Default time tag", () =>
- {
- var startTime = getStartTime();
-
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- { new TextIndex(0), startTime + 500 },
- { new TextIndex(1), startTime + 600 },
- { new TextIndex(2), startTime + 1000 },
- { new TextIndex(3), startTime + 1500 },
- { new TextIndex(4), startTime + 2000 },
- };
- });
- AddStep("Time tag with end state", () =>
- {
- var startTime = getStartTime();
-
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- // カ
- { new TextIndex(0), startTime + 0 },
- { new TextIndex(0, TextIndex.IndexState.End), startTime + 100 },
- // ラ
- { new TextIndex(1), startTime + 1000 },
- { new TextIndex(1, TextIndex.IndexState.End), startTime + 1100 },
- // オ
- { new TextIndex(2), startTime + 2000 },
- { new TextIndex(2, TextIndex.IndexState.End), startTime + 2100 },
- // ケ
- { new TextIndex(3), startTime + 3000 },
- { new TextIndex(3, TextIndex.IndexState.End), startTime + 3100 },
- // !
- { new TextIndex(4), startTime + 4000 },
- { new TextIndex(4, TextIndex.IndexState.End), startTime + 4100 },
- };
- });
- AddStep("Time tag with wrong order", () =>
- {
- var startTime = getStartTime();
-
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- { new TextIndex(4), startTime + 2000 },
- { new TextIndex(3), startTime + 1500 },
- { new TextIndex(2), startTime + 1000 },
- { new TextIndex(1), startTime + 600 },
- { new TextIndex(0), startTime + 500 },
- };
+ karaokeSpriteText.TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags)
+ .ToDictionary(k => k.Key, v => v.Value + startTime);
});
- AddStep("Time tag with out of range", () =>
- {
- var startTime = getStartTime();
-
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- { new TextIndex(-1), startTime + 0 },
- { new TextIndex(0), startTime + 500 },
- { new TextIndex(1), startTime + 600 },
- { new TextIndex(2), startTime + 1000 },
- { new TextIndex(3), startTime + 1500 },
- { new TextIndex(4), startTime + 2000 },
- { new TextIndex(8), startTime + 2500 },
- };
- });
-
- AddStep("Only one time-tag", () =>
- {
- var startTime = getStartTime();
-
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- { new TextIndex(0), startTime + 500 },
- };
- });
-
- AddStep("None time-tag", () =>
- {
- karaokeSpriteText.Clock = manualTime ? new FramedClock(manualClock) : Clock;
- karaokeSpriteText.TimeTags = null;
- });
-
- double getStartTime()
- => manualTime ? 0 : Clock.CurrentTime;
}
- [Test]
- public void TestChangeText()
+ [TestCase("カラオケー")]
+ public void TestText(string text)
{
- AddStep("Change texr", () =>
+ AddStep("Change text", () =>
{
- karaokeSpriteText.Text = "カラオケー";
+ karaokeSpriteText.Text = text;
});
}
- [Test]
- public void TestChangeRuby()
+ [TestCase(new[] { "[0,1]:123aaa", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }, true)]
+ public void TestRuby(string[] rubyTags, bool boo)
{
AddStep("Change ruby", () =>
{
- var rubyTags = new[] { "[0,1]:123aaa", "[1,2]:ら", "[2,3]:お", "[3,4]:け" };
var ruby = TestCaseTagHelper.ParseParsePositionTexts(rubyTags);
karaokeSpriteText.Rubies = ruby;
});
}
- [Test]
- public void TestChangeRomaji()
+ [TestCase(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }, true)]
+ public void TestRomaji(string[] romajiTags, bool boo)
{
AddStep("Change romaji", () =>
{
- var romajiTags = new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" };
var romajies = TestCaseTagHelper.ParseParsePositionTexts(romajiTags);
karaokeSpriteText.Romajies = romajies;
});
}
- [Test]
- public void TestChangeFont()
+ [TestCase(48, 24, 24)]
+ [TestCase(48, 10, 24)]
+ [TestCase(48, 24, 10)]
+ public void TestFont(int mainFontSize, int rubyFontSize, int romajiFontSize)
{
AddStep("Change font", () =>
{
- var font = FontUsage.Default.With(size: 64);
- karaokeSpriteText.Font = font;
- });
- }
-
- [Test]
- public void TestChangeRubyFont()
- {
- AddStep("Change ruby font", () =>
- {
- var font = FontUsage.Default.With(size: 24);
- karaokeSpriteText.RubyFont = font;
- });
- }
-
- [Test]
- public void TestChangeRomajiFont()
- {
- AddStep("Change romaji font", () =>
- {
- var font = FontUsage.Default.With(size: 24);
- karaokeSpriteText.RomajiFont = font;
+ karaokeSpriteText.Font = new FontUsage(null, mainFontSize);
+ karaokeSpriteText.RubyFont = new FontUsage(null, rubyFontSize);
+ karaokeSpriteText.RomajiFont = new FontUsage(null, romajiFontSize);
});
}
@@ -225,6 +88,7 @@ public void TestLeftTextColour()
{
AddStep("Change left text colour", () =>
{
+ // note: usually we use shader to adjust the style.
karaokeSpriteText.LeftTextColour = Color4.Orange;
});
}
@@ -238,66 +102,47 @@ public void TestRightTextColour()
});
}
- [Test]
- public void TestRubyAlignment()
- {
- AddStep("Test ruby alignment", () =>
- {
- karaokeSpriteText.RubyAlignment = LyricTextAlignment.EqualSpace;
- });
- }
-
- [Test]
- public void TestRomajiAlignment()
+ [TestCase(LyricTextAlignment.Auto, LyricTextAlignment.Auto)]
+ [TestCase(LyricTextAlignment.Auto, LyricTextAlignment.Center)]
+ [TestCase(LyricTextAlignment.Auto, LyricTextAlignment.EqualSpace)]
+ [TestCase(LyricTextAlignment.Center, LyricTextAlignment.Auto)]
+ [TestCase(LyricTextAlignment.Center, LyricTextAlignment.Center)]
+ [TestCase(LyricTextAlignment.Center, LyricTextAlignment.EqualSpace)]
+ [TestCase(LyricTextAlignment.EqualSpace, LyricTextAlignment.Auto)]
+ [TestCase(LyricTextAlignment.EqualSpace, LyricTextAlignment.Center)]
+ [TestCase(LyricTextAlignment.EqualSpace, LyricTextAlignment.EqualSpace)]
+ public void TestAlignment(LyricTextAlignment rubyAlignment, LyricTextAlignment romajiAlignment)
{
- AddStep("Test romaji alignment", () =>
+ AddStep("Change alignment", () =>
{
- karaokeSpriteText.RomajiAlignment = LyricTextAlignment.EqualSpace;
+ karaokeSpriteText.RomajiAlignment = rubyAlignment;
+ karaokeSpriteText.RomajiAlignment = romajiAlignment;
});
}
- [Test]
- public void TestSpacing()
+ [TestCase(null, null, null)]
+ [TestCase("(10,0)", null, null)]
+ [TestCase(null, "(10,0)", null)]
+ [TestCase(null, null, "(10,0)")]
+ public void TestSpacing(string spacing, string rubySpacing, string romajiSpacing)
{
AddStep("Change spacing", () =>
{
- karaokeSpriteText.Spacing = new Vector2(10);
+ karaokeSpriteText.Spacing = TestCaseVectorHelper.ParseVector2(spacing);
+ karaokeSpriteText.RubySpacing = TestCaseVectorHelper.ParseVector2(rubySpacing);
+ karaokeSpriteText.RomajiSpacing = TestCaseVectorHelper.ParseVector2(romajiSpacing);
});
}
- [Test]
- public void TestRubySpacing()
- {
- AddStep("Change ruby spacing", () =>
- {
- karaokeSpriteText.RubySpacing = new Vector2(10);
- });
- }
-
- [Test]
- public void TestRomajiSpacing()
- {
- AddStep("Change romaji spacing", () =>
- {
- karaokeSpriteText.RomajiSpacing = new Vector2(10);
- });
- }
-
- [Test]
- public void TestRubyMargin()
- {
- AddStep("Change ruby margin", () =>
- {
- karaokeSpriteText.RubyMargin = 10;
- });
- }
-
- [Test]
- public void TestRomajiMargin()
+ [TestCase(0, 0)]
+ [TestCase(0, 20)]
+ [TestCase(20, 0)]
+ public void TestMarginPadding(int rubyMargin, int romajiMargin)
{
- AddStep("Change romaji margin", () =>
+ AddStep("Change margin", () =>
{
- karaokeSpriteText.RomajiMargin = 10;
+ karaokeSpriteText.RubyMargin = rubyMargin;
+ karaokeSpriteText.RomajiMargin = romajiMargin;
});
}
}
diff --git a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteTextWithShader.cs b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteTextWithShader.cs
index 34a8bbc..40da926 100644
--- a/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteTextWithShader.cs
+++ b/osu.Framework.Font.Tests/Visual/Sprites/TestSceneKaraokeSpriteTextWithShader.cs
@@ -1,14 +1,13 @@
// Copyright (c) karaoke.dev . Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
-using System;
-using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Extensions;
using osu.Framework.Font.Tests.Helper;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Sprites;
+using osu.Framework.Timing;
using osuTK;
using osuTK.Graphics;
@@ -16,21 +15,30 @@ namespace osu.Framework.Font.Tests.Visual.Sprites
{
public class TestSceneKaraokeSpriteTextWithShader : BackgroundGridTestScene
{
- private readonly KaraokeSpriteText karaokeSpriteText;
+ private readonly ManualClock manualClock = new();
+
+ private readonly TestKaraokeSpriteText karaokeSpriteText;
public TestSceneKaraokeSpriteTextWithShader()
{
- Child = karaokeSpriteText = new KaraokeSpriteText
+ Child = karaokeSpriteText = new TestKaraokeSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケ!",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
+ TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:500", "[1,start]:600", "[2,start]:1000", "[3,start]:1500", "[4,start]:2000" }),
Scale = new Vector2(2),
LeftTextColour = Color4.Green,
RightTextColour = Color4.Red,
+ Clock = new FramedClock(manualClock),
};
+
+ AddSliderStep("Adjust clock time", 0, 3000, 1000, time =>
+ {
+ manualClock.CurrentTime = time;
+ });
}
[Test]
@@ -103,26 +111,9 @@ public void ApplyRightLyricTextShader()
});
}
- protected new void AddStep(string description, Action action)
+ private class TestKaraokeSpriteText : KaraokeSpriteText
{
- base.AddStep(description, () =>
- {
- action?.Invoke();
- resetTime();
- });
-
- void resetTime()
- {
- var startTime = Time.Current;
- karaokeSpriteText.TimeTags = new Dictionary
- {
- { new TextIndex(0), startTime + 500 },
- { new TextIndex(1), startTime + 600 },
- { new TextIndex(2), startTime + 1000 },
- { new TextIndex(3), startTime + 1500 },
- { new TextIndex(4), startTime + 2000 },
- };
- }
+ public override bool RemoveCompletedTransforms => false;
}
}
}