Skip to content

Commit

Permalink
Make the dependencies as nullable and add the null check.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 14, 2022
1 parent d90ccd2 commit 89a9a80
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditorClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,26 @@ public class LyricEditorClipboard : Component, ILyricEditorClipboard
[Resolved, AllowNull]
private ITimeTagModeState timeTagModeState { get; set; }

[Resolved, AllowNull]
private ILyricsChangeHandler lyricsChangeHandler { get; set; }
[Resolved]
private ILyricsChangeHandler? lyricsChangeHandler { get; set; }

[Resolved, AllowNull]
private ILyricLanguageChangeHandler languageChangeHandler { get; set; }
[Resolved]
private ILyricLanguageChangeHandler? languageChangeHandler { get; set; }

[Resolved, AllowNull]
private ILyricRubyTagsChangeHandler lyricRubyTagsChangeHandler { get; set; }
[Resolved]
private ILyricRubyTagsChangeHandler? lyricRubyTagsChangeHandler { get; set; }

[Resolved, AllowNull]
private ILyricRomajiTagsChangeHandler lyricRomajiTagsChangeHandler { get; set; }
[Resolved]
private ILyricRomajiTagsChangeHandler? lyricRomajiTagsChangeHandler { get; set; }

[Resolved, AllowNull]
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; }
[Resolved]
private ILyricTimeTagsChangeHandler? lyricTimeTagsChangeHandler { get; set; }

[Resolved, AllowNull]
private ILyricSingerChangeHandler lyricSingerChangeHandler { get; set; }
[Resolved]
private ILyricSingerChangeHandler? lyricSingerChangeHandler { get; set; }

[Resolved, AllowNull]
private ISingersChangeHandler singersChangeHandler { get; set; }
[Resolved]
private ISingersChangeHandler? singersChangeHandler { get; set; }

private readonly IBindable<LyricEditorMode> bindableMode = new Bindable<LyricEditorMode>();

Expand Down Expand Up @@ -155,6 +155,9 @@ private bool performCut()
return false;

case TextingEditMode.Split:
if (lyricsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricsChangeHandler)}");

lyricsChangeHandler.Remove();
return true;

Expand All @@ -166,14 +169,17 @@ private bool performCut()
return false;

case LyricEditorMode.Language:
languageChangeHandler.SetLanguage(null);
languageChangeHandler?.SetLanguage(null);
return true;

case LyricEditorMode.EditRuby:
var rubies = editRubyModeState.SelectedItems;
if (!rubies.Any())
return false;

if (lyricRubyTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricRubyTagsChangeHandler)}");

lyricRubyTagsChangeHandler.RemoveRange(rubies);
return true;

Expand All @@ -182,6 +188,9 @@ private bool performCut()
if (!romajies.Any())
return false;

if (lyricRomajiTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricRomajiTagsChangeHandler)}");

lyricRomajiTagsChangeHandler.RemoveRange(romajies);
return true;

Expand All @@ -190,13 +199,19 @@ private bool performCut()
if (!timeTags.Any())
return false;

if (lyricTimeTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricTimeTagsChangeHandler)}");

lyricTimeTagsChangeHandler.RemoveRange(timeTags);
return true;

case LyricEditorMode.EditNote:
return false;

case LyricEditorMode.Singer:
if (lyricSingerChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricSingerChangeHandler)}");

lyricSingerChangeHandler.Clear();
return true;

Expand Down Expand Up @@ -298,6 +313,9 @@ private bool performPaste(Lyric lyric)
if (pasteLyric == null)
return false;

if (lyricsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricsChangeHandler)}");

lyricsChangeHandler.AddBelowToSelection(pasteLyric);
return true;

Expand All @@ -313,6 +331,9 @@ private bool performPaste(Lyric lyric)
if (pasteLanguage == null)
return false;

if (languageChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(languageChangeHandler)}");

languageChangeHandler.SetLanguage(pasteLanguage);
return true;

Expand All @@ -321,6 +342,9 @@ private bool performPaste(Lyric lyric)
if (pasteRubies == null)
return false;

if (lyricRubyTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricRubyTagsChangeHandler)}");

lyricRubyTagsChangeHandler.AddRange(pasteRubies);
return true;

Expand All @@ -329,6 +353,9 @@ private bool performPaste(Lyric lyric)
if (pasteRomajies == null)
return false;

if (lyricRomajiTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricRomajiTagsChangeHandler)}");

lyricRomajiTagsChangeHandler.AddRange(pasteRomajies);
return true;

Expand All @@ -337,6 +364,9 @@ private bool performPaste(Lyric lyric)
if (pasteTimeTags == null)
return false;

if (lyricTimeTagsChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricTimeTagsChangeHandler)}");

lyricTimeTagsChangeHandler.AddRange(pasteTimeTags);
return true;

Expand All @@ -348,6 +378,9 @@ private bool performPaste(Lyric lyric)
if (pasteSingerIds == null)
return false;

if (lyricSingerChangeHandler == null)
throw new NullDependencyException($"Missing {nameof(lyricSingerChangeHandler)}");

var singers = getMatchedSinges(pasteSingerIds);
lyricSingerChangeHandler.AddRange(singers);
return true;
Expand All @@ -358,7 +391,9 @@ private bool performPaste(Lyric lyric)
}

private IEnumerable<Singer> getMatchedSinges(IEnumerable<int> singerIds)
=> singersChangeHandler.Singers.Where(x => singerIds.Contains(x.ID));
{
return singersChangeHandler == null ? throw new NullDependencyException($"Missing {nameof(singersChangeHandler)}") : singersChangeHandler.Singers.Where(x => singerIds.Contains(x.ID));
}

private void copyObjectToClipboard<T>(T obj)
{
Expand Down

0 comments on commit 89a9a80

Please sign in to comment.