Skip to content

Commit

Permalink
Remove some un-need null check.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 8, 2022
1 parent c807bd5 commit 42c0d12
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static TimeTagCaretPosition createCaretPosition(IEnumerable<Lyric> lyric
var lyric = lyrics.ElementAtOrDefault(lyricIndex);
var timeTag = timeTagIndex == not_exist_tag
? new TimeTag(new TextIndex(not_exist_tag))
: lyric?.TimeTags?.ElementAtOrDefault(timeTagIndex);
: lyric?.TimeTags.ElementAtOrDefault(timeTagIndex);

if (lyric == null || timeTag == null)
throw new ArgumentNullException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void setTooltip(string testName, Action<Lyric> callBack)
{
Text = "karaoke!"
};
callBack?.Invoke(singer);
callBack.Invoke(singer);
toolTip.SetContent(singer);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static Lyric ParseLyric(string? str)
TimeTags = new[]
{
new TimeTag(new TextIndex(0), startTime),
new TimeTag(new TextIndex((text?.Length ?? 0) - 1, TextIndex.IndexState.End), endTime)
new TimeTag(new TextIndex(text.Length - 1, TextIndex.IndexState.End), endTime)
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool IsScorable(this IBeatmap beatmap)

public static IList<CultureInfo> AvailableTranslates(this IBeatmap beatmap) => (beatmap as KaraokeBeatmap)?.AvailableTranslates ?? new List<CultureInfo>();

public static bool AnyTranslate(this IBeatmap beatmap) => beatmap?.AvailableTranslates().Any() ?? false;
public static bool AnyTranslate(this IBeatmap beatmap) => beatmap.AvailableTranslates().Any();

public static float PitchToScale(this IBeatmap beatmap, float pitch)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ private Dictionary<RubyTagInvalid, RubyTag[]> checkInvalidRubyTags(Lyric lyric)

// Checking out of range tags.
var outOfRangeTags = TextTagsUtils.FindOutOfRange(lyric.RubyTags, lyric.Text);
if (outOfRangeTags?.Length > 0)
if (outOfRangeTags.Length > 0)
result.Add(RubyTagInvalid.OutOfRange, outOfRangeTags);

// Checking overlapping.
var sorting = config.RomajiPositionSorting;
var overlappingTags = TextTagsUtils.FindOverlapping(lyric.RubyTags, sorting);
if (overlappingTags?.Length > 0)
if (overlappingTags.Length > 0)
result.Add(RubyTagInvalid.Overlapping, overlappingTags);

// check empty string.
var emptyTextTags = TextTagsUtils.FindEmptyText(lyric.RubyTags);
if (emptyTextTags?.Length > 0)
if (emptyTextTags.Length > 0)
result.Add(RubyTagInvalid.EmptyText, emptyTextTags);

return result;
Expand All @@ -72,18 +72,18 @@ private Dictionary<RomajiTagInvalid, RomajiTag[]> checkInvalidRomajiTags(Lyric l

// Checking out of range tags.
var outOfRangeTags = TextTagsUtils.FindOutOfRange(lyric.RomajiTags, lyric.Text);
if (outOfRangeTags?.Length > 0)
if (outOfRangeTags.Length > 0)
result.Add(RomajiTagInvalid.OutOfRange, outOfRangeTags);

// Checking overlapping.
var sorting = config.RomajiPositionSorting;
var overlappingTags = TextTagsUtils.FindOverlapping(lyric.RomajiTags, sorting);
if (overlappingTags?.Length > 0)
if (overlappingTags.Length > 0)
result.Add(RomajiTagInvalid.Overlapping, overlappingTags);

// check empty string.
var emptyTextTags = TextTagsUtils.FindEmptyText(lyric.RomajiTags);
if (emptyTextTags?.Length > 0)
if (emptyTextTags.Length > 0)
result.Add(RomajiTagInvalid.EmptyText, emptyTextTags);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Dictionary<TimeTagInvalid, TimeTag[]> checkInvalidTimeTags(Lyric lyric)

// todo : check out of range.
var outOfRangeTags = TimeTagsUtils.FindOutOfRange(lyric.TimeTags, lyric.Text);
if (outOfRangeTags?.Length > 0)
if (outOfRangeTags.Length > 0)
result.Add(TimeTagInvalid.OutOfRange, outOfRangeTags);

// Check overlapping.
Expand All @@ -79,7 +79,7 @@ private Dictionary<TimeTagInvalid, TimeTag[]> checkInvalidTimeTags(Lyric lyric)

// Check time-tag should have time.
var noTimeTimeTags = TimeTagsUtils.FindNoneTime(lyric.TimeTags);
if (noTimeTimeTags?.Length > 0)
if (noTimeTimeTags.Length > 0)
result.Add(TimeTagInvalid.EmptyTime, noTimeTimeTags);

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using osu.Framework.Localisation;
Expand All @@ -16,7 +15,7 @@ public class LanguageDetector : ILyricPropertyDetector<CultureInfo?>

public LanguageDetector(LanguageDetectorConfig config)
{
var targetLanguages = config?.AcceptLanguages?.Where(x => x != null).ToList() ?? new List<CultureInfo>();
var targetLanguages = config.AcceptLanguages.Where(x => x != null).ToList();

if (targetLanguages.Any())
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

watcher?.Dispose();
watcher.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void onIsHittingChanged(ValueChangedEvent<bool> isHitting)

private void applySingerStyle(ISkinSource skin, Note note)
{
var noteSkin = skin?.GetConfig<Note, NoteStyle>(note)?.Value;
var noteSkin = skin.GetConfig<Note, NoteStyle>(note)?.Value;
if (noteSkin == null)
return;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Utils/TextTagUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static Tuple<int, int> GetFixedIndex<T>(T textTag, string lyric) where T

public static Tuple<int, int> GetShiftingIndex<T>(T textTag, string lyric, int offset) where T : ITextTag
{
int lyricLength = lyric?.Length ?? 0;
int lyricLength = lyric.Length;
int newStartIndex = Math.Clamp(textTag.StartIndex + offset, 0, lyricLength);
int newEndIndex = Math.Clamp(textTag.EndIndex + offset, 0, lyricLength);
return new Tuple<int, int>(Math.Min(newStartIndex, newEndIndex), Math.Max(newStartIndex, newEndIndex));
Expand Down

0 comments on commit 42c0d12

Please sign in to comment.