Skip to content

Commit

Permalink
Merge pull request #1813 from andy840119/upgrade-package-to-the-latest
Browse files Browse the repository at this point in the history
Upgrade package to the latest.
  • Loading branch information
andy840119 authored Dec 27, 2022
2 parents 21be8ec + 48be664 commit 1a32c11
Show file tree
Hide file tree
Showing 32 changed files with 100 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void processTranslate(Beatmap beatmap, IEnumerable<string> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private IEnumerable<string> 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);
Expand Down Expand Up @@ -75,7 +75,7 @@ private IEnumerable<string> 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}";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
7 changes: 6 additions & 1 deletion osu.Game.Rulesets.Karaoke/Beatmaps/Metadatas/PageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,12 +31,16 @@ public PageInfo()
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
Debug.Assert(args.NewItems != null);

foreach (var c in args.NewItems.Cast<Page>())
c.TimeBindable.ValueChanged += timeValueChanged;
break;

case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var c in args.OldItems.Cast<Page>())
c.TimeBindable.ValueChanged -= timeValueChanged;
break;
Expand Down Expand Up @@ -85,7 +90,7 @@ void onPageChanged()

public PageInfo DeepClone()
{
var controlPointInfo = (PageInfo)Activator.CreateInstance(GetType());
var controlPointInfo = (PageInfo)Activator.CreateInstance(GetType())!;

return controlPointInfo;
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/Bindables/BindableCultureInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -46,6 +46,6 @@ public override void Parse(object? input)
protected override Bindable<CultureInfo?> CreateInstance() => new BindableCultureInfo();

public override string ToString(string format, IFormatProvider formatProvider)
=> CultureInfoUtils.GetLanguageDisplayText(Value);
=> Value != null ? CultureInfoUtils.GetSaveCultureInfoCode(Value) : string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class TrickyCompositeDrawableExtension
if (prop == null)
return null;

return (IReadOnlyList<Drawable>)prop.GetValue(compositeDrawable);
return (IReadOnlyList<Drawable>)prop.GetValue(compositeDrawable)!;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace osu.Game.Rulesets.Karaoke.IO.Serialization.Converters
{
public abstract class DictionaryConverter<TKey, TValue> : JsonConverter<IDictionary<TKey, TValue>>
public abstract class DictionaryConverter<TKey, TValue> : JsonConverter<IDictionary<TKey, TValue>> where TKey : notnull
{
public sealed override IDictionary<TKey, TValue> ReadJson(JsonReader reader, Type objectType, IDictionary<TKey, TValue>? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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 System.Diagnostics;
using System.Reflection;
using osu.Game.Rulesets.Karaoke.Skinning.Groups;

Expand All @@ -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;
}
}
}
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 System.Diagnostics;
using System.Reflection;
using osu.Game.Rulesets.Karaoke.Skinning.MappingRoles;

Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
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 System.Diagnostics;
using System.Reflection;
using osu.Game.Rulesets.Karaoke.Objects.Properties;

Expand All @@ -12,7 +13,9 @@ public class ReferenceLyricPropertyConfigConvertor : GenericTypeConvertor<IRefer
protected override Type GetTypeByName(string name)
{
var assembly = Assembly.GetExecutingAssembly();
return assembly.GetType($"osu.Game.Rulesets.Karaoke.Objects.Properties.{name}");
var type = assembly.GetType($"osu.Game.Rulesets.Karaoke.Objects.Properties.{name}");
Debug.Assert(type != null);
return type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ protected override Type GetTypeByName(string name)
// only get name from font
var assembly = AssemblyUtils.GetAssemblyByName("osu.Framework.KaraokeFont");
Debug.Assert(assembly != null);
return assembly.GetType($"osu.Framework.Graphics.Shaders.{name}");

var type = assembly.GetType($"osu.Framework.Graphics.Shaders.{name}");
Debug.Assert(type != null);
return type;
}
}
}
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 System.Diagnostics;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -47,6 +48,8 @@ protected override void PostProcessJObject(JObject jObject, ISinger value, JsonS
protected override Type GetTypeByName(string name)
{
var assembly = Assembly.GetExecutingAssembly();
return assembly.GetType($"osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas.{name}");
var type = assembly.GetType($"osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas.{name}");
Debug.Assert(type != null);
return type;
}
}
14 changes: 13 additions & 1 deletion osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeTag>())
c.Changed += invalidate;
break;

case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var c in args.OldItems.Cast<TimeTag>())
c.Changed -= invalidate;
break;
Expand All @@ -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<RubyTag>())
c.Changed += invalidate;
break;

case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var c in args.OldItems.Cast<RubyTag>())
c.Changed -= invalidate;
break;
Expand All @@ -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<RomajiTag>())
c.Changed += invalidate;
break;

case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var c in args.OldItems.Cast<RomajiTag>())
c.Changed -= invalidate;
break;
Expand Down Expand Up @@ -281,7 +293,7 @@ private void bindListValueChange<T>(ValueChangedEvent<Lyric?> e, Func<Lyric, IBi
triggerPropertyChanged();
}

void propertyChanged(object sender, NotifyCollectionChangedEventArgs _) => triggerPropertyChanged();
void propertyChanged(object? sender, NotifyCollectionChangedEventArgs _) => triggerPropertyChanged();

void triggerPropertyChanged()
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Objects/Tone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -148,5 +148,9 @@ private Popover createSelectionPopover()
}).ToList()
}
};

private partial class AutoGenerateButton : EditorSectionButton
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -20,7 +21,7 @@ public abstract partial class BindableBlueprintContainer<T> : BlueprintContainer
protected void RegisterBindable(BindableList<T> bindable)
{
if (bindableList != null)
throw new Exception();
throw new InvalidOperationException("Already have bindable.");

bindableList = bindable;

Expand All @@ -30,12 +31,16 @@ protected void RegisterBindable(BindableList<T> bindable)
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
Debug.Assert(args.NewItems != null);

foreach (var obj in args.NewItems.OfType<T>())
AddBlueprintFor(obj);

break;

case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var obj in args.OldItems.OfType<T>())
RemoveBlueprintFor(obj);

Expand Down
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.Collections.Specialized;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -83,12 +84,16 @@ public NoteEditor()
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
Debug.Assert(args.NewItems != null);

foreach (var obj in args.NewItems.OfType<Note>())
Playfield.Add(obj);

break;

case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var obj in args.OldItems.OfType<Note>())
Playfield.Remove(obj);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void initialSubModeChanged<TSubMode>() where TSubMode : Enum
{
var editModeState = getEditModeState<TSubMode>();
if (editModeState == null)
throw new NullReferenceException("Unknows sub mode.");
throw new ArgumentNullException();

editModeState.BindableEditMode.BindValueChanged(e =>
{
Expand Down Expand Up @@ -448,7 +448,7 @@ public void SwitchSubMode<TSubMode>(TSubMode subMode) where TSubMode : Enum
{
var editModeState = getEditModeState<TSubMode>();
if (editModeState == null)
throw new NullReferenceException("Unknows sub mode.");
throw new ArgumentNullException();

editModeState.ChangeEditMode(subMode);
}
Expand Down
Loading

0 comments on commit 1a32c11

Please sign in to comment.