#include "xmaterialtechniqueset.h"

XMaterialTechniqueSet::XMaterialTechniqueSet()
    : XAsset()
    , mName()
    , mWorldVertFormat(0)
    , mRemappedTechniqueSet()
    , mTechniques(26)
{
    SetType(ASSET_TYPE_TECHNIQUE_SET);
    SetName("Material Technique Set");
}

XMaterialTechniqueSet::~XMaterialTechniqueSet()
{
    
}

void XMaterialTechniqueSet::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        if (IsDebug())
        {
            qDebug() << QString("[%1] Parsing data for %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(GetName());
        }
        mName.ParsePtr(aStream, false);

        *aStream >> mWorldVertFormat;
        if (IsDebug())
        {
            qDebug() << QString("[%1] mWorldVertFormat = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(mWorldVertFormat);
        }

        aStream->skipRawData(3);

        qint32 remappedPtr;
        *aStream >> remappedPtr;
        if (IsDebug())
        {
            qDebug() << QString("[%1] remappedPtr = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(remappedPtr);

            qDebug() << QString("Parsing techniques.");
        }
        for (int i = 0; i < 26; i++)
        {
            XMaterialTechnique newTechnique;
            newTechnique.ParsePtr(aStream, false);
            mTechniques.append(newTechnique);
        }

        mName.SetRemoveString(",");
        mName.ParseData(aStream);

        for (int i = 0; i < 26; i++)
        {
            mTechniques[i].ParseData(aStream);
        }
    }
}

void XMaterialTechniqueSet::Clear()
{
    mName.Clear();
    mWorldVertFormat = 0;

    delete mRemappedTechniqueSet;
    mRemappedTechniqueSet = new XMaterialTechniqueSet();

    mTechniques.clear();
    mTechniques = QVector<XMaterialTechnique>(26);
}
