Files
BallanceTasEditor/Core/TASFile.cs

93 lines
3.2 KiB
C#
Raw Normal View History

2021-05-13 15:49:26 +08:00
using BallanceTASEditor.Core.TASStruct;
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
}
public void Set(FrameDataField field, long prevRange, long nextRange, bool isSet) {
if (mPointer == null) return;
var cachePointer = mPointer;
var offset = ConstValue.Mapping[field];
for (long i = 0; i < nextRange && cachePointer != null; i++) {
if (isSet) cachePointer.Value.SetKeyStates(offset);
else cachePointer.Value.UnsetKeyStates(offset);
cachePointer = cachePointer.Next;
}
for (long i = 0; i < prevRange && cachePointer != null; i++) {
if (isSet) cachePointer.Value.SetKeyStates(offset);
else cachePointer.Value.UnsetKeyStates(offset);
cachePointer = cachePointer.Previous;
}
}
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();
}
}
}