#include "xcomworld.h"

ComWorld::ComWorld()
    : XAsset()
    , mName(new XString())
    , mInUse(false)
    , mPrimaryLightCount(-1)
    , mPrimaryLights(new XComPrimaryLightArray())
{

}

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

    delete mPrimaryLights;
    delete mName;
}

void ComWorld::ParseData(QDataStream *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 ComWorld::GetName() const
{
    return mName->GetString();
}

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

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

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

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

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

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

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