1
0

fix: fix build issue and tas seq refactor issue

This commit is contained in:
2026-03-30 10:58:26 +08:00
parent 530dc2a76e
commit d0174bbf86
4 changed files with 50 additions and 47 deletions

View File

@@ -27,7 +27,7 @@ namespace BallanceTasEditor.Backend {
/// </remarks>
/// <param name="index">要访问的单元的索引。</param>
/// <returns>被访问的单元。</returns>
/// <exception cref="ArgumentOutOfRangeException">给定的索引无效。</exception>
/// <exception cref="IndexOutOfRangeException">给定的索引无效。</exception>
TasFrame Visit(int index);
/// <summary>
/// 在给定的帧索引<b>之前</b>插入给定的项目。
@@ -43,7 +43,7 @@ namespace BallanceTasEditor.Backend {
/// </remarks>
/// <param name="index">要在前方插入数据的元素的索引。</param>
/// <param name="items">要插入的元素的迭代器。</param>
/// <exception cref="ArgumentOutOfRangeException">给定的索引无效。</exception>
/// <exception cref="IndexOutOfRangeException">给定的索引无效。</exception>
void Insert(int index, IExactSizeEnumerable<TasFrame> items);
/// <summary>
/// 从序列中移出给定帧区间的元素。
@@ -55,7 +55,7 @@ namespace BallanceTasEditor.Backend {
/// </remarks>
/// <param name="startIndex">要移除的帧区间的起始索引(包含)。</param>
/// <param name="endIndex">要移除的帧区间的终止索引(包含)</param>
/// <exception cref="ArgumentOutOfRangeException">给定的索引无效。</exception>
/// <exception cref="IndexOutOfRangeException">给定的索引无效。</exception>
void Remove(int startIndex, int endIndex);
/// <summary>
@@ -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<TasFrame> 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<TasFrame>(pendingCursor, 0);
}
var pendingCursor = m_Container.First;
if (pendingCursor is null) {
m_Cursor = null;
} else {
m_Cursor = new LinkedListCursor<TasFrame>(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);
// 我们总是获取要删除的项目的前一项来作为参照。

View File

@@ -5,7 +5,7 @@
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<ApplicationIcon>Assets\App.ico</ApplicationIcon>
<ApplicationIcon>Frontend\Assets\App.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
@@ -13,6 +13,10 @@
<Resource Include="Frontend\Assets\*.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Frontend\Assets\App.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />

View File

@@ -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)),
// };
//}
}
}

View File

@@ -44,18 +44,18 @@ namespace BallanceTasEditorTests.Backend {
[DynamicData(nameof(TasSequenceInstanceProvider))]
public void VisitTest(ITasSequence sequence) {
// 空时访问
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(0));
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(-1));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(0));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(1));
// 设置数据
sequence.Insert(0, GetExactSizeProbe());
// 访问数据
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(-1));
for (int i = 0; i < PROBE.Length; i++) {
Assert.AreEqual(sequence.Visit(i), PROBE[i]);
}
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(PROBE.Length));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(PROBE.Length));
}
/// <summary>
@@ -68,8 +68,8 @@ namespace BallanceTasEditorTests.Backend {
// 和在非空时的头,中,尾分别插入的结果。
// 先检测空插入
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(-1, GetExactSizeProbe()));
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Insert(1, GetExactSizeProbe()));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Insert(-1, GetExactSizeProbe()));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => 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<TasFrame>();
@@ -201,9 +198,9 @@ namespace BallanceTasEditorTests.Backend {
// 清空后插入0项然后确认
sequence.Clear();
sequence.Insert(0, GetExactSizeBlank());
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(-1));
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(0));
AssertExtension.ThrowsDerivedException<ArgumentException>(() => sequence.Visit(1));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(-1));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(0));
AssertExtension.ThrowsDerivedException<IndexOutOfRangeException>(() => sequence.Visit(1));
}
}
}