Compare commits
18 Commits
9d41119710
...
ng
| Author | SHA1 | Date | |
|---|---|---|---|
| 802c258a99 | |||
| 8f1b7cc196 | |||
| b16c7508f0 | |||
| 590645b13c | |||
| 84897a409b | |||
| 5323617ca6 | |||
| 0e9837a75a | |||
| 87e6c63aae | |||
| 85fc2ad3ce | |||
| 06482e2218 | |||
| c42305c8d2 | |||
| 49940b43d5 | |||
| 941e59e471 | |||
| ab5a68bed7 | |||
| 4aaf64eae5 | |||
| eb40906975 | |||
| ee6a565ce0 | |||
| 334accd070 |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
44
BallanceTasEditor/Assets/AppIcons/ClearKeys.svg
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
sodipodi:docname="ClearKeys.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="32.916667"
|
||||
inkscape:cx="12"
|
||||
inkscape:cy="12"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1017"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg1" />
|
||||
<path
|
||||
d="m 19.36,2.72 1.42,1.42 -5.72,5.71 c 1.07,1.54 1.22,3.39 0.32,4.59 L 9.06,8.12 c 1.2,-0.9 3.05,-0.75 4.59,0.32 L 19.36,2.72 M 5.93,17.57 C 3.92,15.56 2.69,13.16 2.35,10.92 l 4.88,-2.09 7.44,7.44 -2.09,4.88 C 10.34,20.81 7.94,19.58 5.93,17.57 Z"
|
||||
id="path1"
|
||||
style="display:none" />
|
||||
<path
|
||||
style="fill:#607d8b;stroke-width:0.000911392;fill-opacity:1"
|
||||
d="M 12.136709,21.054947 C 9.849802,20.570498 7.6401138,19.296543 5.8025316,17.403096 4.4028758,15.960889 3.3992023,14.37058 2.7993906,12.644655 2.6463627,12.204326 2.4273042,11.35402 2.3985171,11.088608 L 2.3803943,10.921519 4.7251585,9.9189873 C 6.0147788,9.3675949 7.1043011,8.9044989 7.1463187,8.8898851 c 0.071606,-0.024904 0.3085786,0.2056059 3.7789633,3.6759029 2.036411,2.03636 3.702566,3.714727 3.702566,3.729703 0,0.01498 -0.461067,1.105251 -1.024592,2.422831 l -1.024593,2.395602 -0.09186,-0.0021 c -0.05053,-0.0012 -0.208066,-0.02675 -0.350091,-0.05684 z"
|
||||
id="path2" />
|
||||
<path
|
||||
style="fill:#607d8b;fill-opacity:1;stroke-width:0.000911392"
|
||||
d="M 12.228787,11.256636 9.0890771,8.1168152 9.262956,8.0055861 c 0.537045,-0.3435433 1.29721,-0.5112188 2.003468,-0.4419202 0.416509,0.040868 0.869029,0.1466631 1.241447,0.2902384 0.298885,0.1152267 0.773018,0.3576119 0.98551,0.5038104 0.07023,0.04832 0.138874,0.087855 0.152539,0.087855 0.01366,0 1.306513,-1.281613 2.872996,-2.8480292 l 2.84815,-2.8480293 0.691078,0.6910787 0.691079,0.6910786 -2.855424,2.8555452 C 15.12356,9.75757 15.039674,9.8448024 15.081906,9.911253 c 0.598284,0.941377 0.857172,1.729415 0.860857,2.620393 0.002,0.475353 -0.04848,0.782692 -0.194207,1.183063 -0.08105,0.222676 -0.299494,0.631956 -0.355907,0.666821 -0.01328,0.0082 -1.437021,-1.397993 -3.163862,-3.124894 z"
|
||||
id="path3" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
@@ -1,4 +1,8 @@
|
||||
using System.Configuration;
|
||||
// Import LanguageExt globally
|
||||
global using LanguageExt;
|
||||
global using static LanguageExt.Prelude;
|
||||
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
BIN
BallanceTasEditor/BallanceTasEditor/Assets/ClearKeys.ico
Normal file
|
After Width: | Height: | Size: 108 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
@@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ApplicationIcon>Assets\App.ico</ApplicationIcon>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
@@ -15,6 +16,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
||||
<PackageReference Include="DotNetZip" Version="1.9.1.8" />
|
||||
<PackageReference Include="LanguageExt.Core" Version="4.4.9" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace BallanceTasEditor.Converters {
|
||||
[ValueConversion(typeof(int), typeof(string))]
|
||||
public class FpsConverter : IValueConverter {
|
||||
public static FpsConverter Instance = new FpsConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is int tv) {
|
||||
if (tv <= 0) return DependencyProperty.UnsetValue;
|
||||
else return Utils.FpsConverter.ToDelta(tv).ToString();
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将IsEnable转换为Visibility。
|
||||
/// </summary>
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class VisibilityConverter : IValueConverter {
|
||||
public static VisibilityConverter Instance = new VisibilityConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is bool bv) {
|
||||
if (bv) return Visibility.Visible;
|
||||
else return Visibility.Collapsed;
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace BallanceTasEditor.Converters {
|
||||
|
||||
[ValueConversion(typeof(int?), typeof(string))]
|
||||
public class StringifyIntegerConverter : IValueConverter {
|
||||
public static StringifyIntegerConverter Instance = new StringifyIntegerConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is null) {
|
||||
return "";
|
||||
} else if (value is int iv) {
|
||||
return iv.ToString();
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is string s) {
|
||||
if (int.TryParse(s, out int iv)) return iv;
|
||||
else return null;
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BallanceTasEditor.Utils {
|
||||
/// <summary>
|
||||
/// 一种提前给定元素个数的的IEnumerable。
|
||||
/// </summary>
|
||||
public sealed class CountableEnumerable<T> {
|
||||
/// <summary>
|
||||
/// 以直接方式构建。
|
||||
/// </summary>
|
||||
/// <param name="enumerable">一个迭代器,其最多只能迭代给定次数。</param>
|
||||
/// <param name="count">迭代器会迭代的次数。</param>
|
||||
public CountableEnumerable(IEnumerable<T> enumerable, int count) {
|
||||
m_Inner = enumerable;
|
||||
m_Count = count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数组便捷构建。
|
||||
/// </summary>
|
||||
/// <param name="array">要使用的数组。</param>
|
||||
public CountableEnumerable(T[] array) {
|
||||
m_Inner = array;
|
||||
m_Count = array.Length;
|
||||
}
|
||||
|
||||
private IEnumerable<T> m_Inner;
|
||||
private int m_Count;
|
||||
|
||||
/// <summary>
|
||||
/// 获取迭代器对象。
|
||||
/// </summary>
|
||||
/// <returns>用于迭代的迭代器。</returns>
|
||||
/// <exception cref="ArgumentException">当迭代器迭代次数与给定次数不匹配时。</exception>
|
||||
public IEnumerable<T> GetInner() {
|
||||
int counter = 0;
|
||||
foreach (var item in m_Inner) {
|
||||
if (counter >= m_Count) {
|
||||
throw new ArgumentException("Given IEnumerable<T> is not stopped at given count.");
|
||||
} else {
|
||||
yield return item;
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
|
||||
if (counter != m_Count) {
|
||||
throw new ArgumentException("Given IEnumerable<T> is not stopped at given count.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取该迭代器会迭代的次数。
|
||||
/// </summary>
|
||||
/// <returns>迭代器会迭代的次数,用于给使用该结构的方法提前分配必要的空间。</returns>
|
||||
public int GetCount() {
|
||||
return m_Count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
BallanceTasEditor/BallanceTasEditor/Utils/TasOperation.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BallanceTasEditor.Utils {
|
||||
|
||||
/// <summary>
|
||||
/// TAS操作接口。所有TAS操作均需要支持此接口。
|
||||
/// </summary>
|
||||
public interface ITasOperation {
|
||||
/// <summary>
|
||||
/// 执行对应的TAS操作。
|
||||
/// </summary>
|
||||
/// <param name="storage">所要操作的TAS存储容器。</param>
|
||||
void Execute(ITasStorage<TasFrame> storage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可撤销的TAS操作接口,所有可撤销的TAS操作均需支持此接口。
|
||||
/// </summary>
|
||||
public interface ITasRevocableOperation : ITasOperation {
|
||||
/// <summary>
|
||||
/// 撤销对应TAS操作。
|
||||
/// </summary>
|
||||
/// <param name="storage">所要撤销操作的TAS存储容器。</param>
|
||||
void Revoke(ITasStorage<TasFrame> storage);
|
||||
}
|
||||
|
||||
public enum CellKeysOperationKind {
|
||||
Set, Unset, Flip
|
||||
}
|
||||
|
||||
public class CellKeysOperation : ITasRevocableOperation {
|
||||
|
||||
private CellKeysOperationKind m_Kind;
|
||||
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Revoke(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class CellFpsOperation : ITasRevocableOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Revoke(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class RemoveFrameOperation : ITasRevocableOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Revoke(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class AddFrameOperation : ITasRevocableOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Revoke(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class InsertFrameOperation : ITasRevocableOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Revoke(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class ClearKeysOperation : ITasOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class UniformFpsOperation : ITasOperation {
|
||||
public void Execute(ITasStorage<TasFrame> storage) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace BallanceTasEditor.Utils {
|
||||
/// <param name="index">要在前方插入数据的元素的索引。</param>
|
||||
/// <param name="items">要插入的元素的迭代器。</param>
|
||||
/// <exception cref="ArgumentException">给定的索引超出范围。</exception>
|
||||
void Insert(int index, IEnumerable<T> items);
|
||||
void Insert(int index, CountableEnumerable<T> items);
|
||||
/// <summary>
|
||||
/// 从给定单元开始,移除给定个数的元素。
|
||||
/// </summary>
|
||||
@@ -70,7 +70,7 @@ namespace BallanceTasEditor.Utils {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Insert(int index, IEnumerable<T> items) {
|
||||
public void Insert(int index, CountableEnumerable<T> items) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ namespace BallanceTasEditor.Utils {
|
||||
return m_Container[index];
|
||||
}
|
||||
|
||||
public void Insert(int index, IEnumerable<T> items) {
|
||||
m_Container.InsertRange(index, items);
|
||||
public void Insert(int index, CountableEnumerable<T> items) {
|
||||
m_Container.InsertRange(index, items.GetInner());
|
||||
}
|
||||
|
||||
public void Remove(int index, int count) {
|
||||
@@ -219,11 +219,11 @@ namespace BallanceTasEditor.Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public void Insert(int index, IEnumerable<T> items) {
|
||||
public void Insert(int index, CountableEnumerable<T> items) {
|
||||
if (index < 0 || index > GetCount()) {
|
||||
throw new ArgumentOutOfRangeException("Index out of range.");
|
||||
} else if (index == GetCount()) {
|
||||
foreach (T item in items) {
|
||||
foreach (T item in items.GetInner()) {
|
||||
m_Container.AddLast(item);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace BallanceTasEditor.Utils {
|
||||
MoveToIndex(index);
|
||||
|
||||
int count = 0;
|
||||
foreach (T item in items) {
|
||||
foreach (T item in items.GetInner()) {
|
||||
m_Container.AddBefore(m_Cursor, item);
|
||||
++count;
|
||||
}
|
||||
97
BallanceTasEditor/BallanceTasEditor/Utils/Validator.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using LanguageExt.Common;
|
||||
using LanguageExt.TypeClasses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BallanceTasEditor.Utils {
|
||||
|
||||
// YYC MARK:
|
||||
// 这些验证器尽管服务于UI,但是并不遵循WPF或者CommunityToolkit.Mvvm的Validator模型,
|
||||
// 所以我把他们放在这里。
|
||||
|
||||
/// <summary>
|
||||
/// 验证器接口。
|
||||
/// </summary>
|
||||
/// <typeparam name="TIn">验证器接受的待验证数据的类型。</typeparam>
|
||||
/// <typeparam name="TOut">验证器验证完毕后,会输出的类型。</typeparam>
|
||||
public interface IValidator<TIn, TOut> {
|
||||
/// <summary>
|
||||
/// 验证给定数据是否正确。
|
||||
/// </summary>
|
||||
/// <param name="data">要验证的数据。</param>
|
||||
/// <returns>数据正确,或对应的错误信息。</returns>
|
||||
ValidationResult Validate(TIn data);
|
||||
|
||||
/// <summary>
|
||||
/// 获取验证无误数据转换后的数据。
|
||||
/// </summary>
|
||||
/// <param name="data">验证无误,用于获取输出的数据。</param>
|
||||
/// <returns>输出的数据。</returns>
|
||||
/// <exception cref="ArgumentException">给定数据验证时出现错误。</exception>
|
||||
TOut Fetch(TIn data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 以字符串呈现的数据的通用验证器
|
||||
/// </summary>
|
||||
public abstract class StringifiedValueValidator<T> : IValidator<string, T> where T : notnull {
|
||||
/// <summary>
|
||||
/// 用户需要实现的验证函数。
|
||||
/// </summary>
|
||||
/// <param name="stringifiedValue">要进行验证的数据。</param>
|
||||
/// <returns>验证完毕用于输出的数值,或者验证失败时的错误消息。</returns>
|
||||
protected abstract Either<T, string> ValidateValue(string stringifiedValue);
|
||||
|
||||
public ValidationResult Validate(string data) {
|
||||
return ValidateValue(data).Match(
|
||||
Left: (_) => ValidationResult.Success,
|
||||
Right: (v) => new ValidationResult(v)
|
||||
);
|
||||
}
|
||||
|
||||
public T Fetch(string data) {
|
||||
return ValidateValue(data).Match(
|
||||
Left: (v) => v,
|
||||
Right: (msg) => throw new ArgumentException($"Given value can not pass Validator due to {msg}.")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class IntegerValidator : StringifiedValueValidator<int> {
|
||||
protected override Either<int, string> ValidateValue(string stringifiedValue) {
|
||||
if (int.TryParse(stringifiedValue, out int val)) {
|
||||
return Left(val);
|
||||
} else {
|
||||
return Right("Given string do not represent any valid number.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FpsValidator : IntegerValidator {
|
||||
public static FpsValidator Instance = new FpsValidator();
|
||||
|
||||
protected override Either<int, string> ValidateValue(string stringifiedValue) {
|
||||
return base.ValidateValue(stringifiedValue).BindLeft<int>((v) => {
|
||||
if (v <= 0) return Right("Fps must be greater than zero.");
|
||||
else return Left(v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class CountValidator : IntegerValidator {
|
||||
public static FpsValidator Instance = new FpsValidator();
|
||||
|
||||
protected override Either<int, string> ValidateValue(string stringifiedValue) {
|
||||
return base.ValidateValue(stringifiedValue).BindLeft<int>((v) => {
|
||||
if (v < 0) return Right("Count can not lower than zero.");
|
||||
else return Left(v);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using BallanceTasEditor.Utils;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BallanceTasEditor.ViewModels {
|
||||
|
||||
public struct NewFileDialogResult {
|
||||
public int Count { get; set; }
|
||||
public float DeltaTime { get; set; }
|
||||
}
|
||||
|
||||
public partial class NewFileDialog : ObservableValidator {
|
||||
public NewFileDialog() {
|
||||
Count = 10000.ToString();
|
||||
// 132 or 264
|
||||
Fps = 264.ToString();
|
||||
}
|
||||
|
||||
// YYC MARK:
|
||||
// 经过无数次的尝试,我发现将int类型绑定到TextBox中所需要涉及的事情太多了,
|
||||
// 尤其是这种绑定到处存在于这个程序中,以至于每次都要重新写一遍。
|
||||
// 也许后面我会做一个只能接受数字输入的文本框,但现在我累了。
|
||||
//
|
||||
// 具体来说,事情是这样的。我一开始就是使用一个int类型的数据,
|
||||
// 然后按照CommunityToolkit.Mvvm的标准,将其应用了Required和Range Attribute,然后将其绑定到了TextBox的Text之上。
|
||||
// 然而最终的效果很奇怪,当我删除TextBox中的所有字符后,绑定什么也没做(后来我才知道要在Required里改一个选项)。
|
||||
// 其次,当我输入不被Range接受的数值时,它仍会将其同步绑定到属性上。比如我输入0,它仍会将其绑定到Fps上,
|
||||
// 进而导致Delta Time的转换显示抛出除以零的错误。这些都不是我想要的。
|
||||
// 同时,这样做的话,我没有办法检测这些字段到底是不是合规的。
|
||||
//
|
||||
// 然后我就将int改写为了int?类型,用null表示当前值不可接受,非null表示绑定的值。
|
||||
// 然后定义了一个转换器,负责在int?和string之间进行转换,并同时去除了所有的验证性Attribute
|
||||
// 然而遗憾的是,这么做也不符合我的要求。当我尝试输入一个数值的时候,如果我输入了任何无效值,
|
||||
// 那么转换器会将其转换为null值,同时将该值赋给Fps,而被赋值的Fps又反向传播,把这个null传递给了转换器,
|
||||
// 转换器将其转换成为空白值,并显示在界面上。这么做的视觉效果就是一旦我输入无效值,整个文本框就会被清空,非常的反人类。
|
||||
// 而且这一问题是不可调和的,我不能在接收到null时,选择不更新文本框的值,因为有可能这个null是我手动放进去的,而不是从转换器接受的。
|
||||
//
|
||||
// 所以最终,我想通了,我决定抛弃将int和TextBox.Text绑定在一起的想法。
|
||||
// 就直接把string绑定到TextBox.Text上,然后再辅以我自己定义的一套可复用验证逻辑。
|
||||
|
||||
[ObservableProperty]
|
||||
[CustomValidation(typeof(NewFileDialog), nameof(ValidateCount))]
|
||||
[NotifyCanExecuteChangedFor(nameof(OkCommand))]
|
||||
private string count;
|
||||
|
||||
[ObservableProperty]
|
||||
[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);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanOk))]
|
||||
private void Ok() {
|
||||
|
||||
}
|
||||
private bool CanOk() {
|
||||
return !HasErrors;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Cancel() {
|
||||
|
||||
}
|
||||
|
||||
public NewFileDialogResult ToResult() {
|
||||
return new NewFileDialogResult {
|
||||
Count = CountValidator.Instance.Fetch(Count),
|
||||
DeltaTime = FpsConverter.ToDelta(FpsValidator.Instance.Fetch(Fps)),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:BallanceTasEditor.Views"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" ShowInTaskbar="False"
|
||||
Title="About Ballance TAS Editor" Width="340" Height="480" Icon="/Assets/About.ico">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:BallanceTasEditor.Views"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" ShowInTaskbar="False"
|
||||
Title="Add Frame" Height="250" Width="400" Icon="/Assets/AddFrame.ico">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:BallanceTasEditor.Views"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" ShowInTaskbar="False"
|
||||
Title="Edit FPS" Height="220" Width="400" Icon="/Assets/SetFps.ico">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -4,7 +4,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:BallanceTasEditor.Views"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow"
|
||||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" ShowInTaskbar="False"
|
||||
Title="Goto..." Height="180" Width="400" Icon="/Assets/Goto.ico">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||