Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lyric transformer issue #1293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void TestDecodeNicoKara()
var outlineShader = shaders.FirstOrDefault() as OutlineShader;
Assert.IsNotNull(outlineShader);
Assert.AreEqual(new Color4(255, 255, 255, 255), outlineShader.OutlineColour);
Assert.AreEqual(10, outlineShader.Radius);
Assert.AreEqual(3, outlineShader.Radius);

// Test shader convert result.
var shadowShader = shaders.LastOrDefault() as ShadowShader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void TestLyricStyleSerializer()
var lyricStyle = LyricStyle.CreateDefault();

const string expected =
"{\"$type\":2,\"left_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":10,\"outline_colour\":\"#CCA532\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#6B5B2D\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"right_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":10,\"outline_colour\":\"#5932CC\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#3D2D6B\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"name\":\"Default\"}";
"{\"$type\":2,\"left_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":3.0,\"outline_colour\":\"#CCA532\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#6B5B2D\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"right_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":3.0,\"outline_colour\":\"#5932CC\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#3D2D6B\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"name\":\"Default\"}";
string actual = JsonConvert.SerializeObject(lyricStyle, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand All @@ -86,7 +86,7 @@ public void TestLyricStyleSerializer()
public void TestLyricStyleDeserializer()
{
const string json =
"{\"$type\":2,\"left_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":10,\"outline_colour\":\"#CCA532\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#6B5B2D\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"right_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":10,\"outline_colour\":\"#5932CC\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#3D2D6B\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"name\":\"Default\"}";
"{\"$type\":2,\"left_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":3.0,\"outline_colour\":\"#CCA532\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#6B5B2D\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"right_lyric_text_shaders\":[{\"$type\":\"StepShader\",\"name\":\"Step shader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"OutlineShader\",\"radius\":3.0,\"outline_colour\":\"#5932CC\"},{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#3D2D6B\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}],\"name\":\"Default\"}";

var expected = LyricStyle.CreateDefault();
var actual = JsonConvert.DeserializeObject<IKaraokeSkinElement>(json, CreateSettings()) as LyricStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public void TestSerializer()
{
var shader = new ShadowShader
{
ShadowOffset = new Vector2(10),
ShadowOffset = new Vector2(3),
ShadowColour = new Color4(0.5f, 0.5f, 0.5f, 0.5f),
};

const string expected = "{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":10.0,\"y\":10.0}}";
const string expected = "{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}";
string result = JsonConvert.SerializeObject(shader, CreateSettings());
Assert.AreEqual(expected, result);
}

[Test]
public void TestDeserialize()
{
const string json = "{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":10.0,\"y\":10.0}}";
const string json = "{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}";

var expected = new ShadowShader
{
ShadowOffset = new Vector2(10),
ShadowOffset = new Vector2(3),
ShadowColour = new Color4(0.5f, 0.5f, 0.5f, 0.5f),
};
var actual = JsonConvert.DeserializeObject<ICustomizedShader>(json, CreateSettings()) as ShadowShader;
Expand All @@ -60,14 +60,14 @@ public void TestSerializerListItems()
{
new ShadowShader
{
ShadowOffset = new Vector2(10),
ShadowOffset = new Vector2(3),
ShadowColour = new Color4(0.5f, 0.5f, 0.5f, 0.5f),
}
}
};

const string expected =
"{\"$type\":\"StepShader\",\"name\":\"HelloShader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":10.0,\"y\":10.0}}]}";
"{\"$type\":\"StepShader\",\"name\":\"HelloShader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}";
string actual = JsonConvert.SerializeObject(shader, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand All @@ -76,7 +76,7 @@ public void TestSerializerListItems()
public void TestDeserializeListItems()
{
const string json =
"{\"$type\":\"StepShader\",\"name\":\"HelloShader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":10.0,\"y\":10.0}}]}";
"{\"$type\":\"StepShader\",\"name\":\"HelloShader\",\"draw\":true,\"step_shaders\":[{\"$type\":\"ShadowShader\",\"shadow_colour\":\"#7F7F7F7F\",\"shadow_offset\":{\"x\":3.0,\"y\":3.0}}]}";

var expected = new StepShader
{
Expand All @@ -85,7 +85,7 @@ public void TestDeserializeListItems()
{
new ShadowShader
{
ShadowOffset = new Vector2(10),
ShadowOffset = new Vector2(3),
ShadowColour = new Color4(0.5f, 0.5f, 0.5f, 0.5f),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#CCA532"
},
{
Expand All @@ -53,7 +53,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#5932CC"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#CCA532"
},
{
Expand All @@ -33,7 +33,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#5932CC"
},
{
Expand Down
13 changes: 13 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/TextTagUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,18 @@ public void TestGetTextFromLyric(string textTag, string lyric, string expected)
string actual = TextTagUtils.GetTextFromLyric(rubyTag, lyric);
Assert.AreEqual(expected, actual);
}

[TestCase("[0,1]:ka")]
[TestCase("[1,0]:ka")] // Should be able to convert even if time-tag is invalid.
[TestCase("[-1,1]:ka")] // Should be able to convert even if time-tag is invalid.
public void TestToPositionText(string textTag)
{
var rubyTag = TestCaseTagHelper.ParseRubyTag(textTag);
var actual = TextTagUtils.ToPositionText(rubyTag);

Assert.AreEqual(rubyTag.Text, actual.Text);
Assert.AreEqual(rubyTag.StartIndex, actual.StartIndex);
Assert.AreEqual(rubyTag.EndIndex, actual.EndIndex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ private static OutlineShader createOutlineShader(BrushInfo info, FontInfo fontIn
return new OutlineShader
{
OutlineColour = color,
Radius = (int)radius,
// Notice that should adjust the radius for looking the same.
Radius = (int)(radius / 3),
};

static float convertEdgeSize(FontInfo info) => info.EdgeSize;
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public LyricEditorSkin(SkinInfo skin, IStorageResourceProvider resources)
{
new OutlineShader
{
Radius = 4,
Radius = 2,
Colour = Color4Extensions.FromHex("#3D2D6B"),
OutlineColour = Color4Extensions.FromHex("#CCA532")
},
Expand All @@ -60,7 +60,7 @@ public LyricEditorSkin(SkinInfo skin, IStorageResourceProvider resources)
{
new OutlineShader
{
Radius = 4,
Radius = 2,
OutlineColour = Color4Extensions.FromHex("#5932CC")
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Extensions;
using osu.Game.Rulesets.Karaoke.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Types;
Expand Down Expand Up @@ -165,50 +164,16 @@ static FontUsage getFont(float? charSize = null)
public class EditorLyricSpriteText : LyricSpriteText
{
public RectangleF GetRubyTagPosition(RubyTag rubyTag)
{
var matchedRuby = Rubies.FirstOrDefault(x => propertyMatched(x, rubyTag));
int rubyIndex = Rubies.IndexOf(matchedRuby);
if (rubyIndex < 0)
throw new ArgumentOutOfRangeException(nameof(rubyIndex));

int startCharacterIndex = Text.Length + skinIndex(Rubies, rubyIndex);
int count = matchedRuby.Text.Length;
var rectangles = Characters.ToList().GetRange(startCharacterIndex, count).Select(x => x.DrawRectangle).ToArray();
return RectangleFUtils.Union(rectangles);
}
=> GetRubyTagPosition(TextTagUtils.ToPositionText(rubyTag));

public RectangleF GetRomajiTagPosition(RomajiTag romajiTag)
{
var matchedRomaji = Romajies.FirstOrDefault(x => propertyMatched(x, romajiTag));
int romajiIndex = Romajies.IndexOf(matchedRomaji);
if (romajiIndex < 0)
throw new ArgumentOutOfRangeException(nameof(romajiIndex));

int startCharacterIndex = Text.Length + skinIndex(Rubies, Rubies.Count) + skinIndex(Romajies, romajiIndex);
int count = matchedRomaji.Text.Length;
var rectangles = Characters.ToList().GetRange(startCharacterIndex, count).Select(x => x.DrawRectangle).ToArray();
return RectangleFUtils.Union(rectangles);
}
=> GetRomajiTagPosition(TextTagUtils.ToPositionText(romajiTag));

public Vector2 GetTimeTagPosition(TextIndex index)
{
if (string.IsNullOrEmpty(Text))
return default;

int charIndex = Math.Min(index.Index, Text.Length - 1);
var character = Characters[charIndex];
var drawRectangle = character.DrawRectangle;

float x = index.State == TextIndex.IndexState.Start ? drawRectangle.Left : drawRectangle.Right;
float y = drawRectangle.Top - character.YOffset + LineBaseHeight;
return new Vector2(x, y);
var drawRectangle = GetCharacterRectangle(index.Index);
return index.State == TextIndex.IndexState.Start ? drawRectangle.BottomLeft : drawRectangle.BottomRight;
}

private int skinIndex(IEnumerable<PositionText> positionTexts, int endIndex)
=> positionTexts.Where((_, i) => i < endIndex).Sum(x => x.Text.Length);

private bool propertyMatched(PositionText positionText, ITextTag textTag)
=> positionText.StartIndex == textTag.StartIndex && positionText.EndIndex == textTag.EndIndex && positionText.Text == textTag.Text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void updateRubies()
{
if (chunkIndex == whole_chunk_index)
{
Rubies = DisplayRuby ? rubyTagsBindable?.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray() : null;
Rubies = DisplayRuby ? rubyTagsBindable?.Select(TextTagUtils.ToPositionText).ToArray() : null;
}
else
{
Expand All @@ -85,7 +85,7 @@ private void updateRomajies()
{
if (chunkIndex == whole_chunk_index)
{
Romajies = DisplayRomaji ? romajiTagsBindable?.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray() : null;
Romajies = DisplayRomaji ? romajiTagsBindable?.Select(TextTagUtils.ToPositionText).ToArray() : null;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;

namespace osu.Game.Rulesets.Karaoke.Graphics.Sprites
{
Expand Down Expand Up @@ -33,12 +34,12 @@ public DrawableLyricSpriteText(Lyric lyric)

private void updateRubies()
{
Rubies = rubyTagsBindable.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray();
Rubies = rubyTagsBindable.Select(TextTagUtils.ToPositionText).ToArray();
}

private void updateRomajies()
{
Romajies = romajiTagsBindable.Select(x => new PositionText(x.Text, x.StartIndex, x.EndIndex)).ToArray();
Romajies = romajiTagsBindable.Select(TextTagUtils.ToPositionText).ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#CCA532"
},
{
Expand All @@ -53,7 +53,7 @@
"step_shaders": [
{
"$type": "OutlineShader",
"radius": 10,
"radius": 3,
"outline_colour": "#5932CC"
},
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Skinning/Elements/LyricStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LyricStyle : IKaraokeSkinElement
{
new OutlineShader
{
Radius = 10,
Radius = 3,
OutlineColour = Color4Extensions.FromHex("#CCA532")
},
new ShadowShader
Expand All @@ -47,7 +47,7 @@ public class LyricStyle : IKaraokeSkinElement
{
new OutlineShader
{
Radius = 10,
Radius = 3,
OutlineColour = Color4Extensions.FromHex("#5932CC")
},
new ShadowShader
Expand Down
4 changes: 4 additions & 0 deletions osu.Game.Rulesets.Karaoke/Utils/TextTagUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Objects.Types;

namespace osu.Game.Rulesets.Karaoke.Utils
Expand Down Expand Up @@ -80,5 +81,8 @@ public static string GetTextFromLyric<T>(T textTag, string lyric) where T : ITex
(int startIndex, int endIndex) = GetFixedIndex(textTag, lyric);
return lyric.Substring(startIndex, endIndex - startIndex);
}

public static PositionText ToPositionText<T>(T textTag) where T : ITextTag
=> new(textTag.Text, textTag.StartIndex, textTag.EndIndex);
}
}
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="ILRepack.Lib.MSBuild" Version="2.1.18" />
<PackageReference Include="LanguageDetection.karaoke-dev" Version="1.3.3-alpha" />
<PackageReference Include="Octokit" Version="0.51.0" />
<PackageReference Include="osu.Framework.KaraokeFont" Version="2022.502.0" />
<PackageReference Include="osu.Framework.KaraokeFont" Version="2022.505.0" />
<PackageReference Include="osu.Framework.Microphone" Version="2022.327.0" />
<PackageReference Include="ppy.osu.Game" Version="2022.501.0" />
<PackageReference Include="LyricMaker" Version="1.1.1" />
Expand Down