#include "xcomworld.h"

XComWorld::XComWorld()
    : XAsset()
    , mName(new XString())
    , mInUse(false)
    , mPrimaryLightCount(-1)
    , mPrimaryLights(new XComPrimaryLightArray())
{
    SetType(ASSET_TYPE_COMWORLD);
    SetName("Com World");
}

XComWorld::~XComWorld()
{

}

void XComWorld::Clear()
{
    for (int i = 0; i < mPrimaryLights->size(); i++)
    {
        delete mPrimaryLights->at(i);
    }

    delete mPrimaryLights;
    delete mName;
}

void XComWorld::ParseData(XDataStream *aStream)
{
    mName->ParsePtr(aStream, false);

    quint32 primaryLightPtr;
    *aStream
        >> mInUse
        >> mPrimaryLightCount
        >> primaryLightPtr;

    mName->ParseData(aStream);

    if (primaryLightPtr)
    {
        if (mPrimaryLights != nullptr)
        {
            delete mPrimaryLights;
        }
        mPrimaryLights = XComPrimaryLight::ParseArray(aStream, mPrimaryLightCount);
    }
}

QString XComWorld::GetName() const
{
    return mName->GetString();
}

bool XComWorld::IsInUse() const
{
    return mInUse;
}

quint32 XComWorld::GetPrimaryLightCount() const
{
    return mPrimaryLightCount;
}

XComPrimaryLight *XComWorld::GetPrimaryLight(quint32 aIndex) const
{
    return mPrimaryLights->at(aIndex);
}

XComPrimaryLightArray *XComWorld::GetPrimaryLights() const
{
    return mPrimaryLights;
}

void XComWorld::SetName(const QString &aName)
{
    if (aName != nullptr)
    {
        mName->SetString(aName);
    }
}

void XComWorld::SetName(XString* aName)
{
    if (aName != nullptr)
    {
        mName = aName;
    }
}

void XComWorld::SetInUse(bool aInUse)
{
    mInUse = aInUse;
}
