2016-01-18 02:55:03 +00:00
|
|
|
#include "gmstcheck.hpp"
|
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
#include <sstream>
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <apps/opencs/model/doc/messages.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/category.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
#include <apps/opencs/model/world/idcollection.hpp>
|
|
|
|
#include <apps/opencs/model/world/record.hpp>
|
|
|
|
#include <apps/opencs/model/world/universalid.hpp>
|
|
|
|
|
|
|
|
#include <components/esm3/loadgmst.hpp>
|
2016-01-18 17:34:33 +00:00
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
#include "../world/defaultgmsts.hpp"
|
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
CSMTools::GmstCheckStage::GmstCheckStage(const CSMWorld::IdCollection<ESM::GameSetting>& gameSettings)
|
2016-01-18 02:55:03 +00:00
|
|
|
: mGameSettings(gameSettings)
|
2018-06-19 22:20:03 +00:00
|
|
|
{
|
2018-06-20 09:29:38 +00:00
|
|
|
mIgnoreBaseRecords = false;
|
2018-06-19 22:20:03 +00:00
|
|
|
}
|
2016-01-18 02:55:03 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
int CSMTools::GmstCheckStage::setup()
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2018-06-19 22:20:03 +00:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
return mGameSettings.getSize();
|
|
|
|
}
|
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
void CSMTools::GmstCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
|
|
|
const CSMWorld::Record<ESM::GameSetting>& record = mGameSettings.getRecord(stage);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
2018-06-20 09:29:38 +00:00
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
2016-01-18 02:55:03 +00:00
|
|
|
return;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
const ESM::GameSetting& gmst = record.get();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Gmst, gmst.mId);
|
2022-10-18 07:26:55 +00:00
|
|
|
const std::string& gmstIdString = gmst.mId.getRefIdString();
|
2016-01-18 02:55:03 +00:00
|
|
|
// Test for empty string
|
|
|
|
if (gmst.mValue.getType() == ESM::VT_String && gmst.mValue.getString().empty())
|
2022-10-06 17:39:46 +00:00
|
|
|
messages.add(id, gmstIdString + " is an empty string", "", CSMDoc::Message::Severity_Warning);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
// Checking type and limits
|
|
|
|
// optimization - compare it to lists based on naming convention (f-float,i-int,s-string)
|
2023-03-01 21:48:00 +00:00
|
|
|
if (gmst.mId.startsWith("f"))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2016-01-18 17:34:33 +00:00
|
|
|
for (size_t i = 0; i < CSMWorld::DefaultGmsts::FloatCount; ++i)
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2022-10-06 17:39:46 +00:00
|
|
|
if (gmst.mId == ESM::RefId::stringRefId(CSMWorld::DefaultGmsts::Floats[i]))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
|
|
|
if (gmst.mValue.getType() != ESM::VT_Float)
|
2016-01-18 17:34:33 +00:00
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << "Expected float type for " << gmst.mId << " but found "
|
|
|
|
<< varTypeToString(gmst.mValue.getType()) << " type";
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
if (gmst.mValue.getFloat() < CSMWorld::DefaultGmsts::FloatLimits[i * 2])
|
|
|
|
messages.add(
|
2022-10-06 17:39:46 +00:00
|
|
|
id, gmstIdString + " is less than the suggested range", "", CSMDoc::Message::Severity_Warning);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
if (gmst.mValue.getFloat() > CSMWorld::DefaultGmsts::FloatLimits[i * 2 + 1])
|
|
|
|
messages.add(
|
2022-10-06 17:39:46 +00:00
|
|
|
id, gmstIdString + " is more than the suggested range", "", CSMDoc::Message::Severity_Warning);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
break; // for loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 21:48:00 +00:00
|
|
|
else if (gmst.mId.startsWith("i"))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2016-01-18 17:34:33 +00:00
|
|
|
for (size_t i = 0; i < CSMWorld::DefaultGmsts::IntCount; ++i)
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2022-10-06 17:39:46 +00:00
|
|
|
if (gmst.mId == ESM::RefId::stringRefId(CSMWorld::DefaultGmsts::Ints[i]))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
|
|
|
if (gmst.mValue.getType() != ESM::VT_Int)
|
2016-01-18 17:34:33 +00:00
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << "Expected int type for " << gmst.mId << " but found "
|
|
|
|
<< varTypeToString(gmst.mValue.getType()) << " type";
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
if (gmst.mValue.getInteger() < CSMWorld::DefaultGmsts::IntLimits[i * 2])
|
|
|
|
messages.add(
|
2022-10-06 17:39:46 +00:00
|
|
|
id, gmstIdString + " is less than the suggested range", "", CSMDoc::Message::Severity_Warning);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
if (gmst.mValue.getInteger() > CSMWorld::DefaultGmsts::IntLimits[i * 2 + 1])
|
|
|
|
messages.add(
|
2022-10-06 17:39:46 +00:00
|
|
|
id, gmstIdString + " is more than the suggested range", "", CSMDoc::Message::Severity_Warning);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
break; // for loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 21:48:00 +00:00
|
|
|
else if (gmst.mId.startsWith("s"))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2016-01-18 17:34:33 +00:00
|
|
|
for (size_t i = 0; i < CSMWorld::DefaultGmsts::StringCount; ++i)
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
2022-10-06 17:39:46 +00:00
|
|
|
if (gmst.mId == ESM::RefId::stringRefId(CSMWorld::DefaultGmsts::Strings[i]))
|
2016-01-18 02:55:03 +00:00
|
|
|
{
|
|
|
|
ESM::VarType type = gmst.mValue.getType();
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
if (type != ESM::VT_String && type != ESM::VT_None)
|
2016-01-18 17:34:33 +00:00
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
2022-10-06 17:39:46 +00:00
|
|
|
stream << "Expected string or none type for " << gmstIdString << " but found "
|
2016-01-18 17:34:33 +00:00
|
|
|
<< varTypeToString(gmst.mValue.getType()) << " type";
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
messages.add(id, stream.str(), "", CSMDoc::Message::Severity_Error);
|
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2016-01-18 02:55:03 +00:00
|
|
|
break; // for loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-18 17:34:33 +00:00
|
|
|
|
|
|
|
std::string CSMTools::GmstCheckStage::varTypeToString(ESM::VarType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case ESM::VT_Unknown:
|
|
|
|
return "unknown";
|
|
|
|
case ESM::VT_None:
|
|
|
|
return "none";
|
|
|
|
case ESM::VT_Short:
|
|
|
|
return "short";
|
|
|
|
case ESM::VT_Int:
|
|
|
|
return "int";
|
|
|
|
case ESM::VT_Long:
|
|
|
|
return "long";
|
|
|
|
case ESM::VT_Float:
|
|
|
|
return "float";
|
|
|
|
case ESM::VT_String:
|
|
|
|
return "string";
|
|
|
|
default:
|
|
|
|
return "unhandled";
|
|
|
|
}
|
|
|
|
}
|