Skip to content

Commit

Permalink
Merge pull request #1667 from andy840119/clean-up-code-by-script
Browse files Browse the repository at this point in the history
Clean up code.
  • Loading branch information
andy840119 authored Oct 16, 2022
2 parents aa03c53 + cf6170e commit 0b43ceb
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SingleLyricEditorTest
public void TestLockMessage()
{
var lyric = new Lyric();
Assert.IsNull(EditableLyric.GetLyricPropertyLockedReason(lyric, LyricEditorMode.View));
Assert.IsNull(InteractableLyric.GetLyricPropertyLockedReason(lyric, LyricEditorMode.View));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void load()
Dependencies.CacheAs<ITimeTagModeState>(new TimeTagModeState());
Dependencies.Cache(new KaraokeRulesetLyricEditorConfigManager());

LyricsProvider lyricsProvider = new LyricsProvider();
var lyricsProvider = new LyricsProvider();
Dependencies.CacheAs<ILyricsProvider>(lyricsProvider);

Children = new Drawable[]
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.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -284,7 +285,7 @@ internal class Check : ICheck
{
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}

public CheckMetadata Metadata { get; } = null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor
[TestFixture]
public class TestSceneLayoutToolTip : OsuTestScene
{
private ISkin skin = new TestingSkin(null);
private readonly ISkin skin = new TestingSkin(null);
private LayoutToolTip toolTip = null!;

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ public void TestLyricConvertorWithNoConfig()
{
var lyric = new Lyric();

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\":{},\"samples\":[],\"auxiliary_samples\":[]}";
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\":{},\"samples\":[],\"auxiliary_samples\":[]}";
string actual = JsonConvert.SerializeObject(lyric, CreateSettings());
Assert.AreEqual(expected, actual);
}

[Test]
public void TestDeserializeWithNoConfig()
{
const string json = "{\"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\":{},\"samples\":[],\"auxiliary_samples\":[]}";
const string json =
"{\"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\":{},\"samples\":[],\"auxiliary_samples\":[]}";

var expected = new Lyric();
var actual = JsonConvert.DeserializeObject<Lyric>(json, CreateSettings())!;
Expand Down Expand Up @@ -63,7 +65,8 @@ public void TestLyricConvertorWithSyncConfig()

const string reference_lyric_json =
"{\"$id\":\"1\",\"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\":{},\"samples\":[],\"auxiliary_samples\":[]}";
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\":{reference_lyric_json},\"reference_lyric_config\":{{\"$type\":\"SyncLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
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\":{reference_lyric_json},\"reference_lyric_config\":{{\"$type\":\"SyncLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
string actual = JsonConvert.SerializeObject(lyric, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand All @@ -79,7 +82,8 @@ public void TestLyricConvertorWithReferenceConfig()

const string reference_lyric_json =
"{\"$id\":\"1\",\"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\":{},\"samples\":[],\"auxiliary_samples\":[]}";
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\":{reference_lyric_json},\"reference_lyric_config\":{{\"$type\":\"ReferenceLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
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\":{reference_lyric_json},\"reference_lyric_config\":{{\"$type\":\"ReferenceLyricConfig\"}},\"samples\":[],\"auxiliary_samples\":[]}}";
string actual = JsonConvert.SerializeObject(lyric, CreateSettings());
Assert.AreEqual(expected, actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public void TestSerializeLyric()
{
var lyric = new Lyric();

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"":[],""samples"":[],""auxiliary_samples"":[]}";
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"":[],""samples"":[],""auxiliary_samples"":[]}";

string actual = JsonConvert.SerializeObject(lyric, createSettings());
Assert.AreEqual(expected, actual);
Expand All @@ -25,10 +26,11 @@ public void TestSerializeLyric()
[Test]
public void TestDeserializeLyric()
{
const string json = @"{""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"":[],""samples"":[],""auxiliary_samples"":[]}";
const string json =
@"{""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"":[],""samples"":[],""auxiliary_samples"":[]}";

Lyric expected = new Lyric();
Lyric actual = JsonConvert.DeserializeObject<Lyric>(json, createSettings())!;
var expected = new Lyric();
var actual = JsonConvert.DeserializeObject<Lyric>(json, createSettings())!;
ObjectAssert.ArePropertyEqual(expected, actual);
}

Expand All @@ -37,7 +39,8 @@ public void TestSerializeNote()
{
var note = new Note();

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},""samples"":[],""auxiliary_samples"":[]}";
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},""samples"":[],""auxiliary_samples"":[]}";

string actual = JsonConvert.SerializeObject(note, createSettings());
Assert.AreEqual(expected, actual);
Expand All @@ -46,10 +49,11 @@ public void TestSerializeNote()
[Test]
public void TestDeserializeNote()
{
const string json = @"{""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},""samples"":[],""auxiliary_samples"":[]}";
const string json =
@"{""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},""samples"":[],""auxiliary_samples"":[]}";

Note expected = new Note();
Note actual = JsonConvert.DeserializeObject<Note>(json, createSettings())!;
var expected = new Note();
var actual = JsonConvert.DeserializeObject<Note>(json, createSettings())!;
ObjectAssert.ArePropertyEqual(expected, actual);
}

Expand Down
11 changes: 5 additions & 6 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using osu.Game.Rulesets.Karaoke.Utils;
using Lyric = osu.Game.Rulesets.Karaoke.Objects.Lyric;
using RubyTag = osu.Game.Rulesets.Karaoke.Objects.RubyTag;
using TextIndex = osu.Framework.Graphics.Sprites.TextIndex;

namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats
{
Expand Down Expand Up @@ -56,15 +55,15 @@ protected override void ParseStreamInto(LineBufferedReader stream, Beatmap outpu
output.HitObjects.Add(lyric);
}

static TimeTag convertTimeTag(KeyValuePair<LrcParser.Model.TextIndex, int?> timeTag)
static TimeTag convertTimeTag(KeyValuePair<TextIndex, int?> timeTag)
=> new(convertTextIndex(timeTag.Key), timeTag.Value);

static TextIndex convertTextIndex(LrcParser.Model.TextIndex textIndex)
static Framework.Graphics.Sprites.TextIndex convertTextIndex(TextIndex textIndex)
{
int index = textIndex.Index;
var state = textIndex.State == IndexState.Start ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
var state = textIndex.State == IndexState.Start ? Framework.Graphics.Sprites.TextIndex.IndexState.Start : Framework.Graphics.Sprites.TextIndex.IndexState.End;

return new TextIndex(index, state);
return new Framework.Graphics.Sprites.TextIndex(index, state);
}

static RubyTag convertRubyTag(LrcParser.Model.RubyTag rubyTag)
Expand All @@ -78,7 +77,7 @@ static RubyTag convertRubyTag(LrcParser.Model.RubyTag rubyTag)
static TimeTag[] convertTimeTagsFromRubyTags(LrcParser.Model.RubyTag rubyTag)
{
int startIndex = rubyTag.StartIndex;
return rubyTag.TimeTags.Select(x => convertTimeTag(new KeyValuePair<LrcParser.Model.TextIndex, int?>(new LrcParser.Model.TextIndex(startIndex), x.Value))).ToArray();
return rubyTag.TimeTags.Select(x => convertTimeTag(new KeyValuePair<TextIndex, int?>(new TextIndex(startIndex), x.Value))).ToArray();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Utils;
using Lyric = osu.Game.Rulesets.Karaoke.Objects.Lyric;
using RubyTag = osu.Game.Rulesets.Karaoke.Objects.RubyTag;
using RubyTag = LrcParser.Model.RubyTag;
using TextIndex = osu.Framework.Graphics.Sprites.TextIndex;

namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats
Expand Down Expand Up @@ -49,8 +49,8 @@ static LrcParser.Model.TextIndex convertTextIndex(TextIndex textIndex)
return new LrcParser.Model.TextIndex(index, state);
}

static List<LrcParser.Model.RubyTag> convertRubyTag(IEnumerable<RubyTag> rubyTags)
=> rubyTags.Select(x => new LrcParser.Model.RubyTag
static List<RubyTag> convertRubyTag(IEnumerable<Objects.RubyTag> rubyTags)
=> rubyTags.Select(x => new RubyTag
{
Text = x.Text,
StartIndex = x.StartIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(I
// todo : might have a sort.
// LegacySortHelper<HitObject>.Sort(sortedObjects, Comparer<HitObject>.Create((a, b) => (int)Math.Round(a.StartTime) - (int)Math.Round(b.StartTime)));

List<DifficultyHitObject> objects = new List<DifficultyHitObject>();
var objects = new List<DifficultyHitObject>();

for (int i = 1; i < sortedObjects.Length; i++)
objects.Add(new KaraokeDifficultyHitObject(sortedObjects[i], sortedObjects[i - 1], clockRate, objects, objects.Count));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected override void Update()

public override MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem(HitObject.Display ? "Hide" : "Show", HitObject.Display ? MenuItemType.Destructive : MenuItemType.Standard, () => notePropertyChangeHandler.ChangeDisplayState(!HitObject.Display)),
new OsuMenuItem(HitObject.Display ? "Hide" : "Show", HitObject.Display ? MenuItemType.Destructive : MenuItemType.Standard,
() => notePropertyChangeHandler.ChangeDisplayState(!HitObject.Display)),
new OsuMenuItem("Split", MenuItemType.Destructive, () => notesChangeHandler.Split()),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ public enum LyricAutoGenerateProperty
AutoGenerateNotes,
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public KaraokeLegacyBeatmapExporter(Storage storage, string filename, string con
public override void ExportModelTo(BeatmapSetInfo model, Stream outputStream)
{
// base.ExportModelTo(model, outputStream);
using (ZipArchive zipArchive = ZipArchive.Create())
using (var zipArchive = ZipArchive.Create())
{
foreach (INamedFileUsage file in model.Files)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected override void LoadComplete()
public override void Complete()
{
// Check is need to go to generate ruby/romaji step or just skip.
if (lyricAutoGenerateChangeHandler.CanGenerate(LyricAutoGenerateProperty.AutoGenerateRubyTags) || lyricAutoGenerateChangeHandler.CanGenerate(LyricAutoGenerateProperty.AutoGenerateRomajiTags))
if (lyricAutoGenerateChangeHandler.CanGenerate(LyricAutoGenerateProperty.AutoGenerateRubyTags)
|| lyricAutoGenerateChangeHandler.CanGenerate(LyricAutoGenerateProperty.AutoGenerateRomajiTags))
{
ScreenStack.Push(LyricImporterStep.GenerateRuby);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void assignPanelPosition(PanelLayout panelLayout)

foreach (var (direction, panelTypes) in panelDirections)
{
foreach (Panel instance in panelTypes.Select(panelType => panelInstance[panelType]))
foreach (var instance in panelTypes.Select(panelType => panelInstance[panelType]))
{
instance.Direction = direction;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ private void assignBottomEditor(BottomEditorType? bottomEditorType)
return;

bottomEditorContainer.Add(newButtonEditor);
newButtonEditor.Delay(hasOldButtonEditor ? remove_old_editor_time : 0).FadeIn(0).MoveToY(0, new_animation_time);
newButtonEditor.Delay(hasOldButtonEditor ? remove_old_editor_time : 0).FadeIn().MoveToY(0, new_animation_time);

static BaseBottomEditor? createBottomEditor(BottomEditorType? bottomEditorType) =>
bottomEditorType switch
Expand Down
Loading

0 comments on commit 0b43ceb

Please sign in to comment.