#include "xitemdefdata.h"
#include "xitemdef.h"

XItemDefData::XItemDefData()
    : XAsset()
    , mListBox()
    , mEditField()
    , mMulti()
    , mEnumDvarName()
    , mParent(nullptr)
{

}

XItemDefData::XItemDefData(XItemDef &aParent)
    : XAsset()
    , mListBox()
    , mEditField()
    , mMulti()
    , mEnumDvarName()
    , mParent(&aParent)
{

}

XItemDefData::~XItemDefData()
{
    delete mParent;
}

void XItemDefData::Clear()
{
    mListBox.Clear();
    mEditField.Clear();
    mMulti.Clear();
    mEnumDvarName.Clear();
    mParent = nullptr;
}

void XItemDefData::ParseData(QDataStream *aStream)
{
    if (!mParent)
    {
        return;
    }

    mListBox.ParsePtr(aStream, false);
    mEditField.ParsePtr(aStream, false);
    mMulti.ParsePtr(aStream, false);
    mEnumDvarName.ParsePtr(aStream, false);

    qint32 dataPtr;
    *aStream >> dataPtr;

    switch (mParent->GetType())
    {
    case 6:
        mListBox.ParseData(aStream);
        break;
    case 0:
    case 4:
    case 9:
    case 10:
    case 11:
    case 14:
    case 16:
    case 17:
    case 18:
        mListBox.ParseData(aStream);
        break;
    case 12:
        mMulti.ParseData(aStream);
        break;
    case 13:
        mEnumDvarName.ParseData(aStream);
        break;
    }
}
