#include "xcomprimarylight.h"

XComPrimaryLight::XComPrimaryLight()
    : XAsset()
    , mType(-1)
    , mCanUseShadowMap(-1)
    , mExponent(-1)
    , mUnused(-1)
    , mColor(0, 0, 0)
    , mDir(0, 0, 0)
    , mOrigin(0, 0, 0)
    , mRadius(0.0)
    , mCosHalfFovOuter(0.0)
    , mCosHalfFovInner(0.0)
    , mCosHalfFovExpanded(0.0)
    , mRotationLimit(0.0)
    , mTranslationLimit(0.0)
    , mDefName()
{
    SetName("Com Primary Light");
}

XComPrimaryLight::~XComPrimaryLight()
{

}

void XComPrimaryLight::Clear()
{

}

XComPrimaryLightArray *XComPrimaryLight::ParseArray(XDataStream *aStream, int aCount)
{
    XComPrimaryLightArray* result = new XComPrimaryLightArray();

    for (int i = 0; i < aCount; i++)
    {
        XComPrimaryLight* comPrimaryLight = new XComPrimaryLight();
        comPrimaryLight->ParseData(aStream);

        result->append(comPrimaryLight);
    }

    return result;
}

void XComPrimaryLight::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mType             = aStream->ParseUInt8(QString("%1 type").arg(GetName()));
        mCanUseShadowMap  = aStream->ParseUInt8(QString("%1 can use shadow map").arg(GetName()));
        mExponent         = aStream->ParseUInt8(QString("%1 exponent").arg(GetName()));
        mUnused           = aStream->ParseUInt8(QString("%1 unused").arg(GetName()));

        float r = aStream->ParseSingle(QString("%1 color r").arg(GetName()));
        float g = aStream->ParseSingle(QString("%1 color g").arg(GetName()));
        float b = aStream->ParseSingle(QString("%1 color b").arg(GetName()));
        mColor = QColor::fromRgbF(r, g, b);

        mDir.setX(aStream->ParseSingle(QString("%1 dir x").arg(GetName())));
        mDir.setY(aStream->ParseSingle(QString("%1 dir y").arg(GetName())));
        mDir.setZ(aStream->ParseSingle(QString("%1 dir z").arg(GetName())));

        mOrigin.setX(aStream->ParseSingle(QString("%1 origin x").arg(GetName())));
        mOrigin.setY(aStream->ParseSingle(QString("%1 origin y").arg(GetName())));
        mOrigin.setZ(aStream->ParseSingle(QString("%1 origin z").arg(GetName())));

        mRadius             = aStream->ParseSingle(QString("%1 radius").arg(GetName()));
        mCosHalfFovOuter    = aStream->ParseSingle(QString("%1 cos half fov outer").arg(GetName()));
        mCosHalfFovInner    = aStream->ParseSingle(QString("%1 cos half fov inner").arg(GetName()));
        mCosHalfFovExpanded = aStream->ParseSingle(QString("%1 cos half fov expanded").arg(GetName()));
        mRotationLimit      = aStream->ParseSingle(QString("%1 rotation limit").arg(GetName()));
        mTranslationLimit   = aStream->ParseSingle(QString("%1 translation limit").arg(GetName()));

        mDefName.ParseData(aStream);
    }
}

quint8 XComPrimaryLight::GetType() const
{
    return mType;
}

quint8 XComPrimaryLight::GetCanUseShadowMap() const
{
    return mCanUseShadowMap;
}

quint8 XComPrimaryLight::GetExponent() const
{
    return mExponent;
}

quint8 XComPrimaryLight::GetUnused() const
{
    return mUnused;
}

QColor XComPrimaryLight::GetColor() const
{
    return mColor;
}

QVector3D XComPrimaryLight::GetDir() const
{
    return mDir;
}

QVector3D XComPrimaryLight::GetOrigin() const
{
    return mOrigin;
}

float XComPrimaryLight::GetRadius() const
{
    return mRadius;
}

float XComPrimaryLight::GetCosHalfFovOuter() const
{
    return mCosHalfFovOuter;
}

float XComPrimaryLight::GetCosHalfFovInner() const
{
    return mCosHalfFovInner;
}

float XComPrimaryLight::GetCosHalfFovExpanded() const
{
    return mCosHalfFovExpanded;
}

float XComPrimaryLight::GetRotationLimit() const
{
    return mRotationLimit;
}

float XComPrimaryLight::GetTranslationLimit() const
{
    return mTranslationLimit;
}

void XComPrimaryLight::SetType(quint8 aType)
{
    mType = aType;
}

void XComPrimaryLight::SetCanUseShadowMap(quint8 aCanUseShadowMap)
{
    mCanUseShadowMap = aCanUseShadowMap;
}

void XComPrimaryLight::SetExponent(quint8 aExponent)
{
    mExponent = aExponent;
}

void XComPrimaryLight::SetUnused(quint8 aUnused)
{
    mUnused = aUnused;
}

void XComPrimaryLight::SetColor(const QColor aColor)
{
    mColor = aColor;
}

void XComPrimaryLight::SetDir(const QVector3D aDir)
{
    mDir = aDir;
}

void XComPrimaryLight::SetOrigin(const QVector3D aOrigin)
{
    mOrigin = aOrigin;
}

void XComPrimaryLight::SetRadius(float aRadius)
{
    mRadius = aRadius;
}

void XComPrimaryLight::SetCosHalfFovOuter(float aCosHalfFovOuter)
{
    mCosHalfFovOuter = aCosHalfFovOuter;
}

void XComPrimaryLight::SetCosHalfFovInner(float aCosHalfFovInner)
{
    mCosHalfFovInner = aCosHalfFovInner;
}

void XComPrimaryLight::SetCosHalfFovExpanded(float aCosHalfFovExpanded)
{
    mCosHalfFovExpanded = aCosHalfFovExpanded;
}

void XComPrimaryLight::SetRotationLimit(float aRotationLimit)
{
    mRotationLimit = aRotationLimit;
}

void XComPrimaryLight::SetTranslationLimit(float aTranslationLimit)
{
    mTranslationLimit = aTranslationLimit;
}
