mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 10:06:42 +00:00
use new Variant type for GMSTs
This commit is contained in:
parent
ce49ad54a1
commit
ba4907fbaf
8 changed files with 55 additions and 129 deletions
|
@ -719,23 +719,7 @@ void Record<ESM::Global>::print()
|
||||||
template<>
|
template<>
|
||||||
void Record<ESM::GameSetting>::print()
|
void Record<ESM::GameSetting>::print()
|
||||||
{
|
{
|
||||||
std::cout << " Value: ";
|
std::cout << " " << mData.mValue << std::endl;
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -116,8 +116,7 @@ void CSMDoc::Document::addOptionalGmsts()
|
||||||
{
|
{
|
||||||
ESM::GameSetting gmst;
|
ESM::GameSetting gmst;
|
||||||
gmst.mId = sFloats[i];
|
gmst.mId = sFloats[i];
|
||||||
gmst.mF = 0;
|
gmst.mValue.setType (ESM::VT_Float);
|
||||||
gmst.mType = ESM::VT_Float;
|
|
||||||
addOptionalGmst (gmst);
|
addOptionalGmst (gmst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +124,7 @@ void CSMDoc::Document::addOptionalGmsts()
|
||||||
{
|
{
|
||||||
ESM::GameSetting gmst;
|
ESM::GameSetting gmst;
|
||||||
gmst.mId = sIntegers[i];
|
gmst.mId = sIntegers[i];
|
||||||
gmst.mI = 0;
|
gmst.mValue.setType (ESM::VT_Int);
|
||||||
gmst.mType = ESM::VT_Long;
|
|
||||||
addOptionalGmst (gmst);
|
addOptionalGmst (gmst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +132,8 @@ void CSMDoc::Document::addOptionalGmsts()
|
||||||
{
|
{
|
||||||
ESM::GameSetting gmst;
|
ESM::GameSetting gmst;
|
||||||
gmst.mId = sStrings[i];
|
gmst.mId = sStrings[i];
|
||||||
gmst.mStr = "<no text>";
|
gmst.mValue.setType (ESM::VT_String);
|
||||||
gmst.mType = ESM::VT_String;
|
gmst.mValue.setString ("<no text>");
|
||||||
addOptionalGmst (gmst);
|
addOptionalGmst (gmst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,13 +100,13 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
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)
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
||||||
{
|
{
|
||||||
ESXRecordT record2 = record.get();
|
ESXRecordT record2 = record.get();
|
||||||
record2.mType = static_cast<ESM::VarType> (data.toInt());
|
record2.mValue.setType (static_cast<ESM::VarType> (data.toInt()));
|
||||||
record.setModified (record2);
|
record.setModified (record2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +123,11 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual QVariant get (const Record<ESXRecordT>& record) const
|
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_String: return record.get().mValue.getString().c_str(); break;
|
||||||
case ESM::VT_Int: return record.get().mI; break;
|
case ESM::VT_Int: return record.get().mValue.getInteger(); break;
|
||||||
case ESM::VT_Float: return record.get().mF; break;
|
case ESM::VT_Float: return record.get().mValue.getFloat(); break;
|
||||||
|
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -137,11 +137,22 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
ESXRecordT record2 = record.get();
|
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_String:
|
||||||
case ESM::VT_Int: record2.mI = data.toInt(); break;
|
|
||||||
case ESM::VT_Float: record2.mF = data.toFloat(); break;
|
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;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
#include <components/esm/esmreader.hpp>
|
#include <components/esm/esmreader.hpp>
|
||||||
|
#include <components/esm/defs.hpp>
|
||||||
#include <components/esm/loadglob.hpp>
|
#include <components/esm/loadglob.hpp>
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#include "idtable.hpp"
|
||||||
|
|
|
@ -569,7 +569,7 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
|
||||||
else
|
else
|
||||||
mMessageBoxManager->createMessageBox(message);
|
mMessageBoxManager->createMessageBox(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
|
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
|
||||||
|
@ -592,8 +592,9 @@ std::string WindowManager::getGameSettingString(const std::string &id, const std
|
||||||
const ESM::GameSetting *setting =
|
const ESM::GameSetting *setting =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search(id);
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search(id);
|
||||||
|
|
||||||
if (setting && setting->mType == ESM::VT_String)
|
if (setting && setting->mValue.getType()==ESM::VT_String)
|
||||||
return setting->getString();
|
return setting->mValue.getString();
|
||||||
|
|
||||||
return default_;
|
return default_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,8 +775,8 @@ void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _r
|
||||||
const ESM::GameSetting *setting =
|
const ESM::GameSetting *setting =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(tag);
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(tag);
|
||||||
|
|
||||||
if (setting && setting->mType == ESM::VT_String)
|
if (setting && setting->mValue.getType()==ESM::VT_String)
|
||||||
_result = setting->getString();
|
_result = setting->mValue.getString();
|
||||||
else
|
else
|
||||||
_result = tag;
|
_result = tag;
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ namespace MWWorld
|
||||||
for (std::vector<std::string>::size_type i = 0; i < master.size(); i++, idx++)
|
for (std::vector<std::string>::size_type i = 0; i < master.size(); i++, idx++)
|
||||||
{
|
{
|
||||||
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master[i]));
|
boost::filesystem::path masterPath (fileCollections.getCollection (".esm").getPath (master[i]));
|
||||||
|
|
||||||
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
||||||
|
|
||||||
// This parses the ESM file
|
// This parses the ESM file
|
||||||
|
@ -210,11 +210,11 @@ namespace MWWorld
|
||||||
mEsm[idx] = lEsm;
|
mEsm[idx] = lEsm;
|
||||||
mStore.load (mEsm[idx]);
|
mStore.load (mEsm[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::string>::size_type i = 0; i < plugins.size(); i++, 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]));
|
boost::filesystem::path pluginPath (fileCollections.getCollection (".esp").getPath (plugins[i]));
|
||||||
|
|
||||||
std::cout << "Loading ESP " << pluginPath.string() << "\n";
|
std::cout << "Loading ESP " << pluginPath.string() << "\n";
|
||||||
|
|
||||||
// This parses the ESP file
|
// This parses the ESP file
|
||||||
|
@ -226,7 +226,7 @@ namespace MWWorld
|
||||||
mEsm[idx] = lEsm;
|
mEsm[idx] = lEsm;
|
||||||
mStore.load (mEsm[idx]);
|
mStore.load (mEsm[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
mStore.setUp();
|
mStore.setUp();
|
||||||
|
|
||||||
mPlayer = new MWWorld::Player (mStore.get<ESM::NPC>().find ("player"), *this);
|
mPlayer = new MWWorld::Player (mStore.get<ESM::NPC>().find ("player"), *this);
|
||||||
|
@ -363,10 +363,8 @@ namespace MWWorld
|
||||||
const ESM::GameSetting *setting =
|
const ESM::GameSetting *setting =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().search("sDefaultCellname");
|
||||||
|
|
||||||
if (setting && setting->mType == ESM::VT_String)
|
if (setting && setting->mValue.getType()==ESM::VT_String)
|
||||||
name = setting->getString();
|
name = setting->mValue.getString();
|
||||||
else
|
|
||||||
name = "Wilderness";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,104 +1,39 @@
|
||||||
#include "loadgmst.hpp"
|
#include "loadgmst.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#include "esmreader.hpp"
|
|
||||||
#include "esmwriter.hpp"
|
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
|
void GameSetting::load (ESMReader &esm)
|
||||||
void GameSetting::load(ESMReader &esm)
|
|
||||||
{
|
|
||||||
assert(mId != "");
|
|
||||||
|
|
||||||
// We are apparently allowed to be empty
|
|
||||||
if (!esm.hasMoreSubs())
|
|
||||||
{
|
{
|
||||||
mType = VT_None;
|
mValue.read (esm, ESM::Variant::Format_Gmst);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load some data
|
void GameSetting::save (ESMWriter &esm)
|
||||||
esm.getSubName();
|
|
||||||
NAME n = esm.retSubName();
|
|
||||||
if (n == "STRV")
|
|
||||||
{
|
{
|
||||||
mStr = esm.getHString();
|
mValue.write (esm, ESM::Variant::Format_Gmst);
|
||||||
mType = VT_String;
|
|
||||||
}
|
}
|
||||||
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)
|
int GameSetting::getInt() const
|
||||||
{
|
|
||||||
switch(mType)
|
|
||||||
{
|
{
|
||||||
case VT_String: esm.writeHNString("STRV", mStr); break;
|
return mValue.getInteger();
|
||||||
case VT_Int: esm.writeHNT("INTV", mI); break;
|
|
||||||
case VT_Float: esm.writeHNT("FLTV", mF); break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int GameSetting::getInt() const
|
float GameSetting::getFloat() const
|
||||||
{
|
|
||||||
switch (mType)
|
|
||||||
{
|
{
|
||||||
case VT_Float: return static_cast<int> (mF);
|
return mValue.getFloat();
|
||||||
case VT_Int: return mI;
|
|
||||||
default: throw std::runtime_error ("GMST " + mId + " is not of a numeric type");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
float GameSetting::getFloat() const
|
std::string GameSetting::getString() const
|
||||||
{
|
|
||||||
switch (mType)
|
|
||||||
{
|
{
|
||||||
case VT_Float: return mF;
|
return mValue.getString();
|
||||||
case VT_Int: return mI;
|
|
||||||
default: throw std::runtime_error ("GMST " + mId + " is not of a numeric type");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::string GameSetting::getString() const
|
|
||||||
{
|
|
||||||
if (mType==VT_String)
|
|
||||||
return mStr;
|
|
||||||
|
|
||||||
throw std::runtime_error ("GMST " + mId + " is not a string");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameSetting::blank()
|
void GameSetting::blank()
|
||||||
{
|
{
|
||||||
mStr.clear();
|
mValue.setType (ESM::VT_None);
|
||||||
mI = 0;
|
|
||||||
mF = 0;
|
|
||||||
mType = VT_Float;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== (const GameSetting& left, const GameSetting& right)
|
bool operator== (const GameSetting& left, const GameSetting& right)
|
||||||
{
|
{
|
||||||
if (left.mType!=right.mType)
|
return left.mValue==right.mValue;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "defs.hpp"
|
|
||||||
#include "variant.hpp"
|
#include "variant.hpp"
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
|
@ -20,14 +19,13 @@ class ESMWriter;
|
||||||
struct GameSetting
|
struct GameSetting
|
||||||
{
|
{
|
||||||
std::string mId;
|
std::string mId;
|
||||||
// One of these is used depending on the variable type
|
|
||||||
std::string mStr;
|
Variant mValue;
|
||||||
int mI;
|
|
||||||
float mF;
|
|
||||||
VarType mType;
|
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
void load(ESMReader &esm);
|
||||||
|
|
||||||
|
/// \todo remove the get* functions (redundant, since mValue as equivalent functions now).
|
||||||
|
|
||||||
int getInt() const;
|
int getInt() const;
|
||||||
///< Throws an exception if GMST is not of type int or float.
|
///< Throws an exception if GMST is not of type int or float.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue