From 5cc43937d33c3a479707f5e2cef2a0ec1b5a8dbd Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 00:39:32 +0800 Subject: [PATCH 1/6] Use object.assert() to check the test reuslt. --- .../KaraokeSkinElementConvertorTest.cs | 16 +++++----------- .../Converters/KaraokeSkinGroupConvertorTest.cs | 13 ++++--------- .../KaraokeSkinMappingRoleConvertorTest.cs | 6 ++---- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinElementConvertorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinElementConvertorTest.cs index f06a54179..ad0bc927c 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinElementConvertorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinElementConvertorTest.cs @@ -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 { @@ -40,8 +41,7 @@ public void TestLyricConfigDeserialize() var expected = LyricConfig.CreateDefault(); var actual = (LyricConfig)JsonConvert.DeserializeObject(json, CreateSettings())!; - Assert.AreEqual(expected.Name, actual.Name); - Assert.AreEqual(expected.SmartHorizon, actual.SmartHorizon); + ObjectAssert.ArePropertyEqual(expected, actual); } [Test] @@ -75,8 +75,7 @@ public void TestLyricLayoutDeserialize() VerticalMargin = 20, }; var actual = (LyricLayout)JsonConvert.DeserializeObject(json, CreateSettings())!; - Assert.AreEqual(expected.Name, actual.Name); - Assert.AreEqual(expected.Alignment, actual.Alignment); + ObjectAssert.ArePropertyEqual(expected, actual); } [Test] @@ -98,10 +97,7 @@ public void TestLyricStyleDeserializer() var expected = LyricStyle.CreateDefault(); var actual = (LyricStyle)JsonConvert.DeserializeObject(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] @@ -121,9 +117,7 @@ public void TestNoteStyleDeserializer() var expected = NoteStyle.CreateDefault(); var actual = (NoteStyle)JsonConvert.DeserializeObject(json, CreateSettings())!; - Assert.AreEqual(expected.Name, actual.Name); - Assert.AreEqual(expected.ID, actual.ID); - Assert.AreEqual(expected.BlinkColor, actual.BlinkColor); + ObjectAssert.ArePropertyEqual(expected, actual); } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinGroupConvertorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinGroupConvertorTest.cs index 6631a90bc..3ebfc7364 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinGroupConvertorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinGroupConvertorTest.cs @@ -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 { @@ -37,9 +38,7 @@ public void TestGroupBySingerIdsDeserializer() SingerIds = new[] { 1, 2 } }; var actual = (GroupBySingerIds)JsonConvert.DeserializeObject(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] @@ -69,9 +68,7 @@ public void TestGroupBySingerNumberDeserializer() SingerNumber = 2, }; var actual = (GroupBySingerNumber)JsonConvert.DeserializeObject(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] @@ -101,9 +98,7 @@ public void TestGroupByLyricIdsDeserializer() LyricIds = new[] { 1, 2 } }; var actual = (GroupByLyricIds)JsonConvert.DeserializeObject(json, CreateSettings())!; - Assert.AreEqual(expected.ID, actual.ID); - Assert.AreEqual(expected.Name, actual.Name); - Assert.AreEqual(expected.LyricIds, actual.LyricIds); + ObjectAssert.ArePropertyEqual(expected, actual); } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertorTest.cs index ef21e2eb5..e0b7380e8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertorTest.cs @@ -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 { @@ -40,10 +41,7 @@ public void TestDefaultMappingRoleDeserializer() GroupId = 2, }; var actual = (DefaultMappingRole)JsonConvert.DeserializeObject(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); } } } From 37cc22f8b491f579a5bf805ffebf5d2a89facafe Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 00:42:12 +0800 Subject: [PATCH 2/6] Collect the logic for easier maintainance. --- .../SkinJsonSerializableExtensionsTest.cs | 13 ++++++ .../SkinJsonSerializableExtensions.cs | 41 +++++++++++++++++++ .../Skinning/KaraokeBeatmapSkin.cs | 10 ++--- .../Skinning/KaraokeSkin.cs | 16 ++------ 4 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/SkinJsonSerializableExtensionsTest.cs create mode 100644 osu.Game.Rulesets.Karaoke/IO/Serialization/SkinJsonSerializableExtensions.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/SkinJsonSerializableExtensionsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/SkinJsonSerializableExtensionsTest.cs new file mode 100644 index 000000000..b426e099f --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/SkinJsonSerializableExtensionsTest.cs @@ -0,0 +1,13 @@ +// Copyright (c) andy840119 . 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 + { + } +} diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/SkinJsonSerializableExtensions.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/SkinJsonSerializableExtensions.cs new file mode 100644 index 000000000..6bddc7439 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/SkinJsonSerializableExtensions.cs @@ -0,0 +1,41 @@ +// Copyright (c) andy840119 . 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; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs index 5b25b0279..2a3f4cba4 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs @@ -7,10 +7,10 @@ using System.Linq; using Newtonsoft.Json; using osu.Framework.Bindables; -using osu.Framework.IO.Serialization; using osu.Framework.IO.Stores; using osu.Framework.Logging; using osu.Game.IO; +using osu.Game.Rulesets.Karaoke.IO.Serialization; using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Skinning.Elements; @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Karaoke.Skinning { /// - /// It's the skin for karaoke beatmap. + /// It's the skin that designed for reading the resource file and parse into the understandable format form beatmap skin. /// public class KaraokeBeatmapSkin : KaraokeSkin { @@ -34,7 +34,7 @@ public KaraokeBeatmapSkin(SkinInfo skin, IStorageResourceProvider? resources, IR { SkinInfo.PerformRead(s => { - var globalSetting = CreateJsonSerializerSettings(new KaraokeSkinElementConvertor(), new ShaderConvertor(), new Vector2Converter(), new ColourConvertor()); + var globalSetting = SkinJsonSerializableExtensions.CreateSkinElementGlobalSettings(); // we may want to move this to some kind of async operation in the future. foreach (ElementType skinnableTarget in Enum.GetValues(typeof(ElementType))) @@ -83,7 +83,7 @@ static string getFileNameByType(ElementType elementType) if (string.IsNullOrEmpty(jsonContent)) return; - var globalSetting = CreateJsonSerializerSettings(new KaraokeSkinGroupConvertor()); + var globalSetting = SkinJsonSerializableExtensions.CreateSkinGroupGlobalSettings(); var deserializedContent = JsonConvert.DeserializeObject(jsonContent, globalSetting); if (deserializedContent == null) @@ -107,7 +107,7 @@ static string getFileNameByType(ElementType elementType) if (string.IsNullOrEmpty(jsonContent)) return; - var globalSetting = CreateJsonSerializerSettings(new KaraokeSkinMappingRoleConvertor()); + var globalSetting = SkinJsonSerializableExtensions.CreateSkinMappingGlobalSettings(); var deserializedContent = JsonConvert.DeserializeObject(jsonContent, globalSetting); if (deserializedContent == null) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs index 536a90cfe..8d9f84c4e 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs @@ -10,13 +10,12 @@ using osu.Framework.Audio.Sample; using osu.Framework.Bindables; using osu.Framework.Graphics.Textures; -using osu.Framework.IO.Serialization; using osu.Framework.IO.Stores; using osu.Framework.Logging; using osu.Game.Audio; using osu.Game.Extensions; using osu.Game.IO; -using osu.Game.IO.Serialization; +using osu.Game.Rulesets.Karaoke.IO.Serialization; using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Skinning.Elements; @@ -27,8 +26,7 @@ namespace osu.Game.Rulesets.Karaoke.Skinning { /// - /// It's the skin for karaoke ruleset. - /// todo: should inherit ruleset skin if have. + /// It's the skin that designed for reading the resource file and parse into the understandable format. /// public class KaraokeSkin : Skin { @@ -59,7 +57,7 @@ public KaraokeSkin(SkinInfo skin, IStorageResourceProvider? resources, IResource if (string.IsNullOrEmpty(jsonContent)) return; - var globalSetting = CreateJsonSerializerSettings(new KaraokeSkinElementConvertor(), new ShaderConvertor(), new Vector2Converter(), new ColourConvertor()); + var globalSetting = SkinJsonSerializableExtensions.CreateSkinElementGlobalSettings(); var deserializedContent = JsonConvert.DeserializeObject(jsonContent, globalSetting); if (deserializedContent == null) @@ -76,14 +74,6 @@ public KaraokeSkin(SkinInfo skin, IStorageResourceProvider? resources, IResource }); } - protected JsonSerializerSettings CreateJsonSerializerSettings(params JsonConverter[] converters) - { - var globalSetting = JsonSerializableExtensions.CreateGlobalSettings(); - globalSetting.ContractResolver = new SnakeCaseKeyContractResolver(); - globalSetting.Converters.AddRange(converters); - return globalSetting; - } - protected string? GetElementStringContentFromSkinInfo(SkinInfo skinInfo, string filename) { // should get by file name if files is namespace resource store. From 2f92d076fedfc3ec886f907026ba0adc6804172d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 09:04:50 +0800 Subject: [PATCH 3/6] Remove the default karaoke skin. Because need to read the config from the karaoke skin. So use tricky way to fix the test case broken. Technically, should be better to use the skin transformer ;_; --- .../Editor/TestSceneLayoutToolTip.cs | 38 +++++++++++++++++- .../Screens/TestSceneKaraokeSkinEditor.cs | 39 +++++++++++++++++- .../Edit/Lyrics/LyricEditorSkin.cs | 2 +- .../Skinning/DefaultKaraokeSkin.cs | 40 ------------------- 4 files changed, 76 insertions(+), 43 deletions(-) delete mode 100644 osu.Game.Rulesets.Karaoke/Skinning/DefaultKaraokeSkin.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs index c683680ee..269c45339 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs @@ -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; @@ -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] @@ -62,5 +66,37 @@ private void setTooltip(string testName, Action callBack) toolTip.SetContent(singer); }); } + + /// + /// todo: it's a tricky way to create ruleset's own skin class. + /// should use generic skin like eventually. + /// + 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(); + } + } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/TestSceneKaraokeSkinEditor.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/TestSceneKaraokeSkinEditor.cs index 19238e7db..2f40b133d 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/TestSceneKaraokeSkinEditor.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/TestSceneKaraokeSkinEditor.cs @@ -1,11 +1,16 @@ // Copyright (c) andy840119 . 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; @@ -28,11 +33,43 @@ public class TestSceneKaraokeSkinEditor : ScreenTestScene [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); + + /// + /// todo: it's a tricky way to create ruleset's own skin class. + /// should use generic skin like eventually. + /// + 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(); + } + } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs index a073e70dd..4f1af5799 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorSkin.cs @@ -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) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/DefaultKaraokeSkin.cs b/osu.Game.Rulesets.Karaoke/Skinning/DefaultKaraokeSkin.cs deleted file mode 100644 index 41277eb76..000000000 --- a/osu.Game.Rulesets.Karaoke/Skinning/DefaultKaraokeSkin.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using JetBrains.Annotations; -using osu.Game.IO; -using osu.Game.Rulesets.Karaoke.Extensions; -using osu.Game.Rulesets.Karaoke.Skinning.Elements; -using osu.Game.Skinning; - -namespace osu.Game.Rulesets.Karaoke.Skinning -{ - public class DefaultKaraokeSkin : 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(DefaultKaraokeSkin).GetInvariantInstantiationInfo() - }; - - public DefaultKaraokeSkin(IStorageResourceProvider? resources) - : this(CreateInfo(), resources) - { - } - - [UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)] - public DefaultKaraokeSkin(SkinInfo skin, IStorageResourceProvider? resources) - : base(skin, resources) - { - DefaultElement[ElementType.LyricConfig] = LyricConfig.CreateDefault(); - DefaultElement[ElementType.LyricStyle] = LyricStyle.CreateDefault(); - DefaultElement[ElementType.NoteStyle] = NoteStyle.CreateDefault(); - } - } -} From 276c4a9b47247640f7c0d660683de7020650c922 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 10:36:19 +0800 Subject: [PATCH 4/6] Make the internal skin storage resource provider public. --- .../InternalSkinStorageResourceProvider.cs | 32 +++++++++++++++++++ .../Legacy/KaraokeLegacySkinTransformer.cs | 28 ---------------- 2 files changed, 32 insertions(+), 28 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Skinning/InternalSkinStorageResourceProvider.cs diff --git a/osu.Game.Rulesets.Karaoke/Skinning/InternalSkinStorageResourceProvider.cs b/osu.Game.Rulesets.Karaoke/Skinning/InternalSkinStorageResourceProvider.cs new file mode 100644 index 000000000..754ba7901 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Skinning/InternalSkinStorageResourceProvider.cs @@ -0,0 +1,32 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Audio; +using osu.Framework.Graphics.Rendering; +using osu.Framework.Graphics.Rendering.Dummy; +using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; +using osu.Game.Database; +using osu.Game.IO; + +namespace osu.Game.Rulesets.Karaoke.Skinning +{ + public class InternalSkinStorageResourceProvider : IStorageResourceProvider + { + public InternalSkinStorageResourceProvider(string skinName) + { + var store = new KaraokeRuleset().CreateResourceStore(); + Files = Resources = new NamespacedResourceStore(store, $"Skin/{skinName}"); + } + + public IRenderer Renderer => new DummyRenderer(); + + public AudioManager AudioManager => null; + public IResourceStore Files { get; } + public IResourceStore Resources { get; } + public RealmAccess RealmAccess => null; + public IResourceStore CreateTextureLoaderStore(IResourceStore underlyingStore) => null; + } +} diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs index ecf5976e2..803419ea6 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs @@ -3,16 +3,9 @@ using System; using System.ComponentModel; -using osu.Framework.Audio; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Rendering; -using osu.Framework.Graphics.Rendering.Dummy; -using osu.Framework.Graphics.Textures; -using osu.Framework.IO.Stores; using osu.Game.Beatmaps; -using osu.Game.Database; -using osu.Game.IO; using osu.Game.Rulesets.Karaoke.UI.HUD; using osu.Game.Rulesets.Scoring; using osu.Game.Skinning; @@ -102,26 +95,5 @@ public TempLegacySkin(SkinInfo skin) { } } - -#nullable disable - - private class InternalSkinStorageResourceProvider : IStorageResourceProvider - { - public InternalSkinStorageResourceProvider(string skinName) - { - var store = new KaraokeRuleset().CreateResourceStore(); - Files = Resources = new NamespacedResourceStore(store, $"Skin/{skinName}"); - } - - public IRenderer Renderer => new DummyRenderer(); - - public AudioManager AudioManager => null; - public IResourceStore Files { get; } - public IResourceStore Resources { get; } - public RealmAccess RealmAccess => null; - public IResourceStore CreateTextureLoaderStore(IResourceStore underlyingStore) => null; - } - -#nullable enable } } From c004c841cc14ab5c7f660ea381a036035d6c3dd9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 10:36:59 +0800 Subject: [PATCH 5/6] Add some skin transformers. --- osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs | 20 ++++++++++++++-- .../Argon/KaraokeArgonSkinTransformer.cs | 17 ++++++++++++++ .../Default/KaraokeDefaultSkinTransformer.cs | 23 +++++++++++++++++++ .../Legacy/KaraokeClassicSkinTransformer.cs | 16 +++++++++++++ .../KaraokeTrianglesSkinTransformer.cs | 17 ++++++++++++++ 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Skinning/Argon/KaraokeArgonSkinTransformer.cs create mode 100644 osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs create mode 100644 osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs create mode 100644 osu.Game.Rulesets.Karaoke/Skinning/Triangles/KaraokeTrianglesSkinTransformer.cs diff --git a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs index 41b3b6e1e..61519774e 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs @@ -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; @@ -193,8 +195,22 @@ public override IResourceStore 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(); diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Argon/KaraokeArgonSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Argon/KaraokeArgonSkinTransformer.cs new file mode 100644 index 000000000..6bed074f5 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Skinning/Argon/KaraokeArgonSkinTransformer.cs @@ -0,0 +1,17 @@ +// Copyright (c) andy840119 . 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) + { + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs new file mode 100644 index 000000000..a7cda0dd1 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Skinning/Default/KaraokeDefaultSkinTransformer.cs @@ -0,0 +1,23 @@ +// Copyright (c) andy840119 . 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? GetConfig(TLookup lookup) + => karaokeSkin.GetConfig(lookup); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs new file mode 100644 index 000000000..ba876fe50 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeClassicSkinTransformer.cs @@ -0,0 +1,16 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Beatmaps; +using osu.Game.Skinning; + +namespace osu.Game.Rulesets.Karaoke.Skinning.Legacy +{ + public class KaraokeClassicSkinTransformer : KaraokeLegacySkinTransformer + { + public KaraokeClassicSkinTransformer(ISkin source, IBeatmap beatmap) + : base(source, beatmap) + { + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Triangles/KaraokeTrianglesSkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Triangles/KaraokeTrianglesSkinTransformer.cs new file mode 100644 index 000000000..aded68f44 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Skinning/Triangles/KaraokeTrianglesSkinTransformer.cs @@ -0,0 +1,17 @@ +// Copyright (c) andy840119 . 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.Triangles +{ + public class KaraokeTrianglesSkinTransformer : KaraokeDefaultSkinTransformer + { + public KaraokeTrianglesSkinTransformer(ISkin skin, IBeatmap beatmap) + : base(skin, beatmap) + { + } + } +} From f00aa303708f6c49ee69d431a14cf08e35d1075b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 10 Oct 2022 10:48:09 +0800 Subject: [PATCH 6/6] Here's no need to read the skin from default skin. --- .../Skinning/Legacy/KaraokeLegacySkinTransformer.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs index 803419ea6..95dcd8f95 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Legacy/KaraokeLegacySkinTransformer.cs @@ -15,14 +15,14 @@ namespace osu.Game.Rulesets.Karaoke.Skinning.Legacy public class KaraokeLegacySkinTransformer : LegacySkinTransformer { private readonly Lazy isLegacySkin; - private readonly KaraokeBeatmapSkin defaultKaraokeSkin; + private readonly KaraokeBeatmapSkin karaokeSkin; public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) : base(source) { // we should get config by default karaoke skin. // if has resource or texture, then try to get from legacy skin. - defaultKaraokeSkin = new KaraokeBeatmapSkin(new SkinInfo(), new InternalSkinStorageResourceProvider("Default")); + karaokeSkin = new KaraokeBeatmapSkin(new SkinInfo(), new InternalSkinStorageResourceProvider("Default")); isLegacySkin = new Lazy(() => GetConfig(SkinConfiguration.LegacySetting.Version) != null); } @@ -82,10 +82,7 @@ public KaraokeLegacySkinTransformer(ISkin source, IBeatmap beatmap) } public override IBindable? GetConfig(TLookup lookup) - { - var config = defaultKaraokeSkin.GetConfig(lookup); - return config ?? base.GetConfig(lookup); - } + => karaokeSkin.GetConfig(lookup); // it's a temp class for just getting SkinnableTarget.MainHUDComponents private class TempLegacySkin : LegacySkin