feat: write shit operator
This commit is contained in:
@@ -9,6 +9,31 @@ namespace BallanceTasEditor.Backend {
|
|||||||
/// FPS converter
|
/// FPS converter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class FpsConverter {
|
public static class FpsConverter {
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the FPS is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fps">FPS in integer</param>
|
||||||
|
/// <returns>Is valid</returns>
|
||||||
|
public static bool IsValidFps(uint fps) {
|
||||||
|
return fps > 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the FPS is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fps">FPS in float point</param>
|
||||||
|
/// <returns>Is valid</returns>
|
||||||
|
public static bool IsValidFps(float fps) {
|
||||||
|
return fps > 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the delta time is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="delta">Delta time in float point</param>
|
||||||
|
/// <returns>Is valid</returns>
|
||||||
|
public static bool IsValidDelta(float delta) {
|
||||||
|
return delta > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert float point delta time to float point FPS
|
/// Convert float point delta time to float point FPS
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ namespace BallanceTasEditor.Backend {
|
|||||||
return GetClipboardObject() is not null;
|
return GetClipboardObject() is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumerableArray? GetClipboard() {
|
public static IExactSizeEnumerable<TasFrame>? GetClipboard() {
|
||||||
var rawFrames = GetClipboardObject();
|
var rawFrames = GetClipboardObject();
|
||||||
if (rawFrames is null) return null;
|
if (rawFrames is null) return null;
|
||||||
|
|
||||||
return new EnumerableArray(rawFrames);
|
return new EnumerableArray(rawFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class EnumerableArray : IExactSizeEnumerable<TasFrame> {
|
private sealed class EnumerableArray : IExactSizeEnumerable<TasFrame> {
|
||||||
public EnumerableArray(RawTasFrame[] rawFrames) {
|
public EnumerableArray(RawTasFrame[] rawFrames) {
|
||||||
m_RawFrames = rawFrames;
|
m_RawFrames = rawFrames;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ namespace BallanceTasEditor.Backend {
|
|||||||
public const int MIN_KEY_INDEX = 0;
|
public const int MIN_KEY_INDEX = 0;
|
||||||
public const int MAX_KEY_INDEX = 8;
|
public const int MAX_KEY_INDEX = 8;
|
||||||
|
|
||||||
|
public static bool IsValidIndex(int index) {
|
||||||
|
return index >= MIN_KEY_INDEX && index <= MAX_KEY_INDEX;
|
||||||
|
}
|
||||||
|
|
||||||
public static TasKey FromIndex(int index) {
|
public static TasKey FromIndex(int index) {
|
||||||
if (index < MIN_KEY_INDEX || index > MAX_KEY_INDEX) {
|
if (index < MIN_KEY_INDEX || index > MAX_KEY_INDEX) {
|
||||||
throw new ArgumentOutOfRangeException(nameof(index));
|
throw new ArgumentOutOfRangeException(nameof(index));
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ namespace BallanceTasEditor.Backend {
|
|||||||
int Occupation();
|
int Occupation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static class OperationExceptions {
|
||||||
|
internal static readonly InvalidOperationException ExecutionEnvironment = new InvalidOperationException("Can not execute one TAS operation multiple times.");
|
||||||
|
internal static readonly InvalidOperationException RevokeEnvironment = new InvalidOperationException("Can not revoke an not executed TAS operation.");
|
||||||
|
}
|
||||||
|
|
||||||
public enum CellKeysOperationKind {
|
public enum CellKeysOperationKind {
|
||||||
Set, Unset, Flip
|
Set, Unset, Flip
|
||||||
}
|
}
|
||||||
@@ -88,7 +93,7 @@ namespace BallanceTasEditor.Backend {
|
|||||||
|
|
||||||
public void Execute(ITasSequence seq) {
|
public void Execute(ITasSequence seq) {
|
||||||
if (m_FramesBackup is not null) {
|
if (m_FramesBackup is not null) {
|
||||||
throw new InvalidOperationException("Can not execute one TAS operation multiple times.");
|
throw OperationExceptions.ExecutionEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check index range.
|
// Check index range.
|
||||||
@@ -126,7 +131,7 @@ namespace BallanceTasEditor.Backend {
|
|||||||
|
|
||||||
public void Revoke(ITasSequence seq) {
|
public void Revoke(ITasSequence seq) {
|
||||||
if (m_FramesBackup is null) {
|
if (m_FramesBackup is null) {
|
||||||
throw new InvalidOperationException("Can not revoke an not executed TAS operation.");
|
throw OperationExceptions.RevokeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index range is checked,
|
// Index range is checked,
|
||||||
@@ -185,8 +190,10 @@ namespace BallanceTasEditor.Backend {
|
|||||||
public class AddFrameOperation : ITasRevocableOperation {
|
public class AddFrameOperation : ITasRevocableOperation {
|
||||||
public AddFrameOperation(int index, uint fps, int count) {
|
public AddFrameOperation(int index, uint fps, int count) {
|
||||||
// Check argument
|
// Check argument
|
||||||
|
if (!FpsConverter.IsValidFps(fps)) {
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(fps));
|
||||||
|
}
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
ArgumentOutOfRangeException.ThrowIfNegative(count);
|
||||||
ArgumentOutOfRangeException.ThrowIfZero(fps);
|
|
||||||
// Assign argument
|
// Assign argument
|
||||||
m_Index = index;
|
m_Index = index;
|
||||||
m_Fps = fps;
|
m_Fps = fps;
|
||||||
@@ -205,17 +212,20 @@ namespace BallanceTasEditor.Backend {
|
|||||||
|
|
||||||
public void Execute(ITasSequence seq) {
|
public void Execute(ITasSequence seq) {
|
||||||
if (m_IsExecuted) {
|
if (m_IsExecuted) {
|
||||||
throw new InvalidOperationException("Can not execute one TAS operation multiple times.");
|
throw OperationExceptions.ExecutionEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check argument.
|
// Check argument.
|
||||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
ArgumentOutOfRangeException.ThrowIfGreaterThan(m_Index, seq.GetCount());
|
||||||
|
|
||||||
|
// Skip if count is zero.
|
||||||
|
if (m_Count != 0) {
|
||||||
// Prepare data builder.
|
// Prepare data builder.
|
||||||
var iter = Enumerable.Range(0, m_Count).Select((_) => TasFrame.FromFps(m_Fps));
|
var iter = Enumerable.Range(0, m_Count).Select((_) => TasFrame.FromFps(m_Fps));
|
||||||
var exactSizedIter = new ExactSizeEnumerableAdapter<TasFrame>(iter, m_Count);
|
var exactSizedIter = new ExactSizeEnumerableAdapter<TasFrame>(iter, m_Count);
|
||||||
// Execute inserting.
|
// Execute inserting.
|
||||||
seq.Insert(m_Index, exactSizedIter);
|
seq.Insert(m_Index, exactSizedIter);
|
||||||
|
}
|
||||||
|
|
||||||
// Set status
|
// Set status
|
||||||
m_IsExecuted = true;
|
m_IsExecuted = true;
|
||||||
@@ -223,14 +233,13 @@ namespace BallanceTasEditor.Backend {
|
|||||||
|
|
||||||
public void Revoke(ITasSequence seq) {
|
public void Revoke(ITasSequence seq) {
|
||||||
if (!m_IsExecuted) {
|
if (!m_IsExecuted) {
|
||||||
throw new InvalidOperationException("Can not revoke an not executed TAS operation.");
|
throw OperationExceptions.RevokeEnvironment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we inserted count is not zero, remove inserted frames
|
// Arguments were checked so we directly resotre them.
|
||||||
|
// If we inserted count is not zero, remove inserted frames, otherwise do nothing.
|
||||||
if (m_Count != 0) {
|
if (m_Count != 0) {
|
||||||
seq.Remove(m_Index, m_Index + m_Count - 1);
|
seq.Remove(m_Index, m_Index + m_Count - 1);
|
||||||
} else {
|
|
||||||
// Otherwise just skip it.
|
|
||||||
}
|
}
|
||||||
// Modify execution status
|
// Modify execution status
|
||||||
m_IsExecuted = false;
|
m_IsExecuted = false;
|
||||||
@@ -269,7 +278,7 @@ namespace BallanceTasEditor.Backend {
|
|||||||
public void Execute(ITasSequence seq) {
|
public void Execute(ITasSequence seq) {
|
||||||
// Check execution status first.
|
// Check execution status first.
|
||||||
if (m_IsExecuted) {
|
if (m_IsExecuted) {
|
||||||
throw new InvalidOperationException("Can not execute one TAS operation multiple times.");
|
throw OperationExceptions.ExecutionEnvironment;
|
||||||
}
|
}
|
||||||
// Execute operation
|
// Execute operation
|
||||||
foreach (var frame in seq) {
|
foreach (var frame in seq) {
|
||||||
@@ -295,7 +304,7 @@ namespace BallanceTasEditor.Backend {
|
|||||||
public void Execute(ITasSequence seq) {
|
public void Execute(ITasSequence seq) {
|
||||||
// Check execution status first.
|
// Check execution status first.
|
||||||
if (m_IsExecuted) {
|
if (m_IsExecuted) {
|
||||||
throw new InvalidOperationException("Can not execute one TAS operation multiple times.");
|
throw OperationExceptions.ExecutionEnvironment;
|
||||||
}
|
}
|
||||||
// Execute operation
|
// Execute operation
|
||||||
foreach (var frame in seq) {
|
foreach (var frame in seq) {
|
||||||
|
|||||||
Reference in New Issue
Block a user