diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Stages/StageElementCategoryChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Stages/StageElementCategoryChangeHandlerTest.cs index 9089a0b91..804b85012 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Stages/StageElementCategoryChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Stages/StageElementCategoryChangeHandlerTest.cs @@ -119,49 +119,6 @@ public void TestAddToMapping() }); } - [Test] - public void TestOffsetMapping() - { - Lyric lyric = new Lyric(); - Lyric unSelectedLyric = new Lyric(); - - SetUpStageInfo(stageInfo => - { - var category = stageInfo.Category; - var element = category.AddElement(x => x.Name = "Element 1"); - category.AddElement(x => x.Name = "Element 2"); - - // Add to Mapping - category.AddToMapping(element, lyric); - category.AddToMapping(element, unSelectedLyric); - }); - - PrepareHitObject(() => lyric); - PrepareHitObject(() => unSelectedLyric, false); - - TriggerHandlerChanged(c => - { - c.OffsetMapping(1); - }); - - AssertStageInfo(stageInfo => - { - var category = stageInfo.Category; - - Assert.AreEqual("Element 2", category.GetElementByItem(lyric).Name); - Assert.AreEqual("Element 1", category.GetElementByItem(unSelectedLyric).Name); // should not change the id if lyric is not selected. - }); - } - - [Test] - public void TestOffsetMappingWithZeroValue() - { - PrepareHitObject(() => new Lyric()); - - // offset value should not be zero. - TriggerHandlerChangedWithException(c => c.OffsetMapping(0)); - } - [Test] public void TestRemoveFromMapping() { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Stages/BaseStageElementCategoryGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Stages/BaseStageElementCategoryGeneratorTest.cs index e147cd415..d3b017f5f 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Stages/BaseStageElementCategoryGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Stages/BaseStageElementCategoryGeneratorTest.cs @@ -15,14 +15,14 @@ public abstract class BaseLyricStageElementCategoryGeneratorTest where TGenerator : StageInfoPropertyGenerator where TObject : StageElementCategory - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where TConfig : GeneratorConfig, new(); public abstract class BaseStageElementCategoryGeneratorTest : BaseStageInfoPropertyGeneratorTest where TGenerator : StageInfoPropertyGenerator where TObject : StageElementCategory - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where THitObject : KaraokeHitObject, IHasPrimaryKey where TConfig : GeneratorConfig, new() { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Stages/Infos/StageElementCategoryTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Stages/Infos/StageElementCategoryTest.cs index 619b564dc..9d47b6937 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Stages/Infos/StageElementCategoryTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Stages/Infos/StageElementCategoryTest.cs @@ -226,20 +226,6 @@ public void TestGetHitObjectIdsByElement() Assert.IsEmpty(category.GetHitObjectIdsByElement(defaultElement)); } - [Test] - public void TestGetElementOrder() - { - var category = new TestStageElementCategory(); - var element = category.AddElement(); - - int? existElementOrder = category.GetElementOrder(element); - Assert.AreEqual(1, existElementOrder); - - var notExistElement = new TestStageElement(); - int? notExistElementOrder = category.GetElementOrder(notExistElement); - Assert.IsNull(notExistElementOrder); - } - #endregion private class TestStageElement : StageElement, IComparable diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/IStageElementCategoryChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/IStageElementCategoryChangeHandler.cs index 77a84c4ed..237909497 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/IStageElementCategoryChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/IStageElementCategoryChangeHandler.cs @@ -18,8 +18,6 @@ public interface IStageElementCategoryChangeHandler void AddToMapping(TStageElement element); - void OffsetMapping(int offset); - void RemoveFromMapping(); void ClearUnusedMapping(); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/StageElementCategoryChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/StageElementCategoryChangeHandler.cs index 03d1bbb3a..d86614b3f 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/StageElementCategoryChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Stages/StageElementCategoryChangeHandler.cs @@ -56,31 +56,6 @@ public void AddToMapping(TStageElement element) }); } - public void OffsetMapping(int offset) - { - if (offset == 0) - throw new InvalidOperationException("Offset number should not be zero."); - - PerformOnSelection(hitObject => - { - performStageInfoChanged(s => - { - var element = s.GetElementByItem(hitObject); - int mappingIndex = s.SortedElements.IndexOf(element); - if (mappingIndex < 0) - return; - - int newMappingIndex = mappingIndex + offset; - var newElement = s.SortedElements.ElementAtOrDefault(newMappingIndex); - if (newElement == null) - return; - - s.RemoveHitObjectFromMapping(hitObject); - s.AddToMapping(newElement, hitObject); - }); - }); - } - public void RemoveFromMapping() { PerformOnSelection(hitObject => diff --git a/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckStageInfo.cs b/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckStageInfo.cs index 3123c228a..18ee2a131 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckStageInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckStageInfo.cs @@ -34,7 +34,7 @@ private readonly IList, IEnumer = new List, IEnumerable>>(); public void RegisterCategory(Func> categoryAction, int minimumRequiredElements) - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where THitObject : KaraokeHitObject, IHasPrimaryKey { stageInfoCategoryActions.Add((info, hitObjects) => @@ -46,7 +46,7 @@ public void RegisterCategory(Func checkElementCategory(StageElementCategory category, IReadOnlyList hitObjects, int minimumRequiredElements) - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where THitObject : KaraokeHitObject, IHasPrimaryKey { // check mapping. @@ -68,7 +68,7 @@ private IEnumerable checkElementCategory(Stage } private IEnumerable checkMappings(StageElementCategory category, IReadOnlyList hitObjects) - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where THitObject : KaraokeHitObject, IHasPrimaryKey { var elements = category.AvailableElements; diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicLyricLayout.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicLyricLayout.cs index df524fee0..d8680c3b4 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicLyricLayout.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicLyricLayout.cs @@ -1,15 +1,13 @@ // Copyright (c) andy840119 . 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; using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Stages.Infos.Classic; -public class ClassicLyricLayout : StageElement, IComparable +public class ClassicLyricLayout : StageElement { [JsonIgnore] public readonly Bindable AlignmentBindable = new(ClassicLyricLayoutAlignment.Center); @@ -20,11 +18,7 @@ public class ClassicLyricLayout : StageElement, IComparable public ClassicLyricLayoutAlignment Alignment { get => AlignmentBindable.Value; - set - { - AlignmentBindable.Value = value; - TriggerOrderVersionChanged(); - } + set => AlignmentBindable.Value = value; } [JsonIgnore] @@ -36,11 +30,7 @@ public ClassicLyricLayoutAlignment Alignment public float HorizontalMargin { get => HorizontalMarginBindable.Value; - set - { - HorizontalMarginBindable.Value = value; - TriggerOrderVersionChanged(); - } + set => HorizontalMarginBindable.Value = value; } [JsonIgnore] @@ -53,19 +43,6 @@ public float HorizontalMargin public int Line { get => LineBindable.Value; - set - { - LineBindable.Value = value; - TriggerOrderVersionChanged(); - } - } - - public int CompareTo(ClassicLyricLayout? other) - { - return ComparableUtils.CompareByProperty(this, other, - x => x.Line, - x => x.Alignment, - x => x.HorizontalMargin, - x => x.ID); + set => LineBindable.Value = value; } } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStageInfo.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStageInfo.cs index 54792e624..5eb93de3b 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStageInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStageInfo.cs @@ -11,17 +11,17 @@ public class ClassicStageInfo : StageInfo { #region Category - /// - /// Category to save the 's and 's style. - /// - public ClassicStyleCategory StyleCategory { get; set; } = new(); - /// /// The definition for the .
/// Like the line height or font size. ///
public ClassicStageDefinition StageDefinition { get; set; } = new(); + /// + /// Category to save the 's and 's style. + /// + public ClassicStyleCategory StyleCategory { get; set; } = new(); + /// /// Category to save the 's layout. /// diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStyle.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStyle.cs index 76b36789d..51c54f8cd 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStyle.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Classic/ClassicStyle.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Infos.Classic; -public class ClassicStyle : StageElement, IComparable +public class ClassicStyle : StageElement { [JsonIgnore] public readonly Bindable LyricStyleIndexBindable = new(); @@ -34,11 +34,4 @@ public int? NoteStyleIndex get => NoteStyleIndexBindable.Value; set => NoteStyleIndexBindable.Value = value; } - - public int CompareTo(ClassicStyle? other) - { - return ComparableUtils.CompareByProperty(this, other, - x => x.Name, - x => x.ID); - } } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewLyricLayout.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewLyricLayout.cs index b36ae19aa..fbf9b51ab 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewLyricLayout.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewLyricLayout.cs @@ -1,14 +1,12 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Stages.Infos.Preview; -public class PreviewLyricLayout : StageElement, IComparable +public class PreviewLyricLayout : StageElement { /// /// 's timing with row index. @@ -24,10 +22,4 @@ public class PreviewLyricLayout : StageElement, IComparable /// 's end time. /// public double EndTime { get; set; } - - public int CompareTo(PreviewLyricLayout? other) - { - return ComparableUtils.CompareByProperty(this, other, - x => x.ID); - } } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStageInfo.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStageInfo.cs index 1b81a3080..ebe693113 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStageInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStageInfo.cs @@ -16,20 +16,22 @@ public class PreviewStageInfo : StageInfo, IHasCalculatedProperty { #region Category - /// - /// Category to save the 's and 's style. - /// - [JsonIgnore] - private PreviewStyleCategory styleCategory { get; set; } = new(); - /// /// The definition for the . /// Like how many lyrics can in the playfield at the same time. /// public PreviewStageDefinition StageDefinition { get; set; } = new(); + /// + /// Category to save the 's and 's style. + /// This property will not be saved because it's real-time calculated. + /// + [JsonIgnore] + private PreviewStyleCategory styleCategory { get; set; } = new(); + /// /// Category to save the 's layout. + /// This property will not be saved because it's real-time calculated. /// [JsonIgnore] private PreviewLyricLayoutCategory layoutCategory { get; set; } = new(); @@ -38,32 +40,12 @@ public class PreviewStageInfo : StageInfo, IHasCalculatedProperty #region Validation - private bool calculatedPropertyIsUpdated; - - /// - /// Mark the stage info's calculated property as invalidate. - /// - /// - public void TriggerRecalculate() - { - calculatedPropertyIsUpdated = false; - } - - /// - /// Check if the stage info's calculated property is calculated and the value is the latest. - /// - /// - public bool IsUpdated() => calculatedPropertyIsUpdated; - /// /// If the calculated property is not updated, then re-calculate the property inside the stage info in the /// /// public void ValidateCalculatedProperty(IBeatmap beatmap) { - if (IsUpdated()) - return; - var calculator = new PreviewStageTimingCalculator(beatmap, StageDefinition); // also, clear all mapping in the layout and re-create one. @@ -83,8 +65,6 @@ public void ValidateCalculatedProperty(IBeatmap beatmap) }); layoutCategory.AddToMapping(element, lyric); } - - calculatedPropertyIsUpdated = true; } #endregion diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStyle.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStyle.cs index dcf598bbf..9551edd61 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStyle.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Preview/PreviewStyle.cs @@ -1,13 +1,11 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Stages.Infos.Preview; -public class PreviewStyle : StageElement, IComparable +public class PreviewStyle : StageElement { /// /// 's skin lookup index. @@ -18,11 +16,4 @@ public class PreviewStyle : StageElement, IComparable /// 's skin lookup index. /// public int? NoteStyleIndex { get; set; } - - public int CompareTo(PreviewStyle? other) - { - return ComparableUtils.CompareByProperty(this, other, - x => x.Name, - x => x.ID); - } } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElement.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElement.cs index 0295e75d8..c2fc7682c 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElement.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElement.cs @@ -9,10 +9,6 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Infos; public abstract class StageElement : IHasPrimaryKey { - private readonly Bindable orderVersion = new(); - - public IBindable OrderVersion => orderVersion; - /// /// Index of the element. /// @@ -30,9 +26,4 @@ public string Name get => NameBindable.Value; set => NameBindable.Value = value; } - - protected void TriggerOrderVersionChanged() - { - orderVersion.Value++; - } } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElementCategory.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElementCategory.cs index ea38c583e..7283fdcb0 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElementCategory.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/StageElementCategory.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; -using System.Diagnostics; using System.Linq; -using Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Objects; @@ -14,10 +11,11 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Infos; /// -/// It's a category to record the list of and handle the mapping by several rules. +/// It's a category to record the list of and handle the mapping by default role.
+/// Can add more customised role by inherit this class.
///
public abstract class StageElementCategory - where TStageElement : StageElement, IComparable, new() + where TStageElement : StageElement, new() where THitObject : KaraokeHitObject, IHasPrimaryKey { /// @@ -26,19 +24,11 @@ public abstract class StageElementCategory /// public TStageElement DefaultElement { get; protected set; } - [JsonIgnore] - public IBindable ElementsVersion => elementsVersion; - - private readonly Bindable elementsVersion = new(); - /// /// All available elements. /// public BindableList AvailableElements { get; protected set; } = new(); - [JsonIgnore] - public List SortedElements { get; private set; } = new(); - /// /// Mapping between and
/// This is the 1st mapping roles. @@ -48,37 +38,6 @@ public abstract class StageElementCategory protected StageElementCategory() { DefaultElement = new TStageElement(); - - AvailableElements.CollectionChanged += (_, args) => - { - switch (args.Action) - { - case NotifyCollectionChangedAction.Add: - Debug.Assert(args.NewItems != null); - - foreach (var c in args.NewItems.Cast()) - c.OrderVersion.ValueChanged += orderValueChanged; - break; - - case NotifyCollectionChangedAction.Reset: - case NotifyCollectionChangedAction.Remove: - Debug.Assert(args.OldItems != null); - - foreach (var c in args.OldItems.Cast()) - c.OrderVersion.ValueChanged -= orderValueChanged; - break; - } - - onElementOrderChanged(); - - void orderValueChanged(ValueChangedEvent e) => onElementOrderChanged(); - }; - - void onElementOrderChanged() - { - SortedElements = AvailableElements.OrderBy(x => x).ToList(); - elementsVersion.Value++; - } } #region Edit @@ -111,13 +70,13 @@ public void RemoveElement(TStageElement element) AvailableElements.Remove(element); } - public void ClearElements() + public virtual void ClearElements() { Mappings.Clear(); AvailableElements.Clear(); } - public void AddToMapping(TStageElement element, THitObject hitObject) + public virtual void AddToMapping(TStageElement element, THitObject hitObject) { var key = hitObject.ID; var value = element.ID; @@ -134,12 +93,12 @@ public void AddToMapping(TStageElement element, THitObject hitObject) } } - public void RemoveHitObjectFromMapping(THitObject hitObject) + public virtual void RemoveHitObjectFromMapping(THitObject hitObject) { Mappings.Remove(hitObject.ID); } - public void RemoveElementFromMapping(TStageElement element) + public virtual void RemoveElementFromMapping(TStageElement element) { var objectIds = getMappingHitObjectIds(element); @@ -152,7 +111,7 @@ IEnumerable getMappingHitObjectIds(TStageElement stageElement) => Mappings.Where(x => x.Value == stageElement.ID).Select(x => x.Key).ToArray(); } - public void ClearUnusedMapping(Func checkExist) + public virtual void ClearUnusedMapping(Func checkExist) { var unusedIds = Mappings.Select(x => x.Key).Where(x => !checkExist(x)); @@ -166,7 +125,7 @@ public void ClearUnusedMapping(Func checkExist) #region Query - public TStageElement GetElementByItem(THitObject hitObject) + public virtual TStageElement GetElementByItem(THitObject hitObject) { var id = hitObject.ID; @@ -177,16 +136,10 @@ public TStageElement GetElementByItem(THitObject hitObject) return matchedElements ?? DefaultElement; } - public IEnumerable GetHitObjectIdsByElement(TStageElement element) + public virtual IEnumerable GetHitObjectIdsByElement(TStageElement element) { return Mappings.Where(x => x.Value == element.ID).Select(x => x.Key); } - public int? GetElementOrder(TStageElement element) - { - int index = SortedElements.IndexOf(element); - return index == -1 ? null : index + 1; - } - #endregion } diff --git a/osu.Game.Rulesets.Karaoke/Stages/Infos/Types/IHasCalculatedProperty.cs b/osu.Game.Rulesets.Karaoke/Stages/Infos/Types/IHasCalculatedProperty.cs index cf0160edf..81f43ccce 100644 --- a/osu.Game.Rulesets.Karaoke/Stages/Infos/Types/IHasCalculatedProperty.cs +++ b/osu.Game.Rulesets.Karaoke/Stages/Infos/Types/IHasCalculatedProperty.cs @@ -8,18 +8,6 @@ namespace osu.Game.Rulesets.Karaoke.Stages.Infos.Types; public interface IHasCalculatedProperty { - /// - /// Mark the stage info's calculated property as invalidate. - /// - /// - void TriggerRecalculate(); - - /// - /// Check if the stage info's calculated property is calculated and the value is the latest. - /// - /// - bool IsUpdated(); - /// /// If the calculated property is not updated, then re-calculate the property inside the stage info in the ///