Skip to content

Commit

Permalink
Merge pull request #1562 from andy840119/implement-lock-check-in-the-…
Browse files Browse the repository at this point in the history
…lock-change-handler

Implement lock check in the lock change handler.
  • Loading branch information
andy840119 authored Sep 4, 2022
2 parents 70b142e + 4b73fd4 commit 902f62c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers;
using osu.Game.Rulesets.Objects;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers
{
public abstract class BaseHitObjectPropertyChangeHandlerTest<TChangeHandler, THitObject> : BaseHitObjectChangeHandlerTest<TChangeHandler, THitObject>
where TChangeHandler : HitObjectPropertyChangeHandler<THitObject>, new() where THitObject : HitObject
{
protected void TriggerHandlerChangedWithChangeForbiddenException(Action<TChangeHandler> c)
{
TriggerHandlerChangedWithException<HitObjectPropertyChangeHandler<THitObject>.ChangeForbiddenException>(c);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Properties;
using osu.Game.Rulesets.Karaoke.Objects.Types;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers
{
public class LockChangeHandlerTest : BaseHitObjectChangeHandlerTest<LockChangeHandler, KaraokeHitObject>
public class LockChangeHandlerTest : BaseHitObjectPropertyChangeHandlerTest<LockChangeHandler, KaraokeHitObject>
{
[Test]
public void TestLock()
Expand Down Expand Up @@ -55,5 +56,18 @@ public void TestUnlock()
Assert.AreEqual(LockState.None, hasLock.Lock);
});
}

[Test]
public void TestLockToReferenceLyric()
{
PrepareHitObject(new Lyric
{
Text = "カラオケ",
ReferenceLyric = new Lyric(),
ReferenceLyricConfig = new SyncLyricConfig(),
});

TriggerHandlerChangedWithChangeForbiddenException(c => c.Lock(LockState.Full));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// 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 osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Properties;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics
{
public abstract class LyricPropertyChangeHandlerTest<TChangeHandler> : BaseHitObjectChangeHandlerTest<TChangeHandler, Lyric>
public abstract class LyricPropertyChangeHandlerTest<TChangeHandler> : BaseHitObjectPropertyChangeHandlerTest<TChangeHandler, Lyric>
where TChangeHandler : LyricPropertyChangeHandler, new()
{
protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyricPropertyConfig? config = null, bool selected = true)
Expand All @@ -23,10 +22,5 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri

return lyric;
}

protected void TriggerHandlerChangedWithChangeForbiddenException(Action<TChangeHandler> c)
{
TriggerHandlerChangedWithException<LyricPropertyChangeHandler.ChangeForbiddenException>(c);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Notes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Properties;

namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Notes
{
public class NotePropertyChangeHandlerTest : BaseHitObjectChangeHandlerTest<NotePropertyChangeHandler, Note>
public class NotePropertyChangeHandlerTest : BaseHitObjectPropertyChangeHandlerTest<NotePropertyChangeHandler, Note>
{
[Test]
public void TestChangeText()
Expand Down Expand Up @@ -71,5 +72,22 @@ public void TestChangeDisplayStateToNonVisible()
Assert.AreEqual(new Tone(), h.Tone);
});
}

[Test]
[Ignore("Waiting to implement the lock rules.")]
public void TestWithReferenceLyric()
{
PrepareHitObject(new Note
{
Text = "カラオケ",
ReferenceLyric = new Lyric
{
ReferenceLyric = new Lyric(),
ReferenceLyricConfig = new ReferenceLyricConfig()
}
});

TriggerHandlerChangedWithChangeForbiddenException(c => c.ChangeText("からおけ"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Game.Rulesets.Karaoke.Edit.Utils;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Types;

Expand All @@ -25,11 +26,10 @@ public void Unlock()

protected override bool IsWritePropertyLocked(KaraokeHitObject hitObject)
{
// todo: implement.
return hitObject switch
{
Lyric => false,
Note => false,
Lyric lyric => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.Lock)),
Note note => HitObjectWritableUtils.IsWriteNotePropertyLocked(note, nameof(Lyric.Lock)),
_ => throw new NotSupportedException()
};
}
Expand Down

0 comments on commit 902f62c

Please sign in to comment.