Skip to content

Commit

Permalink
Merge pull request #1423 from andy840119/remove-disable-null-in-the-l…
Browse files Browse the repository at this point in the history
…yric-editor-state

Enable NRT in the lyric editor state.
  • Loading branch information
andy840119 authored Jun 28, 2022
2 parents d930ef2 + ba03509 commit 09b6ff5
Show file tree
Hide file tree
Showing 27 changed files with 34 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using NUnit.Framework;
Expand All @@ -28,8 +26,8 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Lyrics.States
public class LyricCaretStateTest : OsuTestScene
{
private readonly IBeatmap beatmap;
private ILyricEditorState state;
private LyricCaretState lyricCaretState;
private ILyricEditorState state = null!;
private LyricCaretState lyricCaretState = null!;

public LyricCaretStateTest()
{
Expand Down Expand Up @@ -239,11 +237,11 @@ public void MovingHoverCaretByCaretPositionWithEditMode()

// because switch to the singer lyric, so current caret position will at the first lyric.
assertCaretPosition(Assert.IsInstanceOf<NavigateCaretPosition>);
assertCaretPosition(x => Assert.AreEqual(firstLyric, x.Lyric));
assertCaretPosition(x => Assert.AreEqual(firstLyric, x?.Lyric));

// yes, should change the position if contains algorithm.
assertHoverCaretPosition(Assert.IsInstanceOf<NavigateCaretPosition>);
assertHoverCaretPosition(x => Assert.AreEqual(targetLyric, x.Lyric));
assertHoverCaretPosition(x => Assert.AreEqual(targetLyric, x?.Lyric));
}

[Test]
Expand Down Expand Up @@ -318,17 +316,17 @@ private void movingHoverCaretByLyric(ICaretPosition caretPosition, bool exceptSu
}

private Lyric getLyricFromBeatmap(int index)
=> beatmap.HitObjects[index] as Lyric;
=> (Lyric)beatmap.HitObjects[index];

private void assertCaretPosition(Action<ICaretPosition> caretPosition)
private void assertCaretPosition(Action<ICaretPosition?> caretPosition)
{
AddStep("Assert caret position", () =>
{
caretPosition.Invoke(lyricCaretState.BindableCaretPosition.Value);
});
}

private void assertHoverCaretPosition(Action<ICaretPosition> caretPosition)
private void assertHoverCaretPosition(Action<ICaretPosition?> caretPosition)
{
AddStep("Assert hover caret position", () =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States
{
public enum CreateTimeTagEditMode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition.Algorithms;
Expand All @@ -12,11 +10,11 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States
{
public interface ILyricCaretState
{
IBindable<ICaretPosition> BindableHoverCaretPosition { get; }
IBindable<ICaretPosition?> BindableHoverCaretPosition { get; }

IBindable<ICaretPosition> BindableCaretPosition { get; }
IBindable<ICaretPosition?> BindableCaretPosition { get; }

IBindable<ICaretPositionAlgorithm> BindableCaretPositionAlgorithm { get; }
IBindable<ICaretPositionAlgorithm?> BindableCaretPositionAlgorithm { get; }

bool MoveCaret(MovingCaretAction action);

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

#nullable disable

using System;
using System.Collections.Generic;
using osu.Framework.Bindables;
Expand All @@ -19,7 +17,7 @@ public interface ILyricSelectionState

IBindableList<Lyric> SelectedLyrics { get; }

Action<LyricEditorSelectingAction> Action { get; set; }
Action<LyricEditorSelectingAction>? Action { get; set; }

void StartSelecting();

Expand Down
42 changes: 19 additions & 23 deletions osu.Game.Rulesets.Karaoke/Edit/Lyrics/States/LyricCaretState.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand All @@ -21,16 +20,16 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States
{
public class LyricCaretState : Component, ILyricCaretState
{
public IBindable<ICaretPosition> BindableHoverCaretPosition => bindableHoverCaretPosition;
public IBindable<ICaretPosition> BindableCaretPosition => bindableCaretPosition;
public IBindable<ICaretPosition?> BindableHoverCaretPosition => bindableHoverCaretPosition;
public IBindable<ICaretPosition?> BindableCaretPosition => bindableCaretPosition;

public IBindable<ICaretPositionAlgorithm> BindableCaretPositionAlgorithm => bindableCaretPositionAlgorithm;
public IBindable<ICaretPositionAlgorithm?> BindableCaretPositionAlgorithm => bindableCaretPositionAlgorithm;

private readonly Bindable<ICaretPosition> bindableHoverCaretPosition = new();
private readonly Bindable<ICaretPosition> bindableCaretPosition = new();
private readonly Bindable<ICaretPositionAlgorithm> bindableCaretPositionAlgorithm = new();
private readonly Bindable<ICaretPosition?> bindableHoverCaretPosition = new();
private readonly Bindable<ICaretPosition?> bindableCaretPosition = new();
private readonly Bindable<ICaretPositionAlgorithm?> bindableCaretPositionAlgorithm = new();

private ICaretPositionAlgorithm algorithm => bindableCaretPositionAlgorithm.Value;
private ICaretPositionAlgorithm? algorithm => bindableCaretPositionAlgorithm.Value;

private readonly IBindableList<Lyric> bindableLyrics = new BindableList<Lyric>();

Expand All @@ -44,7 +43,7 @@ public class LyricCaretState : Component, ILyricCaretState
private readonly IBindable<MovingTimeTagCaretMode> bindableRecordingMovingCaretMode = new Bindable<MovingTimeTagCaretMode>();
private readonly IBindable<bool> bindableRecordingChangeTimeWhileMovingTheCaret = new Bindable<bool>();

[Resolved]
[Resolved, AllowNull]
private EditorClock editorClock { get; set; }

public LyricCaretState()
Expand Down Expand Up @@ -109,7 +108,7 @@ private void refreshAlgorithmAndCaretPosition()
// should update selection if selected lyric changed.
postProcess();

static ICaretPosition getCaretPosition(ICaretPositionAlgorithm algorithm, Lyric lyric)
static ICaretPosition? getCaretPosition(ICaretPositionAlgorithm? algorithm, Lyric? lyric)
{
if (algorithm == null)
return null;
Expand All @@ -121,7 +120,7 @@ static ICaretPosition getCaretPosition(ICaretPositionAlgorithm algorithm, Lyric
}
}

private ICaretPositionAlgorithm getAlgorithmByMode()
private ICaretPositionAlgorithm? getAlgorithmByMode()
{
var lyrics = bindableLyrics.ToArray();
var lyricEditorMode = bindableMode.Value;
Expand Down Expand Up @@ -187,10 +186,10 @@ public bool MoveCaret(MovingCaretAction action)

var position = action switch
{
MovingCaretAction.Up => algorithm.MoveUp(currentPosition),
MovingCaretAction.Down => algorithm.MoveDown(currentPosition),
MovingCaretAction.Left => algorithm.MoveLeft(currentPosition),
MovingCaretAction.Right => algorithm.MoveRight(currentPosition),
MovingCaretAction.Up => moveIfNotNull(currentPosition, algorithm.MoveUp),
MovingCaretAction.Down => moveIfNotNull(currentPosition, algorithm.MoveDown),
MovingCaretAction.Left => moveIfNotNull(currentPosition, algorithm.MoveLeft),
MovingCaretAction.Right => moveIfNotNull(currentPosition, algorithm.MoveRight),
MovingCaretAction.First => algorithm.MoveToFirst(),
MovingCaretAction.Last => algorithm.MoveToLast(),
_ => throw new InvalidEnumArgumentException(nameof(action))
Expand All @@ -201,6 +200,9 @@ public bool MoveCaret(MovingCaretAction action)

MoveCaretToTargetPosition(position);
return true;

static ICaretPosition? moveIfNotNull(ICaretPosition? caretPosition, Func<ICaretPosition, ICaretPosition?> action)
=> caretPosition != null ? action.Invoke(caretPosition) : caretPosition;
}

public void MoveCaretToTargetPosition(Lyric lyric)
Expand All @@ -220,9 +222,6 @@ public void MoveCaretToTargetPosition(ICaretPosition position)
if (position == null)
throw new ArgumentNullException(nameof(position));

if (position.Lyric == null)
return;

bool movable = CaretPositionMovable(position);

// stop moving the caret if forbidden by algorithm calculation.
Expand All @@ -240,9 +239,6 @@ public void MoveHoverCaretToTargetPosition(ICaretPosition position)
if (position == null)
throw new ArgumentNullException(nameof(position));

if (position.Lyric == null)
return;

if (!CaretPositionMovable(position))
return;

Expand Down Expand Up @@ -275,7 +271,7 @@ private void postProcess()
var caretPosition = bindableCaretPosition.Value;
navigateToTimeByCaretPosition(caretPosition);

void navigateToTimeByCaretPosition(ICaretPosition position)
void navigateToTimeByCaretPosition(ICaretPosition? position)
{
if (position is not TimeTagCaretPosition timeTagCaretPosition)
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States
{
public enum LyricEditorSelectingAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand All @@ -26,12 +25,12 @@ public class LyricSelectionState : Component, ILyricSelectionState

public IBindableList<Lyric> SelectedLyrics => bindableSelectedLyrics;

public Action<LyricEditorSelectingAction> Action { get; set; }
public Action<LyricEditorSelectingAction>? Action { get; set; }

[Resolved]
[Resolved, AllowNull]
private EditorBeatmap beatmap { get; set; }

[Resolved]
[Resolved, AllowNull]
private ILyricCaretState lyricCaretState { get; set; }

private readonly BindableBool selecting = new();
Expand Down Expand Up @@ -119,9 +118,6 @@ public void UpdateDisableLyricList(IDictionary<Lyric, LocalisableString> disable

bindableDisableSelectingLyric.Clear();

if (disableLyrics == null)
return;

foreach ((var lyric, LocalisableString reason) in disableLyrics)
bindableDisableSelectingLyric.Add(lyric, reason);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

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

#nullable disable

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes;
using osu.Game.Rulesets.Karaoke.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using osu.Framework.Bindables;

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

#nullable disable

using System;
using osu.Framework.Bindables;

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

#nullable disable

using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Languages;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Manage;

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Game.Rulesets.Karaoke.Objects;

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

#nullable disable

namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.States.Modes
{
public enum LanguageEditMode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Languages;
Expand Down
Loading

0 comments on commit 09b6ff5

Please sign in to comment.