2011-04-08 13:58:21 +00:00
|
|
|
#include "loadglob.hpp"
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2012-09-17 07:37:50 +00:00
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
void Global::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
std::string tmp = esm.getHNString("FNAM");
|
|
|
|
if (tmp == "s")
|
2012-09-17 07:37:50 +00:00
|
|
|
mType = VT_Short;
|
2011-04-08 13:58:21 +00:00
|
|
|
else if (tmp == "l")
|
2012-09-17 07:37:50 +00:00
|
|
|
mType = VT_Int;
|
2011-04-08 13:58:21 +00:00
|
|
|
else if (tmp == "f")
|
2012-09-17 07:37:50 +00:00
|
|
|
mType = VT_Float;
|
2011-04-08 13:58:21 +00:00
|
|
|
else
|
|
|
|
esm.fail("Illegal global variable type " + tmp);
|
|
|
|
|
|
|
|
// Note: Both floats and longs are represented as floats.
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHNT(mValue, "FLTV");
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
void Global::save(ESMWriter &esm)
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
switch(mType)
|
2012-04-06 19:04:30 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
case VT_Short:
|
|
|
|
esm.writeHNString("FNAM", "s");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VT_Int:
|
|
|
|
esm.writeHNString("FNAM", "l");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VT_Float:
|
|
|
|
esm.writeHNString("FNAM", "f");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2012-04-06 19:04:30 +00:00
|
|
|
}
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.writeHNT("FLTV", mValue);
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 21:16:02 +00:00
|
|
|
void Global::blank()
|
|
|
|
{
|
|
|
|
mValue = 0;
|
|
|
|
mType = VT_Float;
|
|
|
|
}
|
|
|
|
|
2012-11-29 13:45:34 +00:00
|
|
|
bool operator== (const Global& left, const Global& right)
|
|
|
|
{
|
|
|
|
return left.mId==right.mId && left.mValue==right.mValue && left.mType==right.mType;
|
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|