2021-05-13 15:49:26 +08:00
|
|
|
|
using BallanceTASEditor.Core.TASStruct;
|
2021-05-16 14:15:35 +08:00
|
|
|
|
using BallanceTASEditor.UI;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BallanceTASEditor.Core {
|
|
|
|
|
|
public class TASFile {
|
|
|
|
|
|
public TASFile(string filename) {
|
|
|
|
|
|
mFilename = filename;
|
|
|
|
|
|
mMem = new LinkedList<FrameData>();
|
|
|
|
|
|
var fs = new FileStream(mFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
|
|
|
|
ZlibUtil.DecompressTAS(mMem, fs);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
mPointer = mMem.First;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string mFilename { get; private set; }
|
|
|
|
|
|
public long mFrameCount { get { return mMem.Count; } }
|
|
|
|
|
|
LinkedList<FrameData> mMem;
|
|
|
|
|
|
LinkedListNode<FrameData> mPointer;
|
|
|
|
|
|
|
|
|
|
|
|
public void Shift(long shiftNum) {
|
|
|
|
|
|
if (mPointer == null) return;
|
|
|
|
|
|
if (shiftNum == 0) return;
|
|
|
|
|
|
var absNum = Math.Abs(shiftNum);
|
|
|
|
|
|
if (shiftNum > 0) {
|
|
|
|
|
|
for(long num = 0; num < absNum && mPointer.Next != null; num++) {
|
|
|
|
|
|
mPointer = mPointer.Next;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (long num = 0; num < absNum && mPointer.Previous != null; num++) {
|
|
|
|
|
|
mPointer = mPointer.Previous;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-13 22:18:51 +08:00
|
|
|
|
public void Get(List<FrameDataDisplay> container, long startIndex, int count) {
|
|
|
|
|
|
// no item. clean container
|
|
|
|
|
|
if (mPointer == null) {
|
|
|
|
|
|
for(int j = 0; j < count; j++) {
|
|
|
|
|
|
container[j].isEnable = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// fill container
|
2021-05-13 15:49:26 +08:00
|
|
|
|
var cachePointer = mPointer;
|
|
|
|
|
|
int i;
|
|
|
|
|
|
for(i = 0; i < count && cachePointer != null; i++, startIndex++) {
|
|
|
|
|
|
container[i].Reload(startIndex, cachePointer.Value);
|
2021-05-13 22:18:51 +08:00
|
|
|
|
container[i].isEnable = true;
|
2021-05-13 15:49:26 +08:00
|
|
|
|
cachePointer = cachePointer.Next;
|
|
|
|
|
|
}
|
2021-05-13 22:18:51 +08:00
|
|
|
|
for(; i < count; i++) {
|
|
|
|
|
|
container[i].isEnable = false;
|
|
|
|
|
|
}
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-16 14:15:35 +08:00
|
|
|
|
// if isSet is null, mean flip state
|
|
|
|
|
|
public void Set(SelectionRange field, SelectionRange relativeRange, bool? isSet) {
|
2021-05-13 15:49:26 +08:00
|
|
|
|
if (mPointer == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
var cachePointer = mPointer;
|
2021-05-16 14:15:35 +08:00
|
|
|
|
uint offset = 0;
|
|
|
|
|
|
for(int i = (int)field.start; i <= (int)field.end; i++) {
|
|
|
|
|
|
offset |= ConstValue.Mapping[(FrameDataField)i];
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach(var item in mMem.IterateWithSelectionRange(relativeRange, mPointer)) {
|
|
|
|
|
|
if (isSet == null) item.Value.ReverseKeyStates(offset);
|
|
|
|
|
|
else if (isSet == true) item.Value.SetKeyStates(offset);
|
|
|
|
|
|
else if (isSet == false) item.Value.UnsetKeyStates(offset);
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
2021-05-16 14:15:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(SelectionRange relativeRange) {
|
|
|
|
|
|
if (mPointer == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
mMem.RemoveWithSelectionRange(relativeRange, mPointer);
|
|
|
|
|
|
// todo: fix pointer point to invalid item
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Add(long relativePos, bool isAddBefore) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Insert(long relativePos, LinkedList<FrameData> data, bool isInsertBefore) {
|
|
|
|
|
|
if (mPointer == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Copy(SelectionRange relativeRange, LinkedList<FrameData> data) {
|
|
|
|
|
|
if (mPointer == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in mMem.IterateWithSelectionRange(relativeRange, mPointer)) {
|
|
|
|
|
|
data.AddLast(item.Value);
|
2021-05-13 15:49:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Save() {
|
|
|
|
|
|
var fs = new FileStream(mFilename, FileMode.Create, FileAccess.Write, FileShare.None);
|
|
|
|
|
|
ZlibUtil.CompressTAS(mMem, fs);
|
|
|
|
|
|
fs.Close();
|
|
|
|
|
|
fs.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SaveAs(string newfile) {
|
|
|
|
|
|
mFilename = newfile;
|
|
|
|
|
|
Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|