mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 21:06:43 +00:00
added typesafe access functions for GMST values
This commit is contained in:
parent
fca3b67507
commit
677158c477
2 changed files with 44 additions and 0 deletions
|
@ -1,8 +1,15 @@
|
||||||
#include "loadgmst.hpp"
|
#include "loadgmst.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "defs.hpp"
|
||||||
|
|
||||||
namespace ESM
|
namespace ESM
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// \todo Review GMST "fixing". Probably remove completely or at least make it optional. Its definitely not
|
||||||
|
/// working properly in its current state and I doubt it can be fixed without breaking other stuff.
|
||||||
|
|
||||||
// Some handy macros
|
// Some handy macros
|
||||||
#define cI(s,x) { if(id == (s)) return (i == (x)); }
|
#define cI(s,x) { if(id == (s)) return (i == (x)); }
|
||||||
#define cF(s,x) { if(id == (s)) return (f == (x)); }
|
#define cF(s,x) { if(id == (s)) return (f == (x)); }
|
||||||
|
@ -169,4 +176,32 @@ void GameSetting::load(ESMReader &esm)
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GameSetting::getInt() const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case VT_Float: return static_cast<int> (f);
|
||||||
|
case VT_Int: return i;
|
||||||
|
default: throw std::runtime_error ("GMST " + id + " is not of a numeric type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int GameSetting::getFloat() const
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case VT_Float: return f;
|
||||||
|
case VT_Int: return i;
|
||||||
|
default: throw std::runtime_error ("GMST " + id + " is not of a numeric type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GameSetting::getString() const
|
||||||
|
{
|
||||||
|
if (type==VT_String)
|
||||||
|
return str;
|
||||||
|
|
||||||
|
throw std::runtime_error ("GMST " + id + " is not a string");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,15 @@ struct GameSetting
|
||||||
bool isDirtyBloodmoon();
|
bool isDirtyBloodmoon();
|
||||||
|
|
||||||
void load(ESMReader &esm);
|
void load(ESMReader &esm);
|
||||||
|
|
||||||
|
int getInt() const;
|
||||||
|
///< Throws an exception if GMST is not of type int or float.
|
||||||
|
|
||||||
|
int getFloat() const;
|
||||||
|
///< Throws an exception if GMST is not of type int or float.
|
||||||
|
|
||||||
|
std::string getString() const;
|
||||||
|
///< Throwns an exception if GMST is not of type string.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue