#include "xanimparts.h"

XAnimParts::XAnimParts()
    : XAsset() {
}

void XAnimParts::ParseData(QDataStream *aStream) {
    if (GetPtr() == -1) {
        // Parse all fields
        aStream->read((char*)&mNamePtr, sizeof(quint32));
        mName = "";  // We'll need to resolve this pointer later

        aStream->read((char*)&mDataByteCount, sizeof(quint16));
        aStream->read((char*)&mDataShortCount, sizeof(quint16));
        aStream->read((char*)&mDataIntCount, sizeof(quint16));
        aStream->read((char*)&mRandomDataByteCount, sizeof(quint16));
        aStream->read((char*)&mRandomDataIntCount, sizeof(quint16));
        aStream->read((char*)&mNumFrames, sizeof(quint16));

        quint8 loopDelta;
        aStream->read((char*)&loopDelta, sizeof(quint8));
        mIsLoop = (loopDelta & 0x1) != 0;
        mIsDelta = (loopDelta & 0x2) != 0;

        aStream->read((char*)mBoneCount, sizeof(mBoneCount));
        aStream->read((char*)&mNotifyCount, sizeof(quint8));
        aStream->read((char*)&mAssetType, sizeof(quint8));

        quint8 pad;
        aStream->read((char*)&pad, sizeof(quint8));
        mPad = (pad != 0);

        aStream->read((char*)&mRandomDataShortCount, sizeof(quint16));
        aStream->read((char*)&mIndexCount, sizeof(quint16));

        aStream->read((char*)&mFramerate, sizeof(float));
        aStream->read((char*)&mFrequency, sizeof(float));

        aStream->read((char*)&mNamesPtr, sizeof(quint32));
        aStream->read((char*)&mNames, sizeof(quint16));

        aStream->read((char*)&mDataBytePtr, sizeof(quint32));
        aStream->read((char*)&mDataByte, sizeof(quint8));

        aStream->read((char*)&mDataShortPtr, sizeof(quint32));
        aStream->read((char*)&mDataShort, sizeof(qint16));

        aStream->read((char*)&mDataIntPtr, sizeof(quint32));
        aStream->read((char*)&mDataInt, sizeof(int));

        aStream->read((char*)&mRandomDataShortPtr, sizeof(quint32));
        aStream->read((char*)&mRandomDataShort, sizeof(qint16));

        aStream->read((char*)&mRandomDataBytePtr, sizeof(quint32));
        aStream->read((char*)&mRandomDataByte, sizeof(quint8));

        aStream->read((char*)&mRandomDataIntPtr, sizeof(quint32));
        aStream->read((char*)&mRandomDataInt, sizeof(int));

        // Parse indices
        mIndices.ParseData(aStream);

        aStream->read((char*)&mNotifyPtr, sizeof(qint32));
        mNotify.ParseData(aStream);

        aStream->read((char*)&mDeltaPartPtr, sizeof(qint32));
        mDeltaPart.ParseData(aStream);
    }
}

const QString& XAnimParts::GetName() const {
    return mName;
}

void XAnimParts::SetName(const QString& name) {
    mName = name;
}

quint32 XAnimParts::GetNamePtr() const {
    return mNamePtr;
}

void XAnimParts::SetNamePtr(quint32 ptr) {
    mNamePtr = ptr;
}

quint16 XAnimParts::GetDataByteCount() const {
    return mDataByteCount;
}

void XAnimParts::SetDataByteCount(quint16 count) {
    mDataByteCount = count;
}

quint16 XAnimParts::GetDataShortCount() const {
    return mDataShortCount;
}

void XAnimParts::SetDataShortCount(quint16 count) {
    mDataShortCount = count;
}

quint16 XAnimParts::GetDataIntCount() const {
    return mDataIntCount;
}

void XAnimParts::SetDataIntCount(quint16 count) {
    mDataIntCount = count;
}

quint16 XAnimParts::GetRandomDataByteCount() const {
    return mRandomDataByteCount;
}

void XAnimParts::SetRandomDataByteCount(quint16 count) {
    mRandomDataByteCount = count;
}

quint16 XAnimParts::GetRandomDataIntCount() const {
    return mRandomDataIntCount;
}

void XAnimParts::SetRandomDataIntCount(quint16 count) {
    mRandomDataIntCount = count;
}

quint16 XAnimParts::GetNumFrames() const {
    return mNumFrames;
}

void XAnimParts::SetNumFrames(quint16 frames) {
    mNumFrames = frames;
}

bool XAnimParts::IsLoop() const {
    return mIsLoop;
}

void XAnimParts::SetIsLoop(bool loop) {
    mIsLoop = loop;
}

bool XAnimParts::IsDelta() const {
    return mIsDelta;
}

void XAnimParts::SetIsDelta(bool delta) {
    mIsDelta = delta;
}

const quint8* XAnimParts::GetBoneCount() const {
    return mBoneCount;
}

void XAnimParts::SetBoneCount(const quint8* count, size_t boneCount) {
    if (boneCount <= 12) {
        memcpy(mBoneCount, count, boneCount * sizeof(quint8));
    }
}

quint8 XAnimParts::GetNotifyCount() const {
    return mNotifyCount;
}

void XAnimParts::SetNotifyCount(quint8 count) {
    mNotifyCount = count;
}

quint8 XAnimParts::GetAssetType() const {
    return mAssetType;
}

void XAnimParts::SetAssetType(quint8 type) {
    mAssetType = type;
}

bool XAnimParts::IsPad() const {
    return mPad;
}

void XAnimParts::SetIsPad(bool pad) {
    mPad = pad;
}

quint16 XAnimParts::GetRandomDataShortCount() const {
    return mRandomDataShortCount;
}

void XAnimParts::SetRandomDataShortCount(quint16 count) {
    mRandomDataShortCount = count;
}

quint16 XAnimParts::GetIndexCount() const {
    return mIndexCount;
}

void XAnimParts::SetIndexCount(quint16 count) {
    mIndexCount = count;
}

float XAnimParts::GetFramerate() const {
    return mFramerate;
}

void XAnimParts::SetFramerate(float rate) {
    mFramerate = rate;
}

float XAnimParts::GetFrequency() const {
    return mFrequency;
}

void XAnimParts::SetFrequency(float frequency) {
    mFrequency = frequency;
}

quint32 XAnimParts::GetNamesPtr() const {
    return mNamesPtr;
}

void XAnimParts::SetNamesPtr(quint32 ptr) {
    mNamesPtr = ptr;
}

quint16 XAnimParts::GetNames() const {
    return mNames;
}

void XAnimParts::SetNames(quint16 names) {
    mNames = names;
}

quint32 XAnimParts::GetDataBytePtr() const {
    return mDataBytePtr;
}

void XAnimParts::SetDataBytePtr(quint32 ptr) {
    mDataBytePtr = ptr;
}

quint8 XAnimParts::GetDataByte() const {
    return mDataByte;
}

void XAnimParts::SetDataByte(quint8 byte) {
    mDataByte = byte;
}

quint32 XAnimParts::GetDataShortPtr() const {
    return mDataShortPtr;
}

void XAnimParts::SetDataShortPtr(quint32 ptr) {
    mDataShortPtr = ptr;
}

qint16 XAnimParts::GetDataShort() const {
    return mDataShort;
}

void XAnimParts::SetDataShort(qint16 shortValue) {
    mDataShort = shortValue;
}

quint32 XAnimParts::GetDataIntPtr() const {
    return mDataIntPtr;
}

void XAnimParts::SetDataIntPtr(quint32 ptr) {
    mDataIntPtr = ptr;
}

int XAnimParts::GetDataInt() const {
    return mDataInt;
}

void XAnimParts::SetDataInt(int value) {
    mDataInt = value;
}

quint32 XAnimParts::GetRandomDataShortPtr() const {
    return mRandomDataShortPtr;
}

void XAnimParts::SetRandomDataShortPtr(quint32 ptr) {
    mRandomDataShortPtr = ptr;
}

qint16 XAnimParts::GetRandomDataShort() const {
    return mRandomDataShort;
}

void XAnimParts::SetRandomDataShort(qint16 shortValue) {
    mRandomDataShort = shortValue;
}

quint32 XAnimParts::GetRandomDataBytePtr() const {
    return mRandomDataBytePtr;
}

void XAnimParts::SetRandomDataBytePtr(quint32 ptr) {
    mRandomDataBytePtr = ptr;
}

quint8 XAnimParts::GetRandomDataByte() const {
    return mRandomDataByte;
}

void XAnimParts::SetRandomDataByte(quint8 byte) {
    mRandomDataByte = byte;
}

quint32 XAnimParts::GetRandomDataIntPtr() const {
    return mRandomDataIntPtr;
}

void XAnimParts::SetRandomDataIntPtr(quint32 ptr) {
    mRandomDataIntPtr = ptr;
}

int XAnimParts::GetRandomDataInt() const {
    return mRandomDataInt;
}

void XAnimParts::SetRandomDataInt(int value) {
    mRandomDataInt = value;
}

XAnimIndices& XAnimParts::GetIndices() {
    return mIndices;
}

const XAnimIndices& XAnimParts::GetIndices() const {
    return mIndices;
}

void XAnimParts::SetIndices(const XAnimIndices& indices) {
    mIndices = indices;
}

qint32 XAnimParts::GetNotifyPtr() const {
    return mNotifyPtr;
}

void XAnimParts::SetNotifyPtr(qint32 ptr) {
    mNotifyPtr = ptr;
}

XAnimNotifyInfo& XAnimParts::GetNotify() {
    return mNotify;
}

const XAnimNotifyInfo& XAnimParts::GetNotify() const {
    return mNotify;
}

void XAnimParts::SetNotify(const XAnimNotifyInfo& notify) {
    mNotify = notify;
}

qint32 XAnimParts::GetDeltaPartPtr() const {
    return mDeltaPartPtr;
}

void XAnimParts::SetDeltaPartPtr(qint32 ptr) {
    mDeltaPartPtr = ptr;
}

XAnimDeltaPart& XAnimParts::GetDeltaPart() {
    return mDeltaPart;
}

const XAnimDeltaPart& XAnimParts::GetDeltaPart() const {
    return mDeltaPart;
}

void XAnimParts::SetDeltaPart(const XAnimDeltaPart& deltaPart) {
    mDeltaPart = deltaPart;
}

