From d0174bbf869a3d6af98a5909483406cc3b3c5058 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 30 Mar 2026 10:58:26 +0800 Subject: [PATCH] fix: fix build issue and tas seq refactor issue --- .../BallanceTasEditor/Backend/TasSequence.cs | 38 ++++++++++--------- .../BallanceTasEditor.csproj | 6 ++- .../Frontend/ViewModels/NewFileDialog.cs | 28 +++++++------- .../Backend/TasSequenceTests.cs | 25 ++++++------ 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/BallanceTasEditor/BallanceTasEditor/Backend/TasSequence.cs b/BallanceTasEditor/BallanceTasEditor/Backend/TasSequence.cs index d329184..6ed4971 100644 --- a/BallanceTasEditor/BallanceTasEditor/Backend/TasSequence.cs +++ b/BallanceTasEditor/BallanceTasEditor/Backend/TasSequence.cs @@ -27,7 +27,7 @@ namespace BallanceTasEditor.Backend { /// /// 要访问的单元的索引。 /// 被访问的单元。 - /// 给定的索引无效。 + /// 给定的索引无效。 TasFrame Visit(int index); /// /// 在给定的帧索引之前插入给定的项目。 @@ -43,7 +43,7 @@ namespace BallanceTasEditor.Backend { /// /// 要在前方插入数据的元素的索引。 /// 要插入的元素的迭代器。 - /// 给定的索引无效。 + /// 给定的索引无效。 void Insert(int index, IExactSizeEnumerable items); /// /// 从序列中移出给定帧区间的元素。 @@ -55,7 +55,7 @@ namespace BallanceTasEditor.Backend { /// /// 要移除的帧区间的起始索引(包含)。 /// 要移除的帧区间的终止索引(包含) - /// 给定的索引无效。 + /// 给定的索引无效。 void Remove(int startIndex, int endIndex); /// @@ -159,7 +159,7 @@ namespace BallanceTasEditor.Backend { if (endIndex < startIndex || startIndex < 0 || endIndex >= m_Container.Count) { throw new IndexOutOfRangeException("Invalid index for frame."); } else { - m_Container.RemoveRange(startIndex, endIndex - startIndex); + m_Container.RemoveRange(startIndex, endIndex - startIndex + 1); } } @@ -277,20 +277,22 @@ namespace BallanceTasEditor.Backend { } public void Insert(int index, IExactSizeEnumerable items) { - if (index >= m_Container.Count || index < 0) { - throw new IndexOutOfRangeException("Invalid index for frame."); - } else { - if (index == m_Container.Count) { - foreach (TasFrame item in items) { - m_Container.AddLast(item); - } + // YYC MARK: + // We must test the equal first, to handle back appending properly. + if (index == m_Container.Count) { + foreach (TasFrame item in items) { + m_Container.AddLast(item); + } - var pendingCursor = m_Container.First; - if (pendingCursor is null) { - m_Cursor = null; - } else { - m_Cursor = new LinkedListCursor(pendingCursor, 0); - } + var pendingCursor = m_Container.First; + if (pendingCursor is null) { + m_Cursor = null; + } else { + m_Cursor = new LinkedListCursor(pendingCursor, 0); + } + } else { + if (index >= m_Container.Count || index < 0) { + throw new IndexOutOfRangeException("Invalid index for frame."); } else { MoveToIndex(index); @@ -308,7 +310,7 @@ namespace BallanceTasEditor.Backend { } // Compute count and move to index. - var count = endIndex - startIndex; + var count = endIndex - startIndex + 1; MoveToIndex(startIndex); // 我们总是获取要删除的项目的前一项来作为参照。 diff --git a/BallanceTasEditor/BallanceTasEditor/BallanceTasEditor.csproj b/BallanceTasEditor/BallanceTasEditor/BallanceTasEditor.csproj index 5aab69b..2b02ccc 100644 --- a/BallanceTasEditor/BallanceTasEditor/BallanceTasEditor.csproj +++ b/BallanceTasEditor/BallanceTasEditor/BallanceTasEditor.csproj @@ -5,7 +5,7 @@ net8.0-windows enable true - Assets\App.ico + Frontend\Assets\App.ico app.manifest @@ -13,6 +13,10 @@ + + + + diff --git a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/NewFileDialog.cs b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/NewFileDialog.cs index ab3b928..31bd49f 100644 --- a/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/NewFileDialog.cs +++ b/BallanceTasEditor/BallanceTasEditor/Frontend/ViewModels/NewFileDialog.cs @@ -44,21 +44,21 @@ namespace BallanceTasEditor.Frontend.ViewModels { // 就直接把string绑定到TextBox.Text上,然后再辅以我自己定义的一套可复用验证逻辑。 [ObservableProperty] - [CustomValidation(typeof(NewFileDialog), nameof(ValidateCount))] + //[CustomValidation(typeof(NewFileDialog), nameof(ValidateCount))] [NotifyCanExecuteChangedFor(nameof(OkCommand))] private string count; [ObservableProperty] - [CustomValidation(typeof(NewFileDialog), nameof(ValidateFps))] + //[CustomValidation(typeof(NewFileDialog), nameof(ValidateFps))] [NotifyCanExecuteChangedFor(nameof(OkCommand))] private string fps; - public static ValidationResult ValidateCount(string count, ValidationContext context) { - return CountValidator.Instance.Validate(count); - } - public static ValidationResult ValidateFps(string fps, ValidationContext context) { - return FpsValidator.Instance.Validate(fps); - } + //public static ValidationResult ValidateCount(string count, ValidationContext context) { + // return CountValidator.Instance.Validate(count); + //} + //public static ValidationResult ValidateFps(string fps, ValidationContext context) { + // return FpsValidator.Instance.Validate(fps); + //} [RelayCommand(CanExecute = nameof(CanOk))] private void Ok() { @@ -73,12 +73,12 @@ namespace BallanceTasEditor.Frontend.ViewModels { } - public NewFileDialogResult ToResult() { - return new NewFileDialogResult { - Count = CountValidator.Instance.Fetch(Count), - DeltaTime = FpsConverter.ToDelta(FpsValidator.Instance.Fetch(Fps)), - }; - } + //public NewFileDialogResult ToResult() { + // return new NewFileDialogResult { + // Count = CountValidator.Instance.Fetch(Count), + // DeltaTime = FpsConverter.ToDelta(FpsValidator.Instance.Fetch(Fps)), + // }; + //} } } diff --git a/BallanceTasEditor/BallanceTasEditorTests/Backend/TasSequenceTests.cs b/BallanceTasEditor/BallanceTasEditorTests/Backend/TasSequenceTests.cs index f22d162..36ab806 100644 --- a/BallanceTasEditor/BallanceTasEditorTests/Backend/TasSequenceTests.cs +++ b/BallanceTasEditor/BallanceTasEditorTests/Backend/TasSequenceTests.cs @@ -44,18 +44,18 @@ namespace BallanceTasEditorTests.Backend { [DynamicData(nameof(TasSequenceInstanceProvider))] public void VisitTest(ITasSequence sequence) { // 空时访问 - AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); - AssertExtension.ThrowsDerivedException(() => sequence.Visit(0)); - AssertExtension.ThrowsDerivedException(() => sequence.Visit(1)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(0)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(1)); // 设置数据 sequence.Insert(0, GetExactSizeProbe()); // 访问数据 - AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); for (int i = 0; i < PROBE.Length; i++) { Assert.AreEqual(sequence.Visit(i), PROBE[i]); } - AssertExtension.ThrowsDerivedException(() => sequence.Visit(PROBE.Length)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(PROBE.Length)); } /// @@ -68,8 +68,8 @@ namespace BallanceTasEditorTests.Backend { // 和在非空时的头,中,尾分别插入的结果。 // 先检测空插入 - AssertExtension.ThrowsDerivedException(() => sequence.Insert(-1, GetExactSizeProbe())); - AssertExtension.ThrowsDerivedException(() => sequence.Insert(1, GetExactSizeProbe())); + AssertExtension.ThrowsDerivedException(() => sequence.Insert(-1, GetExactSizeProbe())); + AssertExtension.ThrowsDerivedException(() => sequence.Insert(1, GetExactSizeProbe())); sequence.Insert(0, GetExactSizeProbe()); for (int i = 0; i < PROBE.Length; i++) { Assert.AreEqual(sequence.Visit(i), PROBE[i]); @@ -103,16 +103,13 @@ namespace BallanceTasEditorTests.Backend { [DataTestMethod] [DynamicData(nameof(TasSequenceInstanceProvider))] public void RemoveTest(ITasSequence sequence) { - // 在空的时候删除0项 - sequence.Remove(0, 0); - // 插入项目后尝试在头中尾分别删除 var indices = new int[] { 0, PROBE.Length / 2, PROBE.Length - 1 }; foreach (var index in indices) { // 清空,插入,删除 sequence.Clear(); sequence.Insert(0, GetExactSizeProbe()); - sequence.Remove(index, 1); + sequence.Remove(index, index); // 用List做正确模拟 var expected = new List(); @@ -201,9 +198,9 @@ namespace BallanceTasEditorTests.Backend { // 清空后插入0项,然后确认 sequence.Clear(); sequence.Insert(0, GetExactSizeBlank()); - AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); - AssertExtension.ThrowsDerivedException(() => sequence.Visit(0)); - AssertExtension.ThrowsDerivedException(() => sequence.Visit(1)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(-1)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(0)); + AssertExtension.ThrowsDerivedException(() => sequence.Visit(1)); } } }