-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1537 from andy840119/prepare-sync-the-reference-l…
…yric Prepare sync the reference lyric
- Loading branch information
Showing
11 changed files
with
231 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects | ||
{ | ||
public class RomajiTagTest | ||
{ | ||
[TestCase] | ||
public void TestClone() | ||
{ | ||
var romajiTag = new RomajiTag | ||
{ | ||
Text = "romaji", | ||
StartIndex = 1, | ||
EndIndex = 2 | ||
}; | ||
|
||
var clonedRomajiTag = romajiTag.DeepClone(); | ||
|
||
Assert.AreNotSame(clonedRomajiTag.TextBindable, romajiTag.TextBindable); | ||
Assert.AreEqual(clonedRomajiTag.Text, romajiTag.Text); | ||
|
||
Assert.AreNotSame(clonedRomajiTag.StartIndexBindable, romajiTag.StartIndexBindable); | ||
Assert.AreEqual(clonedRomajiTag.StartIndex, romajiTag.StartIndex); | ||
|
||
Assert.AreNotSame(clonedRomajiTag.EndIndexBindable, romajiTag.EndIndexBindable); | ||
Assert.AreEqual(clonedRomajiTag.EndIndex, romajiTag.EndIndex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects | ||
{ | ||
public class RubyTagTest | ||
{ | ||
[TestCase] | ||
public void TestClone() | ||
{ | ||
var rubyTag = new RubyTag | ||
{ | ||
Text = "ruby", | ||
StartIndex = 1, | ||
EndIndex = 2 | ||
}; | ||
|
||
var clonedRubyTag = rubyTag.DeepClone(); | ||
|
||
Assert.AreNotSame(clonedRubyTag.TextBindable, rubyTag.TextBindable); | ||
Assert.AreEqual(clonedRubyTag.Text, rubyTag.Text); | ||
|
||
Assert.AreNotSame(clonedRubyTag.StartIndexBindable, rubyTag.StartIndexBindable); | ||
Assert.AreEqual(clonedRubyTag.StartIndex, rubyTag.StartIndex); | ||
|
||
Assert.AreNotSame(clonedRubyTag.EndIndexBindable, rubyTag.EndIndexBindable); | ||
Assert.AreEqual(clonedRubyTag.EndIndex, rubyTag.EndIndex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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.Graphics.Sprites; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects | ||
{ | ||
public class TimeTagTest | ||
{ | ||
[TestCase] | ||
public void TestClone() | ||
{ | ||
var timeTag = new TimeTag(new TextIndex(1, TextIndex.IndexState.End), 1000); | ||
|
||
var clonedTimeTag = timeTag.DeepClone(); | ||
|
||
Assert.AreEqual(clonedTimeTag.Index, timeTag.Index); | ||
|
||
Assert.AreNotSame(clonedTimeTag.TimeBindable, timeTag.TimeBindable); | ||
Assert.AreEqual(clonedTimeTag.Time, timeTag.Time); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Specialized; | ||
using System.Linq; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Objects | ||
{ | ||
public partial class Lyric | ||
{ | ||
private void initInternalBindingEvent() | ||
{ | ||
TimeTagsBindable.CollectionChanged += (_, args) => | ||
{ | ||
switch (args.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
foreach (var c in args.NewItems.Cast<TimeTag>()) | ||
c.Changed += invalidate; | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Reset: | ||
case NotifyCollectionChangedAction.Remove: | ||
foreach (var c in args.OldItems.Cast<TimeTag>()) | ||
c.Changed -= invalidate; | ||
break; | ||
} | ||
|
||
void invalidate() => TimeTagsVersion.Value++; | ||
}; | ||
|
||
RubyTagsBindable.CollectionChanged += (_, args) => | ||
{ | ||
switch (args.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
foreach (var c in args.NewItems.Cast<RubyTag>()) | ||
c.Changed += invalidate; | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Reset: | ||
case NotifyCollectionChangedAction.Remove: | ||
foreach (var c in args.OldItems.Cast<RubyTag>()) | ||
c.Changed -= invalidate; | ||
break; | ||
} | ||
|
||
void invalidate() => RubyTagsVersion.Value++; | ||
}; | ||
|
||
RomajiTagsBindable.CollectionChanged += (_, args) => | ||
{ | ||
switch (args.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
foreach (var c in args.NewItems.Cast<RomajiTag>()) | ||
c.Changed += invalidate; | ||
break; | ||
|
||
case NotifyCollectionChangedAction.Reset: | ||
case NotifyCollectionChangedAction.Remove: | ||
foreach (var c in args.OldItems.Cast<RomajiTag>()) | ||
c.Changed -= invalidate; | ||
break; | ||
} | ||
|
||
void invalidate() => RomajiTagsVersion.Value++; | ||
}; | ||
|
||
ReferenceLyricConfigBindable.ValueChanged += e => | ||
{ | ||
if (e.OldValue != null) | ||
{ | ||
e.OldValue.Changed -= invalidate; | ||
} | ||
|
||
if (e.NewValue != null) | ||
{ | ||
e.NewValue.Changed += invalidate; | ||
} | ||
|
||
void invalidate() => ReferenceLyricConfigVersion.Value++; | ||
}; | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
osu.Game.Rulesets.Karaoke/Objects/Properties/IReferenceLyricPropertyConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Objects.Properties | ||
{ | ||
public interface IReferenceLyricPropertyConfig | ||
{ | ||
double OffsetTime { get; set; } | ||
|
||
public event Action? Changed; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
osu.Game.Rulesets.Karaoke/Objects/Properties/ReferenceLyricConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
// 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 Newtonsoft.Json; | ||
using osu.Framework.Bindables; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Objects.Properties | ||
{ | ||
public class ReferenceLyricConfig : IReferenceLyricPropertyConfig | ||
{ | ||
public event Action? Changed; | ||
|
||
public ReferenceLyricConfig() | ||
{ | ||
OffsetTimeBindable.ValueChanged += _ => Changed?.Invoke(); | ||
} | ||
|
||
[JsonIgnore] | ||
public readonly Bindable<double> OffsetTimeBindable = new BindableDouble(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 System.Text.Json.Serialization; | ||
using osu.Framework.Bindables; | ||
|
@@ -9,6 +10,15 @@ namespace osu.Game.Rulesets.Karaoke.Objects.Properties | |
{ | ||
public class SyncLyricConfig : IReferenceLyricPropertyConfig | ||
{ | ||
public event Action? Changed; | ||
|
||
public SyncLyricConfig() | ||
{ | ||
OffsetTimeBindable.ValueChanged += _ => Changed?.Invoke(); | ||
SyncSingerPropertyBindable.ValueChanged += _ => Changed?.Invoke(); | ||
SyncTimeTagPropertyBindable.ValueChanged += _ => Changed?.Invoke(); | ||
} | ||
|
||
[JsonIgnore] | ||
public readonly Bindable<double> OffsetTimeBindable = new BindableDouble(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.