Skip to content

Commit

Permalink
Merge pull request #830 from andy840119/clean-up-code
Browse files Browse the repository at this point in the history
Clean up code
  • Loading branch information
andy840119 authored Aug 29, 2021
2 parents 5b6fa31 + 43b7bd1 commit 5909605
Show file tree
Hide file tree
Showing 56 changed files with 145 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseGlyphStoreTest<TGlyphStore> where TGlyphStore : IGlyph
protected void OneTimeSetUp()
{
// create and load glyph store.
var fontResourceStore = new NamespacedResourceStore<byte[]>(TestResources.GetStore(), $"Resources.Testing.Fonts.Fnt.OpenSans");
var fontResourceStore = new NamespacedResourceStore<byte[]>(TestResources.GetStore(), "Resources.Testing.Fonts.Fnt.OpenSans");
GlyphStore = new GlyphStore(fontResourceStore, FontName);
GlyphStore.LoadFontAsync().Wait();

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

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -64,22 +65,32 @@ public void ShowWithNoFetch()

Schedule(() =>
{
var columns = colourName.Select(c => new TitleTableColumn(c)).OfType<TableColumn>().ToArray();
var content = providers.Select(provider =>
{
if (provider == null)
throw new ArgumentNullException(nameof(provider));

return colourName.Select(c =>
{
var value = provider.GetType().GetProperty(c)?.GetValue(provider);
if (value == null)
throw new ArgumentNullException(nameof(value));

var colour = (Color4)value;
return new PreviewColourDrawable(colour);
}).OfType<Drawable>();
}).To2DArray();

Child = new OsuScrollContainer(Direction.Horizontal)
{
RelativeSizeAxes = Axes.Both,
Child = new TableContainer
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Columns = colourName.Select(c => new TitleTableColumn(c)).ToArray(),
Content = providers.Select(p =>
{
return colourName.Select(c =>
{
var colour = (Color4)p.GetType().GetProperty(c).GetValue(p);
return new PreviewColourDrawable(colour);
});
}).To2DArray(),
Columns = columns,
Content = content,
}
};
});
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LrcDecoder : Decoder<Beatmap>
public static void Register()
{
// Lrc decoder looks like [mm:ss:__]
AddDecoder<Beatmap>("[", m => new LrcDecoder());
AddDecoder<Beatmap>("[", _ => new LrcDecoder());
}

protected override void ParseStreamInto(LineBufferedReader stream, Beatmap output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NicoKaraDecoder : Decoder<KaraokeSkin>
{
public static void Register()
{
AddDecoder<KaraokeSkin>("<?xml version=", m => new NicoKaraDecoder());
AddDecoder<KaraokeSkin>("<?xml version=", _ => new NicoKaraDecoder());
}

protected override void ParseStreamInto(LineBufferedReader stream, KaraokeSkin output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public override double Calculate(Dictionary<string, double> categoryDifficulty =

IEnumerable<Mod> scoreIncreaseMods = Ruleset.GetModsFor(ModType.DifficultyIncrease);

double scoreMultiplier = 1.0;
foreach (var m in mods.Where(m => !scoreIncreaseMods.Contains(m)))
scoreMultiplier *= m.ScoreMultiplier;
double scoreMultiplier = mods.Where(m => !scoreIncreaseMods.Contains(m))
.Aggregate(1.0, (current, m) => current * m.ScoreMultiplier);

// Scale score up, so it's comparable to other keymods
scaledScore *= 1.0 / scoreMultiplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LyricLockContextMenu(LyricManager manager, List<Lyric> lyrics, string nam
Items = EnumUtils.GetValues<LockState>().Select(l => new OsuMenuItem(l.ToString(), anyLyricInLockState(l) ? MenuItemType.Highlighted : MenuItemType.Standard, () =>
{
// change all selected lyric state.
lyrics.ForEach(lyric => manager.LockLyrics(lyrics, l));
manager.LockLyrics(lyrics, l);
})).ToList();

bool anyLyricInLockState(LockState lockState) => lyrics.Any(lyric => lyric.Lock == lockState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public AutoFocusToEditLyricMenu(KaraokeRulesetLyricEditorConfigManager config, s
config.BindWith(KaraokeRulesetLyricEditorSetting.AutoFocusToEditLyricSkipRows, bindableAutoFocusToEditLyricSkipRows);

// mark disable as selected option.
bindableAutoFocusToEditLyric.BindValueChanged(e =>
bindableAutoFocusToEditLyric.BindValueChanged(_ =>
{
updateSelectionState();
}, true);

// mark line as selected option.
bindableAutoFocusToEditLyricSkipRows.BindValueChanged(e =>
bindableAutoFocusToEditLyricSkipRows.BindValueChanged(_ =>
{
updateSelectionState();
}, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void TimeTagLogic(Lyric lyric, List<TimeTag> timeTags)

// add new time tags created from ruby
var rubyTags = generateTimeTagByText(ruby.Text);
var shiftingTimeTags = rubyTags.Select((x, v) => new TimeTag(new TextIndex(ruby.StartIndex, x.Index.State), x.Time));
var shiftingTimeTags = rubyTags.Select((x, _) => new TimeTag(new TextIndex(ruby.StartIndex, x.Index.State), x.Time));
timeTags.AddRange(shiftingTimeTags);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override TopNavigation CreateNavigation()
=> new AssignLanguageNavigation(this);

protected override Drawable CreateContent()
=> base.CreateContent().With(x =>
=> base.CreateContent().With(_ =>
{
LyricEditor.Mode = LyricEditorMode.Language;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private PopupDialog createUnknownExceptionDialog()
};

private PopupDialog createCompleteDialog()
=> new OkPopupDialog(ok => { Complete(); })
=> new OkPopupDialog(_ => { Complete(); })
{
Icon = FontAwesome.Regular.CheckCircle,
HeaderText = @"Import success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override TopNavigation CreateNavigation()
=> new EditLyricNavigation(this);

protected override Drawable CreateContent()
=> base.CreateContent().With(x =>
=> base.CreateContent().With(_ =>
{
LyricEditor.Mode = LyricEditorMode.Manage;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override TopNavigation CreateNavigation()
=> new GenerateRubyNavigation(this);

protected override Drawable CreateContent()
=> base.CreateContent().With(x =>
=> base.CreateContent().With(_ =>
{
LyricEditor.Mode = LyricEditorMode.EditRomaji;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override TopNavigation CreateNavigation()
=> new GenerateTimeTagNavigation(this);

protected override Drawable CreateContent()
=> base.CreateContent().With(x =>
=> base.CreateContent().With(_ =>
{
LyricEditor.Mode = LyricEditorMode.CreateTimeTag;
});
Expand Down
14 changes: 7 additions & 7 deletions osu.Game.Rulesets.Karaoke/Edit/KaraokeSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ private void performColumnMovement(Tone lastTone, MoveSelectionEvent<HitObject>
var delta = centerPosition.Y - lastCenterPosition;

// get delta tone.
var deltaTone = new Tone();
const float trigger_height = ScrollingNotePlayfield.COLUMN_SPACING + DefaultColumnBackground.COLUMN_HEIGHT;
var deltaTone = delta switch
{
> trigger_height => -new Tone { Half = true },
< 0 => new Tone { Half = true },
_ => default
};

if (delta > trigger_height)
deltaTone = -new Tone { Half = true };
else if (delta < 0)
deltaTone = new Tone { Half = true };

if (deltaTone == 0)
if (deltaTone == default(Tone))
return;

foreach (var note in EditorBeatmap.SelectedHitObjects.OfType<Note>())
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/ApplySelectingArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void load(OsuColour colours, LyricSelectionState lyricSelectionState)
// get bindable and update bindable if select or not select all.
selectedLyrics = lyricSelectionState.SelectedLyrics.GetBoundCopy();

selectedLyrics.BindCollectionChanged((a, b) =>
selectedLyrics.BindCollectionChanged((_, _) =>
{
var selectAny = selectedLyrics.Any();
applyButton.Enabled.Value = selectAny;
Expand Down Expand Up @@ -172,14 +172,14 @@ private void load(ILyricEditorState state, LyricSelectionState lyricSelectionSta
selectedLyrics = lyricSelectionState.SelectedLyrics.GetBoundCopy();

// should update background if mode changed.
mode.BindValueChanged(e =>
mode.BindValueChanged(_ =>
{
background.Colour = colourProvider.Dark2(state.Mode);
allSelectedCheckbox.AccentColour = colourProvider.Colour2(state.Mode);
}, true);

// should disable selection if current lyric is disabled.
disableSelectingLyrics.BindCollectionChanged((a, b) =>
disableSelectingLyrics.BindCollectionChanged((_, _) =>
{
var disabledLyricNumber = lyricSelectionState.DisableSelectingLyric.Count;
var totalLyrics = beatmap.HitObjects.OfType<Lyric>().Count();
Expand All @@ -190,7 +190,7 @@ private void load(ILyricEditorState state, LyricSelectionState lyricSelectionSta
});

// get bindable and update bindable if select or not select all.
selectedLyrics.BindCollectionChanged((a, b) =>
selectedLyrics.BindCollectionChanged((_, _) =>
{
if (checkboxClicking)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public DrawableLyricEditListItem(Lyric item)
removeExtend();
}, true);

bindableHoverCaretPosition.BindValueChanged(e =>
bindableHoverCaretPosition.BindValueChanged(_ =>
{
updateBackgroundColour();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LanguageAutoGenerateSection : AutoGenerateSection

protected override Dictionary<Lyric, string> GetDisableSelectingLyrics(Lyric[] lyrics)
=> lyrics.Where(x => string.IsNullOrEmpty(x.Text))
.ToDictionary(k => k, i => "Should have text in lyric.");
.ToDictionary(k => k, _ => "Should have text in lyric.");

protected override void Apply(Lyric[] lyrics)
=> lyricManager.AutoDetectLyricLanguage(lyrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void load(LyricCheckerManager lyricCheckerManager)
};

bindableReports = lyricCheckerManager.BindableReports.GetBoundCopy();
bindableReports.BindCollectionChanged((a, b) =>
bindableReports.BindCollectionChanged((_, _) =>
{
var issues = bindableReports.Values.SelectMany(x => x);
table.Issues = issues.Where(x => x.Template is CheckInvalidPropertyLyrics.IssueTemplateNotFillLanguage);
Expand All @@ -60,13 +60,13 @@ public IEnumerable<Issue> Issues
if (value == null)
return;

Content = value.Select((g, i) =>
Content = value.Select((g, _) =>
{
var lyric = g.HitObjects.FirstOrDefault() as Lyric;
return createContent(lyric);
}).ToArray().ToRectangular();

BackgroundFlow.Children = value.Select((g, i) =>
BackgroundFlow.Children = value.Select((g, _) =>
{
var lyric = g.HitObjects.FirstOrDefault() as Lyric;
return new LyricLanguageRowBackground(lyric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NoteAutoGenerateSection : AutoGenerateSection

protected override Dictionary<Lyric, string> GetDisableSelectingLyrics(Lyric[] lyrics)
=> lyricCheckerManager.BindableReports.Where(x => x.Value.OfType<TimeTagIssue>().Any())
.ToDictionary(k => k.Key, i => "Before generate time-tag, need to assign language first.");
.ToDictionary(k => k.Key, _ => "Before generate time-tag, need to assign language first.");

protected override void Apply(Lyric[] lyrics)
=> noteManager.AutoGenerateNotes(lyrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ protected LabelledTextTagTextBox(T textTag)
Component.Text = textTag.Text;

// should change preview text box if selected ruby/romaji changed.
OnCommit += (sender, newText) =>
OnCommit += (sender, _) =>
{
textTag.Text = sender.Text;
};

// change style if focus.
SelectedTextTag.BindCollectionChanged((e, a) =>
SelectedTextTag.BindCollectionChanged((_, _) =>
{
var highLight = SelectedTextTag.Contains(textTag);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RomajiTagAutoGenerateSection : TextTagAutoGenerateSection

protected override Dictionary<Lyric, string> GetDisableSelectingLyrics(Lyric[] lyrics)
=> lyrics.Where(x => x.Language == null)
.ToDictionary(k => k, i => "Before generate romaji-tag, need to assign language first.");
.ToDictionary(k => k, _ => "Before generate romaji-tag, need to assign language first.");

protected override void Apply(Lyric[] lyrics)
=> rubyRomaji.AutoGenerateLyricRomaji(lyrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void load(LyricCheckerManager lyricCheckerManager)
};

bindableReports = lyricCheckerManager.BindableReports.GetBoundCopy();
bindableReports.BindCollectionChanged((a, b) =>
bindableReports.BindCollectionChanged((_, _) =>
{
var issues = bindableReports.Values.SelectMany(x => x);
table.Issues = issues.OfType<RomajiTagIssue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RubyTagAutoGenerateSection : TextTagAutoGenerateSection

protected override Dictionary<Lyric, string> GetDisableSelectingLyrics(Lyric[] lyrics)
=> lyrics.Where(x => x.Language == null)
.ToDictionary(k => k, i => "Before generate ruby-tag, need to assign language first.");
.ToDictionary(k => k, _ => "Before generate ruby-tag, need to assign language first.");

protected override void Apply(Lyric[] lyrics)
=> rubyRomaji.AutoGenerateLyricRuby(lyrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void load(LyricCheckerManager lyricCheckerManager)
};

bindableReports = lyricCheckerManager.BindableReports.GetBoundCopy();
bindableReports.BindCollectionChanged((a, b) =>
bindableReports.BindCollectionChanged((_, _) =>
{
var issues = bindableReports.Values.SelectMany(x => x);
table.Issues = issues.OfType<RubyTagIssue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SingerEditSection : Section

public SingerEditSection()
{
singerIndexes.BindValueChanged(e =>
singerIndexes.BindValueChanged(_ =>
{
foreach (var singerLabel in Content.OfType<LabelledSingerSwitchButton>())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TimeTagAutoGenerateSection : AutoGenerateSection

protected override Dictionary<Lyric, string> GetDisableSelectingLyrics(Lyric[] lyrics)
=> lyrics.Where(x => x.Language == null)
.ToDictionary(k => k, i => "Before generate time-tag, need to assign language first.");
.ToDictionary(k => k, _ => "Before generate time-tag, need to assign language first.");

protected override void Apply(Lyric[] lyrics)
=> lyricManager.AutoGenerateTimeTags(lyrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void load(LyricCheckerManager lyricCheckerManager)
};

bindableReports = lyricCheckerManager.BindableReports.GetBoundCopy();
bindableReports.BindCollectionChanged((a, b) =>
bindableReports.BindCollectionChanged((_, _) =>
{
// todo : might have filter in here.
var issues = bindableReports.Values.SelectMany(x => x);
Expand All @@ -68,7 +68,7 @@ public IEnumerable<TimeTagIssue> Issues
if (value == null)
return;

Content = value.Select((g, i) =>
Content = value.Select((g, _) =>
{
var lyric = g.HitObjects.FirstOrDefault() as Lyric;

Expand All @@ -88,7 +88,7 @@ public IEnumerable<TimeTagIssue> Issues
return rows;
}).SelectMany(x => x).ToArray().ToRectangular();

BackgroundFlow.Children = value.Select((g, i) =>
BackgroundFlow.Children = value.Select((g, _) =>
{
var lyric = g.HitObjects.FirstOrDefault() as Lyric;

Expand Down Expand Up @@ -217,7 +217,7 @@ private void load(ILyricEditorState state, LyricCaretState lyricCaretState, Blue
{
// update selected state by bindable.
selectedTimeTags = blueprintSelectionState.SelectedTimeTags.GetBoundCopy();
selectedTimeTags.BindCollectionChanged((a, b) =>
selectedTimeTags.BindCollectionChanged((_, _) =>
{
var selected = selectedTimeTags.Contains(timeTag);
UpdateState(selected);
Expand Down
Loading

0 comments on commit 5909605

Please sign in to comment.