Skip to content

Commit

Permalink
Merge pull request #1633 from andy840119/refactor-some-skin-logic
Browse files Browse the repository at this point in the history
Fix karaoke text not showing if use the legacy skin.
  • Loading branch information
andy840119 authored Oct 10, 2022
2 parents 3624738 + f00aa30 commit cb0ad1c
Show file tree
Hide file tree
Showing 18 changed files with 275 additions and 121 deletions.
38 changes: 37 additions & 1 deletion osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Edit.Components.Cursor;
using osu.Game.Rulesets.Karaoke.Extensions;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;

Expand All @@ -16,7 +20,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor
[TestFixture]
public class TestSceneLayoutToolTip : OsuTestScene
{
private readonly ISkin skin = new DefaultKaraokeSkin(null);
private ISkin skin = new TestingSkin(null);
private LayoutToolTip toolTip = null!;

[SetUp]
Expand Down Expand Up @@ -62,5 +66,37 @@ private void setTooltip(string testName, Action<Lyric> callBack)
toolTip.SetContent(singer);
});
}

/// <summary>
/// todo: it's a tricky way to create ruleset's own skin class.
/// should use generic skin like <see cref="LegacySkin"/> eventually.
/// </summary>
public class TestingSkin : KaraokeSkin
{
internal static readonly Guid DEFAULT_SKIN = new("FEC5A291-5709-11EC-9F10-0800200C9A66");

public static SkinInfo CreateInfo() => new()
{
ID = DEFAULT_SKIN,
Name = "karaoke! (default skin)",
Creator = "team karaoke!",
Protected = true,
InstantiationInfo = typeof(TestingSkin).GetInvariantInstantiationInfo()
};

public TestingSkin(IStorageResourceProvider? resources)
: this(CreateInfo(), resources)
{
}

[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
public TestingSkin(SkinInfo skin, IStorageResourceProvider? resources)
: base(skin, resources)
{
DefaultElement[ElementType.LyricConfig] = LyricConfig.CreateDefault();
DefaultElement[ElementType.LyricStyle] = LyricStyle.CreateDefault();
DefaultElement[ElementType.NoteStyle] = NoteStyle.CreateDefault();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.IO.Serialization;
using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Rulesets.Karaoke.Tests.Asserts;

namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters
{
Expand Down Expand Up @@ -40,8 +41,7 @@ public void TestLyricConfigDeserialize()

var expected = LyricConfig.CreateDefault();
var actual = (LyricConfig)JsonConvert.DeserializeObject<IKaraokeSkinElement>(json, CreateSettings())!;
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.SmartHorizon, actual.SmartHorizon);
ObjectAssert.ArePropertyEqual(expected, actual);
}

[Test]
Expand Down Expand Up @@ -75,8 +75,7 @@ public void TestLyricLayoutDeserialize()
VerticalMargin = 20,
};
var actual = (LyricLayout)JsonConvert.DeserializeObject<IKaraokeSkinElement>(json, CreateSettings())!;
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.Alignment, actual.Alignment);
ObjectAssert.ArePropertyEqual(expected, actual);
}

[Test]
Expand All @@ -98,10 +97,7 @@ public void TestLyricStyleDeserializer()

var expected = LyricStyle.CreateDefault();
var actual = (LyricStyle)JsonConvert.DeserializeObject<IKaraokeSkinElement>(json, CreateSettings())!;
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.ID, actual.ID);
Assert.AreEqual(expected.LeftLyricTextShaders.Count, actual.LeftLyricTextShaders.Count);
Assert.AreEqual(expected.RightLyricTextShaders.Count, actual.RightLyricTextShaders.Count);
ObjectAssert.ArePropertyEqual(expected, actual);
}

[Test]
Expand All @@ -121,9 +117,7 @@ public void TestNoteStyleDeserializer()

var expected = NoteStyle.CreateDefault();
var actual = (NoteStyle)JsonConvert.DeserializeObject<IKaraokeSkinElement>(json, CreateSettings())!;
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.ID, actual.ID);
Assert.AreEqual(expected.BlinkColor, actual.BlinkColor);
ObjectAssert.ArePropertyEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters;
using osu.Game.Rulesets.Karaoke.Skinning.Groups;
using osu.Game.Rulesets.Karaoke.Tests.Asserts;

namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters
{
Expand Down Expand Up @@ -37,9 +38,7 @@ public void TestGroupBySingerIdsDeserializer()
SingerIds = new[] { 1, 2 }
};
var actual = (GroupBySingerIds)JsonConvert.DeserializeObject<IGroup>(json, CreateSettings())!;
Assert.AreEqual(expected.ID, actual.ID);
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.SingerIds, actual.SingerIds);
ObjectAssert.ArePropertyEqual(expected, actual);
}

[Test]
Expand Down Expand Up @@ -69,9 +68,7 @@ public void TestGroupBySingerNumberDeserializer()
SingerNumber = 2,
};
var actual = (GroupBySingerNumber)JsonConvert.DeserializeObject<IGroup>(json, CreateSettings())!;
Assert.AreEqual(expected.ID, actual.ID);
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.SingerNumber, actual.SingerNumber);
ObjectAssert.ArePropertyEqual(expected, actual);
}

[Test]
Expand Down Expand Up @@ -101,9 +98,7 @@ public void TestGroupByLyricIdsDeserializer()
LyricIds = new[] { 1, 2 }
};
var actual = (GroupByLyricIds)JsonConvert.DeserializeObject<IGroup>(json, CreateSettings())!;
Assert.AreEqual(expected.ID, actual.ID);
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.LyricIds, actual.LyricIds);
ObjectAssert.ArePropertyEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Rulesets.Karaoke.Skinning.MappingRoles;
using osu.Game.Rulesets.Karaoke.Tests.Asserts;

namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters
{
Expand Down Expand Up @@ -40,10 +41,7 @@ public void TestDefaultMappingRoleDeserializer()
GroupId = 2,
};
var actual = (DefaultMappingRole)JsonConvert.DeserializeObject<IMappingRole>(json, CreateSettings())!;
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.ElementType, actual.ElementType);
Assert.AreEqual(expected.ElementId, actual.ElementId);
Assert.AreEqual(expected.GroupId, actual.GroupId);
ObjectAssert.ArePropertyEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters;

namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization
{
[Ignore($"Test case already in the {nameof(KaraokeSkinElementConvertorTest)}, {nameof(KaraokeSkinGroupConvertorTest)}, and {nameof(KaraokeSkinMappingRoleConvertorTest)}")]
public class SkinJsonSerializableExtensionsTest
{
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// 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 JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Game.Database;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Extensions;
using osu.Game.Rulesets.Karaoke.Screens.Skin;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.Skinning.Elements;
using osu.Game.Screens.Edit;
using osu.Game.Skinning;

Expand All @@ -28,11 +33,43 @@ public class TestSceneKaraokeSkinEditor : ScreenTestScene<KaraokeSkinEditor>
[BackgroundDependencyLoader]
private void load(SkinManager skinManager)
{
skinManager.CurrentSkinInfo.Value = DefaultKaraokeSkin.CreateInfo().ToLiveUnmanaged();
skinManager.CurrentSkinInfo.Value = TestingSkin.CreateInfo().ToLiveUnmanaged();

karaokeSkin = skinManager.CurrentSkin.Value as KaraokeSkin;
}

protected override KaraokeSkinEditor CreateScreen() => new(karaokeSkin);

/// <summary>
/// todo: it's a tricky way to create ruleset's own skin class.
/// should use generic skin like <see cref="LegacySkin"/> eventually.
/// </summary>
public class TestingSkin : KaraokeSkin
{
internal static readonly Guid DEFAULT_SKIN = new("FEC5A291-5709-11EC-9F10-0800200C9A66");

public static SkinInfo CreateInfo() => new()
{
ID = DEFAULT_SKIN,
Name = "karaoke! (default skin)",
Creator = "team karaoke!",
Protected = true,
InstantiationInfo = typeof(TestingSkin).GetInvariantInstantiationInfo()
};

public TestingSkin(IStorageResourceProvider? resources)
: this(CreateInfo(), resources)
{
}

[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]
public TestingSkin(SkinInfo skin, IStorageResourceProvider? resources)
: base(skin, resources)
{
DefaultElement[ElementType.LyricConfig] = LyricConfig.CreateDefault();
DefaultElement[ElementType.LyricStyle] = LyricStyle.CreateDefault();
DefaultElement[ElementType.NoteStyle] = NoteStyle.CreateDefault();
}
}
}
}
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class LyricEditorSkin : KaraokeSkin
Name = "karaoke! (default editor skin)",
Creator = "team karaoke!",
Protected = true,
InstantiationInfo = typeof(DefaultKaraokeSkin).GetInvariantInstantiationInfo(),
InstantiationInfo = typeof(LyricEditorSkin).GetInvariantInstantiationInfo(),
};

public LyricEditorSkin(IStorageResourceProvider? resources)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using Newtonsoft.Json;
using osu.Framework.IO.Serialization;
using osu.Game.IO.Serialization;
using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters;

namespace osu.Game.Rulesets.Karaoke.IO.Serialization
{
public static class SkinJsonSerializableExtensions
{
public static JsonSerializerSettings CreateSkinElementGlobalSettings()
{
var globalSetting = JsonSerializableExtensions.CreateGlobalSettings();
globalSetting.ContractResolver = new SnakeCaseKeyContractResolver();
globalSetting.Converters.Add(new KaraokeSkinElementConvertor());
globalSetting.Converters.Add(new ShaderConvertor());
globalSetting.Converters.Add(new Vector2Converter());
globalSetting.Converters.Add(new ColourConvertor());
globalSetting.Converters.Add(new FontUsageConvertor());
return globalSetting;
}

public static JsonSerializerSettings CreateSkinGroupGlobalSettings()
{
var globalSetting = JsonSerializableExtensions.CreateGlobalSettings();
globalSetting.ContractResolver = new SnakeCaseKeyContractResolver();
globalSetting.Converters.Add(new KaraokeSkinGroupConvertor());
return globalSetting;
}

public static JsonSerializerSettings CreateSkinMappingGlobalSettings()
{
var globalSetting = JsonSerializableExtensions.CreateGlobalSettings();
globalSetting.ContractResolver = new SnakeCaseKeyContractResolver();
globalSetting.Converters.Add(new KaraokeSkinMappingRoleConvertor());
return globalSetting;
}
}
}
20 changes: 18 additions & 2 deletions osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
using osu.Game.Rulesets.Karaoke.Replays;
using osu.Game.Rulesets.Karaoke.Resources;
using osu.Game.Rulesets.Karaoke.Scoring;
using osu.Game.Rulesets.Karaoke.Skinning.Argon;
using osu.Game.Rulesets.Karaoke.Skinning.Legacy;
using osu.Game.Rulesets.Karaoke.Skinning.Triangles;
using osu.Game.Rulesets.Karaoke.Statistics;
using osu.Game.Rulesets.Karaoke.UI;
using osu.Game.Rulesets.Mods;
Expand Down Expand Up @@ -193,8 +195,22 @@ public override IResourceStore<byte[]> CreateResourceStore()

public override ISkin CreateSkinTransformer(ISkin skin, IBeatmap beatmap)
{
// always return the legacy skin for now until have skin for karaoke.
return new KaraokeLegacySkinTransformer(skin, beatmap);
switch (skin)
{
case TrianglesSkin:
return new KaraokeTrianglesSkinTransformer(skin, beatmap);

case ArgonSkin:
return new KaraokeArgonSkinTransformer(skin, beatmap);

case DefaultLegacySkin:
return new KaraokeClassicSkinTransformer(skin, beatmap);

case LegacySkin:
return new KaraokeLegacySkinTransformer(skin, beatmap);
}

return null;
}

public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new KaraokeReplayFrame();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.Beatmaps;
using osu.Game.Rulesets.Karaoke.Skinning.Default;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Karaoke.Skinning.Argon
{
public class KaraokeArgonSkinTransformer : KaraokeDefaultSkinTransformer
{
public KaraokeArgonSkinTransformer(ISkin skin, IBeatmap beatmap)
: base(skin, beatmap)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Skinning;

namespace osu.Game.Rulesets.Karaoke.Skinning.Default
{
public class KaraokeDefaultSkinTransformer : SkinTransformer
{
private readonly KaraokeSkin karaokeSkin;

public KaraokeDefaultSkinTransformer(ISkin skin, IBeatmap beatmap)
: base(skin)
{
karaokeSkin = new KaraokeSkin(new SkinInfo(), new InternalSkinStorageResourceProvider("Default"));
}

public override IBindable<TValue>? GetConfig<TLookup, TValue>(TLookup lookup)
=> karaokeSkin.GetConfig<TLookup, TValue>(lookup);
}
}
Loading

0 comments on commit cb0ad1c

Please sign in to comment.