1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/opencs/model/tools/bodypartcheck.cpp
florent.teppe 65cdd489fb create a specific esm reader function for RefID to avoid allocation for string and then again for RefId
Fixed some types

removed useless header

applied clang format

fixed compile tests

fixed clang tidy, and closer to logic before this MR

Removed hardcoded refids

unless there is a returned value we don't use static RefIds
can use == between RefId and hardcoded string

Fix clang format

Fixed a few instances where std::string was used, when only const std::string& was needed

removed unused variable
2022-12-27 19:15:57 +01:00

68 lines
2.4 KiB
C++

#include "bodypartcheck.hpp"
#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"
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();
}
void CSMTools::BodyPartCheckStage::perform(int stage, CSMDoc::Messages& messages)
{
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;
const ESM::BodyPart& bodyPart = record.get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_BodyPart, bodyPart.mId);
// Check BYDT
if (bodyPart.mData.mPart >= ESM::BodyPart::MP_Count)
messages.add(id, "Invalid part", "", CSMDoc::Message::Severity_Error);
if (bodyPart.mData.mType > ESM::BodyPart::MT_Armor)
messages.add(id, "Invalid type", "", CSMDoc::Message::Severity_Error);
// Check MODL
if (bodyPart.mModel.empty())
messages.add(id, "Model is missing", "", CSMDoc::Message::Severity_Error);
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)
if (bodyPart.mData.mType == ESM::BodyPart::MT_Skin)
{
if (bodyPart.mRace.empty())
messages.add(id, "Race is missing", "", CSMDoc::Message::Severity_Error);
else if (mRaces.searchId(bodyPart.mRace) == -1)
messages.add(id, "Race '" + bodyPart.mRace.getRefIdString() + "' does not exist", "",
CSMDoc::Message::Severity_Error);
}
}