Skip to content

Commit

Permalink
Merge pull request #1867 from andy840119/clean-up-code-2
Browse files Browse the repository at this point in the history
Clean up code.
  • Loading branch information
andy840119 authored Feb 26, 2023
2 parents 30d8099 + b40c0d8 commit 14f6a50
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ private static ClassicLyricLayoutCategory getStageCategory(KaraokeBeatmap beatma

public partial class TestBeatmapStageElementCategoryChangeHandler : BeatmapStageElementCategoryChangeHandler<ClassicLyricLayout, Lyric>
{
public TestBeatmapStageElementCategoryChangeHandler(Func<IEnumerable<StageInfo>, StageElementCategory<ClassicLyricLayout, Lyric>> action)
: base(action)
public TestBeatmapStageElementCategoryChangeHandler(Func<IEnumerable<StageInfo>, StageElementCategory<ClassicLyricLayout, Lyric>> stageCategoryAction)
: base(stageCategoryAction)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void setTooltip(string testName, Action<Singer> callBack)
AddStep(testName, () =>
{
var singer = new Singer(1);
callBack?.Invoke(singer);
callBack(singer);
toolTip.SetContent(singer);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TestLyricConverterWithSyncConfig()
};

const string expected =
$"{{\"time_preempt\":600.0,\"time_fade_in\":400.0,\"start_time_bindable\":0.0,\"samples_bindable\":[],\"sample_control_point\":{{\"sample_bank_bindable\":\"normal\",\"sample_volume_bindable\":100,\"sample_bank\":\"normal\",\"sample_volume\":100}},\"difficulty_control_point\":{{\"slider_velocity_bindable\":1.0,\"slider_velocity\":1.0}},\"reference_lyric_id\":0,\"reference_lyric_config\":{{\"$type\":\"SyncLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
"{\"time_preempt\":600.0,\"time_fade_in\":400.0,\"start_time_bindable\":0.0,\"samples_bindable\":[],\"sample_control_point\":{\"sample_bank_bindable\":\"normal\",\"sample_volume_bindable\":100,\"sample_bank\":\"normal\",\"sample_volume\":100},\"difficulty_control_point\":{\"slider_velocity_bindable\":1.0,\"slider_velocity\":1.0},\"reference_lyric_id\":0,\"reference_lyric_config\":{\"$type\":\"SyncLyricConfig\"},\"samples\":[],\"auxiliary_samples\":[]}";
string actual = JsonConvert.SerializeObject(lyric, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand All @@ -79,7 +79,7 @@ public void TestLyricConverterWithReferenceConfig()
};

const string expected =
$"{{\"time_preempt\":600.0,\"time_fade_in\":400.0,\"start_time_bindable\":0.0,\"samples_bindable\":[],\"sample_control_point\":{{\"sample_bank_bindable\":\"normal\",\"sample_volume_bindable\":100,\"sample_bank\":\"normal\",\"sample_volume\":100}},\"difficulty_control_point\":{{\"slider_velocity_bindable\":1.0,\"slider_velocity\":1.0}},\"text\":\"\",\"time_tags\":[],\"ruby_tags\":[],\"romaji_tags\":[],\"singers\":[],\"translates\":{{}},\"reference_lyric_id\":0,\"reference_lyric_config\":{{\"$type\":\"ReferenceLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
"{\"time_preempt\":600.0,\"time_fade_in\":400.0,\"start_time_bindable\":0.0,\"samples_bindable\":[],\"sample_control_point\":{\"sample_bank_bindable\":\"normal\",\"sample_volume_bindable\":100,\"sample_bank\":\"normal\",\"sample_volume\":100},\"difficulty_control_point\":{\"slider_velocity_bindable\":1.0,\"slider_velocity\":1.0},\"text\":\"\",\"time_tags\":[],\"ruby_tags\":[],\"romaji_tags\":[],\"singers\":[],\"translates\":{},\"reference_lyric_id\":0,\"reference_lyric_config\":{\"$type\":\"ReferenceLyricConfig\"},\"samples\":[],\"auxiliary_samples\":[]}";
string actual = JsonConvert.SerializeObject(lyric, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/ComparableUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public void TestCompareByProperty(string leftObjectProperty, string rightObjectP
var leftObject = JsonConvert.DeserializeObject<TestObject>(leftObjectProperty);
var rightObject = JsonConvert.DeserializeObject<TestObject>(rightObjectProperty);
int actual = ComparableUtils.CompareByProperty(leftObject, rightObject,
(t) => t.A,
(t) => t.B,
(t) => t.C);
t => t.A,
t => t.B,
t => t.C);
Assert.AreEqual(expected, actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public partial class BeatmapStageElementCategoryChangeHandler<TStageElement, THi
where TStageElement : class, IStageElement, IComparable<TStageElement>
where THitObject : KaraokeHitObject, IHasPrimaryKey
{
private readonly Func<IEnumerable<StageInfo>, StageElementCategory<TStageElement, THitObject>> action;
private readonly Func<IEnumerable<StageInfo>, StageElementCategory<TStageElement, THitObject>> stageCategoryAction;

public BeatmapStageElementCategoryChangeHandler(Func<IEnumerable<StageInfo>, StageElementCategory<TStageElement, THitObject>> action)
public BeatmapStageElementCategoryChangeHandler(Func<IEnumerable<StageInfo>, StageElementCategory<TStageElement, THitObject>> stageCategoryAction)
{
this.action = action;
this.stageCategoryAction = stageCategoryAction;
}

public void AddElement(Action<TStageElement>? action = null)
Expand Down Expand Up @@ -104,7 +104,7 @@ private void performStageInfoChanged(Action<StageElementCategory<TStageElement,
{
PerformBeatmapChanged(beatmap =>
{
var stageCategory = action(beatmap.StageInfos);
var stageCategory = stageCategoryAction(beatmap.StageInfos);
stageAction(stageCategory);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void SwitchToReferenceLyricConfig()
{
PerformOnSelection(lyric =>
{
if (lyric == null)
if (lyric.ReferenceLyric == null)
throw new InvalidOperationException($"{nameof(lyric)} must have reference lyric.");

lyric.ReferenceLyricConfig = new ReferenceLyricConfig();
Expand All @@ -53,7 +53,7 @@ public void SwitchToSyncLyricConfig()
{
PerformOnSelection(lyric =>
{
if (lyric == null)
if (lyric.ReferenceLyric == null)
throw new InvalidOperationException($"{nameof(lyric)} must have reference lyric.");

lyric.ReferenceLyricConfig = new SyncLyricConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SingerContextMenu(EditorBeatmap beatmap, ILyricSingerChangeHandler lyricS
var karaokeBeatmap = EditorBeatmapUtils.GetPlayableBeatmap(beatmap);
var singers = karaokeBeatmap.SingerInfo.GetAllSingers();

Items = singers?.Select(singer => new OsuMenuItem(singer.Name, anySingerInLyric(singer) ? MenuItemType.Highlighted : MenuItemType.Standard, () =>
Items = singers.Select(singer => new OsuMenuItem(singer.Name, anySingerInLyric(singer) ? MenuItemType.Highlighted : MenuItemType.Standard, () =>
{
// if only one lyric
if (allSingerInLyric(singer))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class LanguageDetector : LyricPropertyDetector<CultureInfo?, LanguageDete
public LanguageDetector(LanguageDetectorConfig config)
: base(config)
{
var targetLanguages = config.AcceptLanguages.Where(x => x != null).ToList();
var targetLanguages = config.AcceptLanguages.ToList();

if (targetLanguages.Any())
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void initInternalBindingEvent()
void invalidate() => timeTagsVersion.Value++;
};

TimeTagsVersion.ValueChanged += (_) =>
TimeTagsVersion.ValueChanged += _ =>
{
updateLyricTime();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ private static void attachShaders(ShaderManager shaderManager, IEnumerable<ICust
attachShaders(shaderManager, stepShader.StepShaders.ToArray());
break;

case null:
throw new InvalidCastException("shader cannot be null.");

default:
throw new InvalidCastException($"{shader?.GetType()} cannot attach shader.");
throw new InvalidCastException($"{shader.GetType()} cannot attach shader.");
}
}
}
Expand Down

0 comments on commit 14f6a50

Please sign in to comment.