Skip to content

Commit

Permalink
Merge pull request #963 from andy840119/remove-lyric-editor-prefix-step
Browse files Browse the repository at this point in the history
Remove lyric editor prefix step
  • Loading branch information
andy840119 authored Dec 11, 2021
2 parents 590b65b + d9712fc commit 21dd020
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand All @@ -26,21 +25,15 @@ protected KaraokeEditorScreenTestScene()
editorBeatmap = new EditorBeatmap(CreateBeatmap());
}

[Test]
public void TestKaraoke() => runForRuleset(new KaraokeRuleset().RulesetInfo);

private void runForRuleset(RulesetInfo rulesetInfo)
protected override void LoadComplete()
{
AddStep("create screen", () =>
{
editorBeatmap.BeatmapInfo.Ruleset = rulesetInfo;
editorBeatmap.BeatmapInfo.Ruleset = new KaraokeRuleset().RulesetInfo;

Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);

Child = CreateEditorScreen().With(x =>
{
x.State.Value = Visibility.Visible;
});
Child = CreateEditorScreen().With(x =>
{
x.State.Value = Visibility.Visible;
});
}

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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -29,17 +28,11 @@ private void load(SkinManager skinManager)
karaokeSkin = skinManager.CurrentSkin.Value as KaraokeSkin;
}

[Test]
public void TestKaraoke() => runForRuleset(new KaraokeRuleset().RulesetInfo);

private void runForRuleset(RulesetInfo rulesetInfo)
protected override void LoadComplete()
{
AddStep("create screen", () =>
Child = CreateEditorScreen(karaokeSkin).With(x =>
{
Child = CreateEditorScreen(karaokeSkin).With(x =>
{
x.State.Value = Visibility.Visible;
});
x.State.Value = Visibility.Visible;
});
}

Expand Down
1 change: 1 addition & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/TimeTagsUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void TestFindNoneTime(string[] timeTagTexts, string[] invalidTimeTags)
[TestCase("カラオケ", new[] { "[3,end]:1000" }, false)]
[TestCase("カラオケ", new[] { "[-1,start]:1000", "[3,end]:2000" }, false)] // out of range end time-tag should be count as missing.
[TestCase("", new[] { "[0,start]:1000", "[0,end]:2000" }, false)] // empty lyric should always count as missing.
[TestCase("カラオケ", null, false)] // empty time-tag should always count as missing.
public void TestHasStartTimeTagInLyric(string text, string[] timeTagTexts, bool actual)
{
var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagTexts);
Expand Down
11 changes: 11 additions & 0 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ private void load(EditorBeatmap beatmap)
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.CreateTimeTagMovingCaretMode, bindableCreateMovingCaretMode);
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.RecordingTimeTagMovingCaretMode, bindableRecordingMovingCaretMode);

// if caret position changed, should add into editor beatmap selected hit objects.
lyricCaretState.BindableCaretPosition.BindValueChanged(e =>
{
beatmap.SelectedHitObjects.Clear();

var lyric = e.NewValue?.Lyric;

if (lyric != null)
beatmap.SelectedHitObjects.Add(lyric);
});

// set-up divisor.
beatDivisor.Value = beatmap.BeatmapInfo.BeatDivisor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected TextTagBlueprintContainer(Lyric lyric)

protected override bool OnMouseDown(MouseDownEvent e)
{
lyricCaretState.MoveCaretToTargetPosition(new NavigateCaretPosition(Lyric));
lyricCaretState.MoveCaretToTargetPosition(Lyric);
return base.OnMouseDown(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TimeTagBlueprintContainer(Lyric lyric)

protected override bool OnMouseDown(MouseDownEvent e)
{
lyricCaretState.MoveCaretToTargetPosition(new NavigateCaretPosition(Lyric));
lyricCaretState.MoveCaretToTargetPosition(Lyric);
return base.OnMouseDown(e);
}

Expand Down
13 changes: 13 additions & 0 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/States/LyricCaretState.cs
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.ComponentModel;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
Expand Down Expand Up @@ -79,6 +80,18 @@ public bool MoveCaret(MovingCaretAction action)
return true;
}

public void MoveCaretToTargetPosition(Lyric lyric)
{
if (lyric == null)
throw new ArgumentNullException(nameof(lyric));

if (algorithm == null)
throw new InvalidOperationException($"{nameof(algorithm)} cannot be null.");

BindableCaretPosition.Value = algorithm.CallMethod<ICaretPosition, Lyric>("MoveToTarget", lyric);
BindableHoverCaretPosition.Value = null;
}

public void MoveCaretToTargetPosition(ICaretPosition position)
{
if (position.Lyric == null)
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Utils/TimeTagsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static TimeTag[] FindNoneTime(TimeTag[] timeTags)
/// <param name="timeTags"></param>
/// <param name="lyric"></param>
public static bool HasStartTimeTagInLyric(TimeTag[] timeTags, string lyric)
=> !string.IsNullOrEmpty(lyric) && timeTags.Any(x => x.Index.State == TextIndex.IndexState.Start && x.Index.Index == 0);
=> !string.IsNullOrEmpty(lyric) && timeTags != null && timeTags.Any(x => x.Index.State == TextIndex.IndexState.Start && x.Index.Index == 0);

/// <summary>
/// Check lyric has end time-tag
Expand Down

0 comments on commit 21dd020

Please sign in to comment.