forked from mirror/openmw-tes3mp
gmst verifier
parent
ed242d8151
commit
1d86f705ba
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,91 @@
|
||||
#include "gmstcheck.hpp"
|
||||
|
||||
#include "../world/defaultgmsts.hpp"
|
||||
|
||||
CSMTools::GMSTCheckStage::GMSTCheckStage(const CSMWorld::IdCollection<ESM::GameSetting>& gameSettings)
|
||||
: mGameSettings(gameSettings)
|
||||
{}
|
||||
|
||||
int CSMTools::GMSTCheckStage::setup()
|
||||
{
|
||||
return mGameSettings.getSize();
|
||||
}
|
||||
|
||||
void CSMTools::GMSTCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
||||
{
|
||||
const CSMWorld::Record<ESM::GameSetting>& record = mGameSettings.getRecord (stage);
|
||||
|
||||
if (record.isDeleted())
|
||||
return;
|
||||
|
||||
const ESM::GameSetting& gmst = record.get();
|
||||
|
||||
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Gmst, gmst.mId);
|
||||
|
||||
// Test for empty string
|
||||
if (gmst.mValue.getType() == ESM::VT_String && gmst.mValue.getString().empty())
|
||||
messages.add(id, gmst.mId + " is an empty string", "", CSMDoc::Message::Severity_Warning);
|
||||
|
||||
// Checking type and limits
|
||||
// optimization - compare it to lists based on naming convention (f-float,i-int,s-string)
|
||||
if (gmst.mId[0] == 'f')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGMSTs::FloatCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGMSTs::Floats[i])
|
||||
{
|
||||
if (gmst.mValue.getType() != ESM::VT_Float)
|
||||
messages.add(id, "The type of " + gmst.mId + " is incorrect",
|
||||
"Change the GMST type to a float", CSMDoc::Message::Severity_Error);
|
||||
|
||||
if (gmst.mValue.getFloat() < CSMWorld::DefaultGMSTs::FloatLimits[i*2])
|
||||
messages.add(id, gmst.mId + " is less than the suggested range", "Change the value",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
if (gmst.mValue.getFloat() > CSMWorld::DefaultGMSTs::FloatLimits[i*2+1])
|
||||
messages.add(id, gmst.mId + " is more than the suggested range", "Change the value",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gmst.mId[0] == 'i')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGMSTs::IntCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGMSTs::Ints[i])
|
||||
{
|
||||
if (gmst.mValue.getType() != ESM::VT_Int)
|
||||
messages.add(id, "The type of " + gmst.mId + " is incorrect",
|
||||
"Change the GMST type to an int", CSMDoc::Message::Severity_Error);
|
||||
|
||||
if (gmst.mValue.getInteger() < CSMWorld::DefaultGMSTs::IntLimits[i*2])
|
||||
messages.add(id, gmst.mId + " is less than the suggested range", "Change the value",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
if (gmst.mValue.getInteger() > CSMWorld::DefaultGMSTs::IntLimits[i*2+1])
|
||||
messages.add(id, gmst.mId + " is more than the suggested range", "Change the value",
|
||||
CSMDoc::Message::Severity_Warning);
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gmst.mId[0] == 's')
|
||||
{
|
||||
for (size_t i = 0; i < CSMWorld::DefaultGMSTs::StringCount; ++i)
|
||||
{
|
||||
if (gmst.mId == CSMWorld::DefaultGMSTs::Strings[i])
|
||||
{
|
||||
ESM::VarType type = gmst.mValue.getType();
|
||||
|
||||
if (type != ESM::VT_String && type != ESM::VT_None)
|
||||
messages.add(id, "The type of " + gmst.mId + " is incorrect",
|
||||
"Change the GMST type to a string", CSMDoc::Message::Severity_Error);
|
||||
|
||||
break; // for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#ifndef CSM_TOOLS_GMSTCHECK_H
|
||||
#define CSM_TOOLS_GMSTCHECK_H
|
||||
|
||||
#include <components/esm/loadgmst.hpp>
|
||||
|
||||
#include "../world/idcollection.hpp"
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
/// \brief VerifyStage: make sure that GMSTs are alright
|
||||
class GMSTCheckStage : public CSMDoc::Stage
|
||||
{
|
||||
public:
|
||||
|
||||
GMSTCheckStage(const CSMWorld::IdCollection<ESM::GameSetting>& gameSettings);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
||||
virtual void perform(int stage, CSMDoc::Messages& messages);
|
||||
///< Messages resulting from this stage will be appended to \a messages
|
||||
|
||||
private:
|
||||
|
||||
const CSMWorld::IdCollection<ESM::GameSetting>& mGameSettings;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
||||
#ifndef CSM_WORLD_DEFAULTGMSTS_H
|
||||
#define CSM_WORLD_DEFAULTGMSTS_H
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace CSMWorld {
|
||||
namespace DefaultGMSTs {
|
||||
|
||||
const size_t FloatCount = 258;
|
||||
const size_t IntCount = 89;
|
||||
const size_t StringCount = 1174;
|
||||
|
||||
const size_t OptionalFloatCount = 42;
|
||||
const size_t OptionalIntCount = 4;
|
||||
const size_t OptionalStringCount = 26;
|
||||
|
||||
extern const char* Floats[];
|
||||
extern const char * Ints[];
|
||||
extern const char * Strings[];
|
||||
|
||||
extern const char * OptionalFloats[];
|
||||
extern const char * OptionalInts[];
|
||||
extern const char * OptionalStrings[];
|
||||
|
||||
extern const float FloatsDefaultValues[];
|
||||
extern const int IntsDefaultValues[];
|
||||
|
||||
extern const float FloatLimits[];
|
||||
extern const int IntLimits[];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue