1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 19:23:52 +00:00
openmw/apps/opencs/model/tools/bodypartcheck.cpp

68 lines
2.4 KiB
C++
Raw Normal View History

#include "bodypartcheck.hpp"
2022-10-19 17:02:00 +00:00
#include <string>
#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/resources.hpp>
#include <apps/opencs/model/world/universalid.hpp>
#include <components/esm3/loadbody.hpp>
#include "../prefs/state.hpp"
2022-09-22 18:26:05 +00:00
CSMTools::BodyPartCheckStage::BodyPartCheckStage(const CSMWorld::IdCollection<ESM::BodyPart>& bodyParts,
const CSMWorld::Resources& meshes, const CSMWorld::IdCollection<ESM::Race>& races)
: mBodyParts(bodyParts)
, mMeshes(meshes)
, mRaces(races)
{
mIgnoreBaseRecords = false;
}
int CSMTools::BodyPartCheckStage::setup()
{
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
return mBodyParts.getSize();
}
2022-09-22 18:26:05 +00:00
void CSMTools::BodyPartCheckStage::perform(int stage, CSMDoc::Messages& messages)
{
2022-09-22 18:26:05 +00:00
const CSMWorld::Record<ESM::BodyPart>& record = mBodyParts.getRecord(stage);
// Skip "Base" records (setting!) and "Deleted" records
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
return;
2022-09-22 18:26:05 +00:00
const ESM::BodyPart& bodyPart = record.get();
2022-09-22 18:26:05 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_BodyPart, bodyPart.mId);
// Check BYDT
2022-09-22 18:26:05 +00:00
if (bodyPart.mData.mPart >= ESM::BodyPart::MP_Count)
messages.add(id, "Invalid part", "", CSMDoc::Message::Severity_Error);
2022-09-22 18:26:05 +00:00
if (bodyPart.mData.mType > ESM::BodyPart::MT_Armor)
messages.add(id, "Invalid type", "", CSMDoc::Message::Severity_Error);
// Check MODL
2022-09-22 18:26:05 +00:00
if (bodyPart.mModel.empty())
messages.add(id, "Model is missing", "", CSMDoc::Message::Severity_Error);
2022-09-22 18:26:05 +00:00
else if (mMeshes.searchId(bodyPart.mModel) == -1)
messages.add(id, "Model '" + bodyPart.mModel + "' does not exist", "", CSMDoc::Message::Severity_Error);
// Check FNAM for skin body parts (for non-skin body parts it's meaningless)
2022-09-22 18:26:05 +00:00
if (bodyPart.mData.mType == ESM::BodyPart::MT_Skin)
{
2022-09-22 18:26:05 +00:00
if (bodyPart.mRace.empty())
messages.add(id, "Race is missing", "", CSMDoc::Message::Severity_Error);
2022-09-22 18:26:05 +00:00
else if (mRaces.searchId(bodyPart.mRace) == -1)
messages.add(id, "Race '" + bodyPart.mRace.getRefIdString() + "' does not exist", "",
CSMDoc::Message::Severity_Error);
}
}