#include "xgfxlight.h"

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

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

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

void XGfxLight::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()));

        aStream->skipRawData(2);

        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()));
        mExponent = aStream->ParseInt32(QString("%1 exponent").arg(GetName()));
        mSpotShadowIndex = aStream->ParseUInt32(QString("%1 spot shadow index").arg(GetName()));
        mDefPtr = aStream->ParseInt32(QString("%1 def ptr").arg(GetName()));

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


void XGfxLight::Clear()
{

}
