use new Variant type for GMSTs

actorid
Marc Zinnschlag 12 years ago
parent ce49ad54a1
commit ba4907fbaf

@ -719,23 +719,7 @@ void Record<ESM::Global>::print()
template<>
void Record<ESM::GameSetting>::print()
{
std::cout << " Value: ";
switch (mData.mType) {
case ESM::VT_String:
std::cout << "'" << mData.mStr << "' (std::string)";
break;
case ESM::VT_Float:
std::cout << mData.mF << " (float)";
break;
case ESM::VT_Int:
std::cout << mData.mI << " (int)";
break;
default:
std::cout << "unknown type";
}
std::cout << " " << mData.mValue << std::endl;
}
template<>

@ -116,8 +116,7 @@ void CSMDoc::Document::addOptionalGmsts()
{
ESM::GameSetting gmst;
gmst.mId = sFloats[i];
gmst.mF = 0;
gmst.mType = ESM::VT_Float;
gmst.mValue.setType (ESM::VT_Float);
addOptionalGmst (gmst);
}
@ -125,8 +124,7 @@ void CSMDoc::Document::addOptionalGmsts()
{
ESM::GameSetting gmst;
gmst.mId = sIntegers[i];
gmst.mI = 0;
gmst.mType = ESM::VT_Long;
gmst.mValue.setType (ESM::VT_Int);
addOptionalGmst (gmst);
}
@ -134,8 +132,8 @@ void CSMDoc::Document::addOptionalGmsts()
{
ESM::GameSetting gmst;
gmst.mId = sStrings[i];
gmst.mStr = "<no text>";
gmst.mType = ESM::VT_String;
gmst.mValue.setType (ESM::VT_String);
gmst.mValue.setString ("<no text>");
addOptionalGmst (gmst);
}
}

@ -100,13 +100,13 @@ namespace CSMWorld
virtual QVariant get (const Record<ESXRecordT>& record) const
{
return static_cast<int> (record.get().mType);
return static_cast<int> (record.get().mValue.getType());
}
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
ESXRecordT record2 = record.get();
record2.mType = static_cast<ESM::VarType> (data.toInt());
record2.mValue.setType (static_cast<ESM::VarType> (data.toInt()));
record.setModified (record2);
}
@ -123,11 +123,11 @@ namespace CSMWorld
virtual QVariant get (const Record<ESXRecordT>& record) const
{
switch (record.get().mType)
switch (record.get().mValue.getType())
{
case ESM::VT_String: return record.get().mStr.c_str(); break;
case ESM::VT_Int: return record.get().mI; break;
case ESM::VT_Float: return record.get().mF; break;
case ESM::VT_String: return record.get().mValue.getString().c_str(); break;
case ESM::VT_Int: return record.get().mValue.getInteger(); break;
case ESM::VT_Float: return record.get().mValue.getFloat(); break;
default: return QVariant();
}
@ -137,11 +137,22 @@ namespace CSMWorld
{
ESXRecordT record2 = record.get();
switch (record2.mType)
switch (record2.mValue.getType())
{
case ESM::VT_String: record2.mStr = data.toString().toUtf8().constData(); break;
case ESM::VT_Int: record2.mI = data.toInt(); break;
case ESM::VT_Float: record2.mF = data.toFloat(); break;
case ESM::VT_String:
record2.mValue.setString (data.toString().toUtf8().constData());
break;
case ESM::VT_Int:
record2.mValue.setInteger (data.toInt());
break;
case ESM::VT_Float:
record2.mValue.setFloat (data.toFloat());
break;
default: break;
}

@ -6,6 +6,7 @@
#include <QAbstractTableModel>
#include <components/esm/esmreader.hpp>
#include <components/esm/defs.hpp>
#include <components/esm/loadglob.hpp>
#include "idtable.hpp"

@ -569,7 +569,7 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
else
mMessageBoxManager->createMessageBox(message);
}
else
{
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
@ -592,8 +592,9 @@ std::string WindowManager::getGameSettingString(const std::string &id, const std
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search(id);
if (setting && setting->mType == ESM::VT_String)
return setting->getString();
if (setting && setting->mValue.getType()==ESM::VT_String)
return setting->mValue.getString();
return default_;
}
@ -774,8 +775,8 @@ void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _r
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(tag);
if (setting && setting->mType == ESM::VT_String)
_result = setting->getString();
if (setting && setting->mValue.getType()==ESM::VT_String)
_result = setting->mValue.getString();
else
_result = tag;
}

@ -198,7 +198,7 @@ namespace MWWorld
for (std::vector<std::string>::size_type i = 0; i < master.size(); i++, idx++)
{
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master[i]));
std::cout << "Loading ESM " << masterPath.string() << "\n";
// This parses the ESM file
@ -210,11 +210,11 @@ namespace MWWorld
mEsm[idx] = lEsm;
mStore.load (mEsm[idx]);
}
for (std::vector<std::string>::size_type i = 0; i < plugins.size(); i++, idx++)
{
boost::filesystem::path pluginPath (fileCollections.getCollection (".esp").getPath (plugins[i]));
std::cout << "Loading ESP " << pluginPath.string() << "\n";
// This parses the ESP file
@ -226,7 +226,7 @@ namespace MWWorld
mEsm[idx] = lEsm;
mStore.load (mEsm[idx]);
}
mStore.setUp();
mPlayer = new MWWorld::Player (mStore.get<ESM::NPC>().find ("player"), *this);
@ -363,10 +363,8 @@ namespace MWWorld
const ESM::GameSetting *setting =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
if (setting && setting->mType == ESM::VT_String)
name = setting->getString();
else
name = "Wilderness";
if (setting && setting->mValue.getType()==ESM::VT_String)
name = setting->mValue.getString();
}
}

@ -1,104 +1,39 @@
#include "loadgmst.hpp"
#include <stdexcept>
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
void GameSetting::load(ESMReader &esm)
{
assert(mId != "");
// We are apparently allowed to be empty
if (!esm.hasMoreSubs())
void GameSetting::load (ESMReader &esm)
{
mType = VT_None;
return;
mValue.read (esm, ESM::Variant::Format_Gmst);
}
// Load some data
esm.getSubName();
NAME n = esm.retSubName();
if (n == "STRV")
void GameSetting::save (ESMWriter &esm)
{
mStr = esm.getHString();
mType = VT_String;
mValue.write (esm, ESM::Variant::Format_Gmst);
}
else if (n == "INTV")
{
esm.getHT(mI);
mType = VT_Int;
}
else if (n == "FLTV")
{
esm.getHT(mF);
mType = VT_Float;
}
else
esm.fail("Unwanted subrecord type");
}
void GameSetting::save(ESMWriter &esm)
{
switch(mType)
int GameSetting::getInt() const
{
case VT_String: esm.writeHNString("STRV", mStr); break;
case VT_Int: esm.writeHNT("INTV", mI); break;
case VT_Float: esm.writeHNT("FLTV", mF); break;
default: break;
return mValue.getInteger();
}
}
int GameSetting::getInt() const
{
switch (mType)
float GameSetting::getFloat() const
{
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");
return mValue.getFloat();
}
}
float GameSetting::getFloat() const
{
switch (mType)
std::string GameSetting::getString() const
{
case VT_Float: return mF;
case VT_Int: return mI;
default: throw std::runtime_error ("GMST " + mId + " is not of a numeric type");
return mValue.getString();
}
}
std::string GameSetting::getString() const
{
if (mType==VT_String)
return mStr;
throw std::runtime_error ("GMST " + mId + " is not a string");
}
void GameSetting::blank()
{
mStr.clear();
mI = 0;
mF = 0;
mType = VT_Float;
mValue.setType (ESM::VT_None);
}
bool operator== (const GameSetting& left, const GameSetting& right)
{
if (left.mType!=right.mType)
return false;
switch (left.mType)
{
case VT_Float: return left.mF==right.mF;
case VT_Int: return left.mI==right.mI;
case VT_String: return left.mStr==right.mStr;
default: return false;
}
return left.mValue==right.mValue;
}
}

@ -3,7 +3,6 @@
#include <string>
#include "defs.hpp"
#include "variant.hpp"
namespace ESM
@ -20,14 +19,13 @@ class ESMWriter;
struct GameSetting
{
std::string mId;
// One of these is used depending on the variable type
std::string mStr;
int mI;
float mF;
VarType mType;
Variant mValue;
void load(ESMReader &esm);
/// \todo remove the get* functions (redundant, since mValue as equivalent functions now).
int getInt() const;
///< Throws an exception if GMST is not of type int or float.

Loading…
Cancel
Save