2011-04-08 13:58:21 +00:00
|
|
|
#include "loadgmst.hpp"
|
|
|
|
|
2012-09-13 08:41:55 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2012-10-01 13:15:16 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2012-09-23 18:41:41 +00:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
2012-09-13 08:41:55 +00:00
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
void GameSetting::load(ESMReader &esm)
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
assert(mId != "");
|
2011-04-08 13:58:21 +00:00
|
|
|
|
|
|
|
// We are apparently allowed to be empty
|
|
|
|
if (!esm.hasMoreSubs())
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
mType = VT_None;
|
2011-04-08 13:58:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load some data
|
|
|
|
esm.getSubName();
|
|
|
|
NAME n = esm.retSubName();
|
|
|
|
if (n == "STRV")
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
mStr = esm.getHString();
|
|
|
|
mType = VT_String;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
else if (n == "INTV")
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHT(mI);
|
|
|
|
mType = VT_Int;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
else if (n == "FLTV")
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
esm.getHT(mF);
|
|
|
|
mType = VT_Float;
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
esm.fail("Unwanted subrecord type");
|
|
|
|
}
|
2012-12-17 22:13:33 +00:00
|
|
|
|
2012-04-06 19:04:30 +00:00
|
|
|
void GameSetting::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_String: esm.writeHNString("STRV", mStr); break;
|
|
|
|
case VT_Int: esm.writeHNT("INTV", mI); break;
|
|
|
|
case VT_Float: esm.writeHNT("FLTV", mF); break;
|
2012-04-06 19:04:30 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 08:41:55 +00:00
|
|
|
int GameSetting::getInt() const
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
switch (mType)
|
2012-09-13 08:41:55 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
case VT_Float: return static_cast<int> (mF);
|
|
|
|
case VT_Int: return mI;
|
|
|
|
default: throw std::runtime_error ("GMST " + mId + " is not of a numeric type");
|
2012-09-13 08:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-21 15:53:16 +00:00
|
|
|
float GameSetting::getFloat() const
|
2012-09-13 08:41:55 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
switch (mType)
|
2012-09-13 08:41:55 +00:00
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
case VT_Float: return mF;
|
|
|
|
case VT_Int: return mI;
|
|
|
|
default: throw std::runtime_error ("GMST " + mId + " is not of a numeric type");
|
2012-09-13 08:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameSetting::getString() const
|
|
|
|
{
|
2012-09-17 07:37:50 +00:00
|
|
|
if (mType==VT_String)
|
|
|
|
return mStr;
|
2012-09-13 08:41:55 +00:00
|
|
|
|
2012-09-17 07:37:50 +00:00
|
|
|
throw std::runtime_error ("GMST " + mId + " is not a string");
|
2012-09-13 08:41:55 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 13:58:21 +00:00
|
|
|
}
|