#include "xgfxlight.h"

#include "qcolor.h"
#include "xgfxlightdef.h"

XGfxLight::XGfxLight()
    : XAsset()
    , mType(0)
    , mCanUseShadowMap(0)
    , mUnused({0, 0})
    , mColor({0.0f, 0.0f, 0.0f})
    , mDir({0.0f, 0.0f, 0.0f})
    , mOrigin({0.0f, 0.0f, 0.0f})
    , mRadius(0.0f)
    , mCosHalfFovOuter(0.0f)
    , mCosHalfFovInner(0.0f)
    , mExponent(0)
    , mSpotShadowIndex(0)
    , mDefPtr(0)
    , mDef(new XGfxLightDef())
{
}

XGfxLight::~XGfxLight()
{
    delete mDef;
}

void XGfxLight::ParseData(QDataStream *aStream) {
    if (GetPtr() == -1) {
        *aStream
            >> mType
            >> mCanUseShadowMap;

        aStream->skipRawData(2);

        float r, g, b;

        *aStream
            >> r
            >> g
            >> b
            >> mDir[0]
            >> mDir[1]
            >> mDir[2]
            >> mOrigin[0]
            >> mOrigin[1]
            >> mOrigin[2]
            >> mRadius
            >> mCosHalfFovOuter
            >> mCosHalfFovInner
            >> mExponent
            >> mSpotShadowIndex
            >> mDefPtr;

        mColor = QColor(r, g, b);

        if (mDefPtr == -1)
        {
            mDef->ParseData(aStream);
        }
    }
}

unsigned char XGfxLight::GetType() const {
    return mType;
}

void XGfxLight::SetType(unsigned char aType) {
    mType = aType;
}

unsigned char XGfxLight::CanUseShadowMap() const {
    return mCanUseShadowMap;
}

void XGfxLight::SetCanUseShadowMap(bool aCanUse) {
    mCanUseShadowMap = aCanUse ? 1 : 0;
}

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

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

QVector<float> XGfxLight::GetDir() const {
    return mDir;
}

void XGfxLight::SetDir(const QVector<float> &aDir) {
    mDir = aDir;
}

QVector<float> XGfxLight::GetOrigin() const {
    return mOrigin;
}

void XGfxLight::SetOrigin(const QVector<float> &aOrigin) {
    mOrigin = aOrigin;
}

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

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

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

void XGfxLight::SetCosHalfFovOuter(float aCosHalfFov) {
    mCosHalfFovOuter = aCosHalfFov;
}

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

void XGfxLight::SetCosHalfFovInner(float aCosHalfFov) {
    mCosHalfFovInner = aCosHalfFov;
}

int XGfxLight::GetExponent() const {
    return mExponent;
}

void XGfxLight::SetExponent(int aExponent) {
    mExponent = aExponent;
}

unsigned int XGfxLight::GetSpotShadowIndex() const {
    return mSpotShadowIndex;
}

void XGfxLight::SetSpotShadowIndex(unsigned int aIndex) {
    mSpotShadowIndex = aIndex;
}

int XGfxLight::GetDefPtr() const {
    return mDefPtr;
}

void XGfxLight::SetDefPtr(int ptr) {
    mDefPtr = ptr;
}


