#include "xcbrush.h"

XCBrush::XCBrush()
    : XAsset()
    , mMins()
    , mContents(0)
    , mMaxs()
    , mNumsides()
    , mSides()
    , mAxialMaterialNum()
    , mBaseAdjacentSide()
    , mFirstAdjacentSideOffsets()
    , mEdgeCount()
{
    SetName("C Brush");
}

XCBrush::~XCBrush()
{
    
}

void XCBrush::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        for (int i = 0; i < 3; i++)
        {
            mMins[i] = aStream->ParseSingle(QString("%1 min %2").arg(GetName()).arg(i));
        }

        mContents = aStream->ParseInt32(QString("%1 contents").arg(GetName()));

        for (int i = 0; i < 3; i++)
        {
            mMaxs[i] = aStream->ParseSingle(QString("%1 max %2").arg(GetName()).arg(i));
        }

        // TODO: Implement baseAdjacentSidePtr
        qint32 sidesPtr;//, baseAdjacentSidePtr;
        mNumsides = aStream->ParseInt32(QString("%1 # sides").arg(GetName()));
        sidesPtr = aStream->ParseInt32(QString("%1 sides ptr").arg(GetName()));

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                mAxialMaterialNum[i][j] = aStream->ParseSingle(QString("%1 axial material num (%2, %3)").arg(GetName()).arg(i).arg(j));
            }
        }

        mBaseAdjacentSide = aStream->ParseInt32(QString("%1 base adjacent side ptr").arg(GetName()));

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                mFirstAdjacentSideOffsets[i][j] = aStream->ParseSingle(QString("%1 first adjacent side offset (%2, %3)").arg(GetName()).arg(i).arg(j));
            }
        }
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                mEdgeCount[i][j] = aStream->ParseSingle(QString("%1 edge count (%2, %3)").arg(GetName()).arg(i).arg(j));
            }
        }

        aStream->skipRawData(10);

        if (sidesPtr == -1)
        {
            XCBrushSide newSize;
            newSize.ParseData(aStream);
        }

        // TODO: Read in this ptr then parse
        //if (baseAdjacentSidePtr == -1)
        //{
        //    XCBrushSide newSize;
        //    newSize.ParseData(aStream);
        //}
    }
}

void XCBrush::Clear()
{
    mMins = QVector3D();
    mContents = 0;
    mMaxs = QVector3D();
    mNumsides = 0;
    mSides = QVector<XCBrushSide>();
    mAxialMaterialNum = QVector<QVector3D>();
    mBaseAdjacentSide = 0;
    mFirstAdjacentSideOffsets = QVector<QVector3D>();
    mEdgeCount = QVector<QVector3D>();
}
