#include "xpathnodeconstant.h"

XPathNodeConstant::XPathNodeConstant()
    : XAsset()
    , mType(XNodeType::NODE_BADNODE)
    , mSpawnflags(0)
    , mTargetname(0)
    , mScriptLinkName(0)
    , mScriptNoteworthy(0)
    , mTarget(0)
    , mAnimscript(0)
    , mAnimscriptfunc(0)
    , mOrigin()
    , mAngle(0.0f)
    , mForward()
    , mRadius(0.0f)
    , mMinUseDistSq(0.0f)
    , mOverlapNode()
    , mChainId(0)
    , mChainDepth(0)
    , mChainParent(0)
    , mTotalLinkCount(0)
    , mLinks()
{
    SetName("Path Node Constant");
}

XPathNodeConstant::~XPathNodeConstant()
{

}

void XPathNodeConstant::ParseData(XDataStream *aStream) {
    if (GetPtr() == -1) {
        mType = (XNodeType)aStream->ParseInt32(QString("%1 node type").arg(GetName()));
        mSpawnflags = aStream->ParseUInt16(QString("%1 spawnflags").arg(GetName()));
        mTargetname = aStream->ParseUInt16(QString("%1 targetname").arg(GetName()));
        mScriptLinkName = aStream->ParseUInt16(QString("%1 script link name").arg(GetName()));
        mScriptNoteworthy = aStream->ParseUInt16(QString("%1 script noteworthy").arg(GetName()));
        mTarget = aStream->ParseUInt16(QString("%1 target").arg(GetName()));
        mAnimscript = aStream->ParseUInt16(QString("%1 animscript").arg(GetName()));
        mAnimscriptfunc = aStream->ParseInt32(QString("%1 animscript func").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())));

        mAngle = aStream->ParseSingle(QString("%1 angle").arg(GetName()));

        mForward.setX(aStream->ParseSingle(QString("%1 forward x").arg(GetName())));
        mForward.setY(aStream->ParseSingle(QString("%1 forward y").arg(GetName())));

        mRadius = aStream->ParseSingle(QString("%1 radius").arg(GetName()));
        mMinUseDistSq = aStream->ParseSingle(QString("%1 min use dist sq").arg(GetName()));

        mOverlapNode.setX(aStream->ParseSingle(QString("%1 overlap node x").arg(GetName())));
        mOverlapNode.setY(aStream->ParseSingle(QString("%1 overlap node y").arg(GetName())));

        mChainId = aStream->ParseInt16(QString("%1 chain id").arg(GetName()));
        mChainDepth = aStream->ParseInt16(QString("%1 chain depth").arg(GetName()));
        mChainParent = aStream->ParseInt16(QString("%1 chain parent").arg(GetName()));
        mTotalLinkCount = aStream->ParseUInt16(QString("%1 total link count").arg(GetName()));

        for (quint16 i = 0; i < mTotalLinkCount; ++i) {
            XPathLink newLink;
            newLink.ParseData(aStream);
            mLinks.append(newLink);
        }
    }
}

void XPathNodeConstant::Clear()
{

}
