From e03bbcb2f8339106ae54ec0520251d3848e8d92b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 22:10:52 +0800 Subject: [PATCH 01/12] Upgrade the package to the .net6 --- osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index 798570604..ae51fd65a 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -1,6 +1,6 @@  - netstandard2.1 + net6.0 osu.Game.Rulesets.Karaoke Library AnyCPU From d7288c285e37d6875b72f5f5647f0359df0116d8 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 22:27:49 +0800 Subject: [PATCH 02/12] Should add the null check for the new and old items. --- .../Beatmaps/Metadatas/PageInfo.cs | 5 +++++ osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs | 12 ++++++++++++ .../Beatmaps/Lyrics/BindableBlueprintContainer.cs | 5 +++++ .../Lyrics/Compose/BottomEditor/Notes/NoteEditor.cs | 5 +++++ .../Edit/Beatmaps/Pages/Settings/PagesSection.cs | 5 +++++ osu.Game.Rulesets.Karaoke/Utils/BindablesUtils.cs | 2 +- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs index 3456e5ab9..039d8bfd4 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; +using System.Diagnostics; using System.Linq; using Newtonsoft.Json; using osu.Framework.Bindables; @@ -30,12 +31,16 @@ public PageInfo() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var c in args.NewItems.Cast()) c.TimeBindable.ValueChanged += timeValueChanged; break; case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var c in args.OldItems.Cast()) c.TimeBindable.ValueChanged -= timeValueChanged; break; diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs index 66e0f33a8..cd912b8be 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs @@ -24,12 +24,16 @@ private void initInternalBindingEvent() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var c in args.NewItems.Cast()) c.Changed += invalidate; break; case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var c in args.OldItems.Cast()) c.Changed -= invalidate; break; @@ -50,12 +54,16 @@ private void initInternalBindingEvent() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var c in args.NewItems.Cast()) c.Changed += invalidate; break; case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var c in args.OldItems.Cast()) c.Changed -= invalidate; break; @@ -69,12 +77,16 @@ private void initInternalBindingEvent() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var c in args.NewItems.Cast()) c.Changed += invalidate; break; case NotifyCollectionChangedAction.Reset: case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var c in args.OldItems.Cast()) c.Changed -= invalidate; break; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs index 3b24d9221..95dc3c267 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Specialized; +using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -30,12 +31,16 @@ protected void RegisterBindable(BindableList bindable) switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var obj in args.NewItems.OfType()) AddBlueprintFor(obj); break; case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var obj in args.OldItems.OfType()) RemoveBlueprintFor(obj); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/BottomEditor/Notes/NoteEditor.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/BottomEditor/Notes/NoteEditor.cs index 0975313d5..c3fff33cc 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/BottomEditor/Notes/NoteEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/BottomEditor/Notes/NoteEditor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Specialized; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using osu.Framework.Allocation; @@ -83,12 +84,16 @@ public NoteEditor() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var obj in args.NewItems.OfType()) Playfield.Add(obj); break; case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var obj in args.OldItems.OfType()) Playfield.Remove(obj); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PagesSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PagesSection.cs index 9b9e738ab..2183cdba6 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PagesSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PagesSection.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Specialized; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using osu.Framework.Allocation; @@ -43,6 +44,8 @@ public PagesSection() switch (args.Action) { case NotifyCollectionChangedAction.Add: + Debug.Assert(args.NewItems != null); + foreach (var obj in args.NewItems.OfType()) { Add(new LabelledPage(obj) @@ -54,6 +57,8 @@ public PagesSection() break; case NotifyCollectionChangedAction.Remove: + Debug.Assert(args.OldItems != null); + foreach (var obj in args.OldItems.OfType()) { var drawable = Children.OfType().FirstOrDefault(x => x.Page == obj); diff --git a/osu.Game.Rulesets.Karaoke/Utils/BindablesUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/BindablesUtils.cs index c743d4073..d0f17a2fb 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/BindablesUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/BindablesUtils.cs @@ -34,7 +34,7 @@ public static void OnyWaySync(BindableList firstBindableList, Bindab if (oldItems != null && oldItems.Count > 0) { // remove objects from second list if exist items has been removed. - secondBindableList.RemoveAll(x => args.OldItems.Contains(x)); + secondBindableList.RemoveAll(x => oldItems.Contains(x)); } }; } From 8d35b6a6eff0b112e98d8224ef045e7b3ff67b7b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 22:41:29 +0800 Subject: [PATCH 03/12] Add the nullable check. --- .../Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs | 2 +- osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs | 2 +- osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs | 2 +- osu.Game.Rulesets.Karaoke/Objects/Tone.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs index 7c75263c2..c592a5e10 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs @@ -75,7 +75,7 @@ private IEnumerable encodeTranslate(Beatmap output) { foreach (var lyric in lyrics) { - string translateString = lyric.Translates.TryGetValue(translate, out string value) ? value : string.Empty; + string translateString = lyric.Translates.TryGetValue(translate, out string? value) ? value : string.Empty; yield return $"@tr[{translate.Name}]={translateString}"; } } diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs index dbcbb53dd..5682820c0 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs @@ -27,7 +27,7 @@ public Page DeepClone() }; } - public int CompareTo(Page other) => Time.CompareTo(other.Time); + public int CompareTo(Page? other) => Time.CompareTo(other?.Time); public override int GetHashCode() => Time.GetHashCode(); } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs index cd912b8be..0fd0fd5c9 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs @@ -293,7 +293,7 @@ private void bindListValueChange(ValueChangedEvent e, Func triggerPropertyChanged(); + void propertyChanged(object? sender, NotifyCollectionChangedEventArgs _) => triggerPropertyChanged(); void triggerPropertyChanged() { diff --git a/osu.Game.Rulesets.Karaoke/Objects/Tone.cs b/osu.Game.Rulesets.Karaoke/Objects/Tone.cs index 6c30a4ebb..9b50e6856 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Tone.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Tone.cs @@ -49,7 +49,7 @@ public int CompareTo(int other) public bool Equals(int other) => Scale == other && Half == false; - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj switch { From 17b908ab6ed86335e3334ca90d67a235aa77466a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 22:55:08 +0800 Subject: [PATCH 04/12] Should add the null check in here. --- .../IO/Serialization/Converters/KaraokeSkinGroupConvertor.cs | 5 ++++- .../Converters/KaraokeSkinMappingRoleConvertor.cs | 5 ++++- .../Converters/ReferenceLyricPropertyConfigConvertor.cs | 5 ++++- .../IO/Serialization/Converters/ShaderConvertor.cs | 5 ++++- .../IO/Serialization/Converters/SingerConvertor.cs | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinGroupConvertor.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinGroupConvertor.cs index 973851785..daaccc84f 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinGroupConvertor.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinGroupConvertor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Reflection; using osu.Game.Rulesets.Karaoke.Skinning.Groups; @@ -13,7 +14,9 @@ protected override Type GetTypeByName(string name) { // only get name from font var assembly = Assembly.GetExecutingAssembly(); - return assembly.GetType($"osu.Game.Rulesets.Karaoke.Skinning.Groups.{name}"); + var type = assembly.GetType($"osu.Game.Rulesets.Karaoke.Skinning.Groups.{name}"); + Debug.Assert(type != null); + return type; } } } diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertor.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertor.cs index 23fde8b50..64d5cc450 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertor.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/KaraokeSkinMappingRoleConvertor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Reflection; using osu.Game.Rulesets.Karaoke.Skinning.MappingRoles; @@ -13,7 +14,9 @@ protected override Type GetTypeByName(string name) { // only get name from font var assembly = Assembly.GetExecutingAssembly(); - return assembly.GetType($"osu.Game.Rulesets.Karaoke.Skinning.MappingRoles.{name}"); + var type = assembly.GetType($"osu.Game.Rulesets.Karaoke.Skinning.MappingRoles.{name}"); + Debug.Assert(type != null); + return type; } } } diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/ReferenceLyricPropertyConfigConvertor.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/ReferenceLyricPropertyConfigConvertor.cs index 09676bb2c..921339aab 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/ReferenceLyricPropertyConfigConvertor.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/ReferenceLyricPropertyConfigConvertor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Reflection; using osu.Game.Rulesets.Karaoke.Objects.Properties; @@ -12,7 +13,9 @@ public class ReferenceLyricPropertyConfigConvertor : GenericTypeConvertor Date: Mon, 26 Dec 2022 23:01:33 +0800 Subject: [PATCH 05/12] Some of the type should be be nullable. --- osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs | 2 +- .../Extensions/TrickyCompositeDrawableExtension.cs | 2 +- .../IO/Serialization/Converters/GenericTypeConvertor.cs | 2 +- .../IO/Serialization/Converters/LyricConvertor.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs index 039d8bfd4..eab58a480 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs @@ -90,7 +90,7 @@ void onPageChanged() public PageInfo DeepClone() { - var controlPointInfo = (PageInfo)Activator.CreateInstance(GetType()); + var controlPointInfo = (PageInfo)Activator.CreateInstance(GetType())!; return controlPointInfo; } diff --git a/osu.Game.Rulesets.Karaoke/Extensions/TrickyCompositeDrawableExtension.cs b/osu.Game.Rulesets.Karaoke/Extensions/TrickyCompositeDrawableExtension.cs index e1a6abf26..c00e9b52f 100644 --- a/osu.Game.Rulesets.Karaoke/Extensions/TrickyCompositeDrawableExtension.cs +++ b/osu.Game.Rulesets.Karaoke/Extensions/TrickyCompositeDrawableExtension.cs @@ -24,7 +24,7 @@ public static class TrickyCompositeDrawableExtension if (prop == null) return null; - return (IReadOnlyList)prop.GetValue(compositeDrawable); + return (IReadOnlyList)prop.GetValue(compositeDrawable)!; } } } diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/GenericTypeConvertor.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/GenericTypeConvertor.cs index 5d29de9cf..611f0108f 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/GenericTypeConvertor.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/GenericTypeConvertor.cs @@ -24,7 +24,7 @@ public sealed override TType ReadJson(JsonReader reader, Type objectType, TType? var newReader = jObject.CreateReader(); - var instance = (TType)Activator.CreateInstance(type); + var instance = (TType)Activator.CreateInstance(type)!; serializer.Populate(newReader, instance); PostProcessValue(instance, jObject, serializer); return instance; diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/LyricConvertor.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/LyricConvertor.cs index 8d2a88b7d..6f8f31105 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/LyricConvertor.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/LyricConvertor.cs @@ -21,7 +21,7 @@ public override Lyric ReadJson(JsonReader reader, Type objectType, Lyric? existi var newReader = jObject.CreateReader(); - var instance = (Lyric)Activator.CreateInstance(objectType); + var instance = (Lyric)Activator.CreateInstance(objectType)!; serializer.Populate(newReader, instance); return instance; } From b5cd56f582b5a810c301bebbb5678e49a7a47a30 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 23:03:01 +0800 Subject: [PATCH 06/12] Fix wrong exception usage. Some of the exception is not recommend in the .net6 project. --- .../Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs | 2 +- .../Beatmaps/KaraokeBeatmapResourcesProvider.cs | 2 +- .../Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs | 2 +- .../Screens/Edit/Beatmaps/Lyrics/LyricEditor.cs | 4 ++-- .../Edit/Beatmaps/Lyrics/LyricList/Rows/Info/InfoControl.cs | 2 +- .../Lyrics/Settings/Reference/ReferenceLyricConfigSection.cs | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs index c592a5e10..4123dda28 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapEncoder.cs @@ -32,7 +32,7 @@ private IEnumerable encodeNote(Beatmap output) { var lyric = g.Key; if (lyric == null) - throw new NullReferenceException(); + throw new ArgumentNullException(); // Get note group var noteGroup = g.ToList().GroupBy(n => n.ReferenceTimeTagIndex); diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapResourcesProvider.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapResourcesProvider.cs index 35fcd2a6e..508e87351 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapResourcesProvider.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/KaraokeBeatmapResourcesProvider.cs @@ -45,7 +45,7 @@ private IBeatmapResourceProvider getBeatmapResourceProvider() // todo : use better way to get the resource provider. var prop = typeof(BeatmapManager).GetField("workingBeatmapCache", BindingFlags.Instance | BindingFlags.NonPublic); if (prop == null) - throw new NullReferenceException(); + throw new ArgumentNullException(); return prop.GetValue(beatmapManager) as WorkingBeatmapCache; } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs index 95dc3c267..cdf30b89d 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/BindableBlueprintContainer.cs @@ -21,7 +21,7 @@ public abstract partial class BindableBlueprintContainer : BlueprintContainer protected void RegisterBindable(BindableList bindable) { if (bindableList != null) - throw new Exception(); + throw new InvalidOperationException("Already have bindable."); bindableList = bindable; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditor.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditor.cs index 224cb262b..84c6e871a 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditor.cs @@ -184,7 +184,7 @@ private void initialSubModeChanged() where TSubMode : Enum { var editModeState = getEditModeState(); if (editModeState == null) - throw new NullReferenceException("Unknows sub mode."); + throw new ArgumentNullException(); editModeState.BindableEditMode.BindValueChanged(e => { @@ -448,7 +448,7 @@ public void SwitchSubMode(TSubMode subMode) where TSubMode : Enum { var editModeState = getEditModeState(); if (editModeState == null) - throw new NullReferenceException("Unknows sub mode."); + throw new ArgumentNullException(); editModeState.ChangeEditMode(subMode); } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricList/Rows/Info/InfoControl.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricList/Rows/Info/InfoControl.cs index 7ab9f5130..caaed19e0 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricList/Rows/Info/InfoControl.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricList/Rows/Info/InfoControl.cs @@ -191,7 +191,7 @@ private void initializeBadge(LyricEditorMode mode, Enum? subMode) case LyricEditorMode.EditTimeTag: if (subMode is not TimeTagEditMode timeTagEditMode) - throw new NullReferenceException(); + throw new ArgumentNullException(); return createTimeTagModeSubInfo(timeTagEditMode, Lyric); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricConfigSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricConfigSection.cs index b34accbc5..3f61160ec 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricConfigSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricConfigSection.cs @@ -92,7 +92,7 @@ public ReferenceLyricConfigSection() break; default: - throw new IndexOutOfRangeException(); + throw new InvalidOperationException(); } }); @@ -166,7 +166,7 @@ private void onConfigChanged() break; default: - throw new IndexOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(config), config, "unknown config."); } isConfigChanging = false; From dd8e3ee7f443c39eb74c5a8d0e6f1ca6b40df54c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 23:03:29 +0800 Subject: [PATCH 07/12] Fix other nullable case. --- .../Beatmaps/Formats/KaraokeLegacyBeatmapDecoder.cs | 2 +- .../ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs | 3 ++- .../States/Modes/ModeStateWithBlueprintContainer.cs | 8 +++++++- osu.Game.Rulesets.Karaoke/Utils/AssemblyUtils.cs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapDecoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapDecoder.cs index 9bad8a457..adf8a1355 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapDecoder.cs +++ b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/KaraokeLegacyBeatmapDecoder.cs @@ -230,7 +230,7 @@ private void processTranslate(Beatmap beatmap, IEnumerable translateLine var translations = translateLines.Select(translate => new { key = translate.Split('=').FirstOrDefault()?.Split('[').LastOrDefault()?.Split(']').FirstOrDefault(), - value = translate.Split('=').LastOrDefault() + value = translate.Split('=').LastOrDefault() ?? string.Empty }).GroupBy(x => x.key, y => y.value).ToList(); foreach (var translation in translations) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs index aeaaef4f3..1023dfc4f 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs @@ -149,7 +149,8 @@ public void RemoveByPosition(TextIndex index) return; var removedTimeTag = matchedTimeTags.OrderBy(x => x.Time).FirstOrDefault(); - lyric.TimeTags.Remove(removedTimeTag); + if (removedTimeTag != null) + lyric.TimeTags.Remove(removedTimeTag); }); } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/States/Modes/ModeStateWithBlueprintContainer.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/States/Modes/ModeStateWithBlueprintContainer.cs index 1619669b8..17d4cbc50 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/States/Modes/ModeStateWithBlueprintContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/States/Modes/ModeStateWithBlueprintContainer.cs @@ -64,7 +64,13 @@ protected virtual void TriggerDisableStateChanged() { case CaretGenerateType.Action: if (SelectFirstProperty(lyric)) - SelectedItems.Add(SelectableProperties(lyric).FirstOrDefault()); + { + var firstItem = SelectableProperties(lyric).FirstOrDefault(); + + if (firstItem != null) + SelectedItems.Add(firstItem); + } + break; case CaretGenerateType.TargetLyric: diff --git a/osu.Game.Rulesets.Karaoke/Utils/AssemblyUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/AssemblyUtils.cs index f7ec16875..cc1c96875 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/AssemblyUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/AssemblyUtils.cs @@ -17,7 +17,7 @@ public static class AssemblyUtils return defaultAssembly; // Note: because multiple assembly might be wrapped into single one by ILRepack, so should find by main dll again if not found. - return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.Contains("osu.Game.Rulesets.Karaoke")); + return AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName?.Contains("osu.Game.Rulesets.Karaoke") ?? false); } } } From e97e83599f2d8287cbe90bfd31d102e60c6a1ad0 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 23:03:39 +0800 Subject: [PATCH 08/12] Key should be not nullable. --- .../IO/Serialization/Converters/DictionaryConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/DictionaryConverter.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/DictionaryConverter.cs index 1263a8ce0..b412afb38 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/DictionaryConverter.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/DictionaryConverter.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.IO.Serialization.Converters { - public abstract class DictionaryConverter : JsonConverter> + public abstract class DictionaryConverter : JsonConverter> where TKey : notnull { public sealed override IDictionary ReadJson(JsonReader reader, Type objectType, IDictionary? existingValue, bool hasExistingValue, JsonSerializer serializer) { From 9c1937c4407d2154868facfa39af49920137c9e5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 23:35:31 +0800 Subject: [PATCH 09/12] Upgrade the osu.game to the latest and fix the api broken. --- .../Edit/Beatmaps/Singers/Rows/Components/SingerAvatar.cs | 2 +- .../Screens/Edit/Import/Lyrics/DragFile/DragFileStepScreen.cs | 2 +- osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Singers/Rows/Components/SingerAvatar.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Singers/Rows/Components/SingerAvatar.cs index 97cd6f49b..b7bf059f7 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Singers/Rows/Components/SingerAvatar.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Singers/Rows/Components/SingerAvatar.cs @@ -86,7 +86,7 @@ Task ICanAcceptFiles.Import(params string[] paths) return Task.CompletedTask; } - Task ICanAcceptFiles.Import(params ImportTask[] tasks) => throw new NotImplementedException(); + Task ICanAcceptFiles.Import(ImportTask[] tasks, ImportParameters parameters) => throw new NotImplementedException(); protected override void Dispose(bool isDisposing) { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/DragFile/DragFileStepScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/DragFile/DragFileStepScreen.cs index 2566eb8f1..d73d6532e 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/DragFile/DragFileStepScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/DragFile/DragFileStepScreen.cs @@ -59,7 +59,7 @@ public Task Import(params string[] paths) return Task.CompletedTask; } - public Task Import(params ImportTask[] tasks) + public Task Import(ImportTask[] tasks, ImportParameters parameters = default) { // todo : wail until really implement needed. throw new NotImplementedException("Report to https://github.com/karaoke-dev/karaoke and i will implement it."); diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index ae51fd65a..39f088a1e 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -18,7 +18,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + From 248d5b0f01b22c978506fe477fbf8ea50258110d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 26 Dec 2022 23:39:56 +0800 Subject: [PATCH 10/12] Make the code happy because osu button is abstract now. --- .../Screens/Edit/AutoGenerateSubsection.cs | 6 +++++- .../Screens/Edit/Import/Lyrics/LyricImporterStepScreen.cs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSubsection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSubsection.cs index db86bfe0b..b81d541ec 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSubsection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/AutoGenerateSubsection.cs @@ -132,7 +132,7 @@ private Popover createSelectionPopover() Children = AvailableSettings.Select(x => { string name = GetDisplayName(x); - return new OsuButton + return new AutoGenerateButton { Text = name, Width = 150, @@ -148,5 +148,9 @@ private Popover createSelectionPopover() }).ToList() } }; + + private partial class AutoGenerateButton : EditorSectionButton + { + } } } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/LyricImporterStepScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/LyricImporterStepScreen.cs index 9e4e2b6db..661e088f7 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/LyricImporterStepScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/LyricImporterStepScreen.cs @@ -42,7 +42,7 @@ protected LyricImporterStepScreen() InternalChildren = new Drawable[] { - new OsuButton + new LyricImporterStepButton { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -89,5 +89,9 @@ public virtual void ConfirmRollBackFromStep(ILyricImporterStepScreen fromScreen, } public override string ToString() => Title; + + private partial class LyricImporterStepButton : OsuButton + { + } } } From 76d9193bfcf2f2bbad582b50e8529abad4b56770 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 27 Dec 2022 20:32:06 +0800 Subject: [PATCH 11/12] Upgrade remaining package to make the project happy. --- osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index 39f088a1e..78cabbe4b 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -12,8 +12,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive From 48be6646a6f304f54834a3454a8a509f4e35e35b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 27 Dec 2022 21:38:07 +0800 Subject: [PATCH 12/12] Fix the test case broken. It's caused due to `RulesetConfigManager` get the data by .ToString(CultureInfo.InvariantCulture) in the bindbable, not by ToString(). See: https://github.com/ppy/osu/issues/21611 --- osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs b/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs index da9a1a5a5..4be103e91 100644 --- a/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs @@ -26,11 +26,11 @@ public override void Parse(object? input) switch (input) { case string str: - Value = new CultureInfo(str); + Value = CultureInfoUtils.CreateLoadCultureInfoByCode(str); break; case int lcid: - Value = new CultureInfo(lcid); + Value = CultureInfoUtils.CreateLoadCultureInfoById(lcid); break; case CultureInfo cultureInfo: @@ -46,6 +46,6 @@ public override void Parse(object? input) protected override Bindable CreateInstance() => new BindableCultureInfo(); public override string ToString(string format, IFormatProvider formatProvider) - => CultureInfoUtils.GetLanguageDisplayText(Value); + => Value != null ? CultureInfoUtils.GetSaveCultureInfoCode(Value) : string.Empty; } }