forked from teamnwah/openmw-tes3coop
added class record verifier
This commit is contained in:
parent
8dd7f0c53a
commit
fea44c05d4
6 changed files with 110 additions and 1 deletions
|
@ -35,7 +35,7 @@ opencs_units (model/tools
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (model/tools
|
opencs_units_noqt (model/tools
|
||||||
stage verifier mandatoryid skillcheck
|
stage verifier mandatoryid skillcheck classcheck
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
63
apps/opencs/model/tools/classcheck.cpp
Normal file
63
apps/opencs/model/tools/classcheck.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
|
||||||
|
#include "classcheck.hpp"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <components/esm/loadclas.hpp>
|
||||||
|
#include <components/esm/loadskil.hpp>
|
||||||
|
|
||||||
|
#include "../world/universalid.hpp"
|
||||||
|
|
||||||
|
CSMTools::ClassCheckStage::ClassCheckStage (const CSMWorld::IdCollection<ESM::Class>& classes)
|
||||||
|
: mClasses (classes)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int CSMTools::ClassCheckStage::setup()
|
||||||
|
{
|
||||||
|
return mClasses.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMTools::ClassCheckStage::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
const ESM::Class& class_= mClasses.getRecord (stage).get();
|
||||||
|
|
||||||
|
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Class, class_.mId);
|
||||||
|
|
||||||
|
// test for empty name and description
|
||||||
|
if (class_.mName.empty())
|
||||||
|
messages.push_back (id.toString() + "|" + class_.mId + " has an empty name");
|
||||||
|
|
||||||
|
if (class_.mDescription.empty())
|
||||||
|
messages.push_back (id.toString() + "|" + class_.mId + " has an empty description");
|
||||||
|
|
||||||
|
// test for invalid attributes
|
||||||
|
for (int i=0; i<2; ++i)
|
||||||
|
if (class_.mData.mAttribute[i]==-1)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream << id.toString() << "|Attribute #" << i << " of " << class_.mId << " is not set";
|
||||||
|
|
||||||
|
messages.push_back (stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// test for non-unique skill
|
||||||
|
std::map<int, int> skills; // ID, number of occurrences
|
||||||
|
|
||||||
|
for (int i=0; i<5; ++i)
|
||||||
|
for (int i2=0; i2<2; ++i2)
|
||||||
|
++skills[class_.mData.mSkills[i][i2]];
|
||||||
|
|
||||||
|
for (std::map<int, int>::const_iterator iter (skills.begin()); iter!=skills.end(); ++iter)
|
||||||
|
if (iter->second>1)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream
|
||||||
|
<< id.toString() << "|"
|
||||||
|
<< ESM::Skill::indexToId (iter->first) << " is listed more than once";
|
||||||
|
|
||||||
|
messages.push_back (stream.str());
|
||||||
|
}
|
||||||
|
}
|
29
apps/opencs/model/tools/classcheck.hpp
Normal file
29
apps/opencs/model/tools/classcheck.hpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef CSM_TOOLS_CLASSCHECK_H
|
||||||
|
#define CSM_TOOLS_CLASSCHECK_H
|
||||||
|
|
||||||
|
#include <components/esm/loadclas.hpp>
|
||||||
|
|
||||||
|
#include "../world/idcollection.hpp"
|
||||||
|
|
||||||
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
namespace CSMTools
|
||||||
|
{
|
||||||
|
/// \brief VerifyStage: make sure that class records are internally consistent
|
||||||
|
class ClassCheckStage : public Stage
|
||||||
|
{
|
||||||
|
const CSMWorld::IdCollection<ESM::Class>& mClasses;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ClassCheckStage (const CSMWorld::IdCollection<ESM::Class>& classes);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||||
|
///< Messages resulting from this tage will be appended to \a messages.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,6 +13,7 @@
|
||||||
#include "reportmodel.hpp"
|
#include "reportmodel.hpp"
|
||||||
#include "mandatoryid.hpp"
|
#include "mandatoryid.hpp"
|
||||||
#include "skillcheck.hpp"
|
#include "skillcheck.hpp"
|
||||||
|
#include "classcheck.hpp"
|
||||||
|
|
||||||
CSMTools::Operation *CSMTools::Tools::get (int type)
|
CSMTools::Operation *CSMTools::Tools::get (int type)
|
||||||
{
|
{
|
||||||
|
@ -54,6 +55,8 @@ CSMTools::Verifier *CSMTools::Tools::getVerifier()
|
||||||
CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Globals), mandatoryIds));
|
CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Globals), mandatoryIds));
|
||||||
|
|
||||||
mVerifier->appendStage (new SkillCheckStage (mData.getSkills()));
|
mVerifier->appendStage (new SkillCheckStage (mData.getSkills()));
|
||||||
|
|
||||||
|
mVerifier->appendStage (new ClassCheckStage (mData.getClasses()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mVerifier;
|
return mVerifier;
|
||||||
|
|
|
@ -107,6 +107,16 @@ CSMWorld::IdCollection<ESM::Skill>& CSMWorld::Data::getSkills()
|
||||||
return mSkills;
|
return mSkills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CSMWorld::IdCollection<ESM::Class>& CSMWorld::Data::getClasses() const
|
||||||
|
{
|
||||||
|
return mClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::IdCollection<ESM::Class>& CSMWorld::Data::getClasses()
|
||||||
|
{
|
||||||
|
return mClasses;
|
||||||
|
}
|
||||||
|
|
||||||
const CSMWorld::IdCollection<ESM::Faction>& CSMWorld::Data::getFactions() const
|
const CSMWorld::IdCollection<ESM::Faction>& CSMWorld::Data::getFactions() const
|
||||||
{
|
{
|
||||||
return mFactions;
|
return mFactions;
|
||||||
|
|
|
@ -54,6 +54,10 @@ namespace CSMWorld
|
||||||
|
|
||||||
IdCollection<ESM::Skill>& getSkills();
|
IdCollection<ESM::Skill>& getSkills();
|
||||||
|
|
||||||
|
const IdCollection<ESM::Class>& getClasses() const;
|
||||||
|
|
||||||
|
IdCollection<ESM::Class>& getClasses();
|
||||||
|
|
||||||
const IdCollection<ESM::Faction>& getFactions() const;
|
const IdCollection<ESM::Faction>& getFactions() const;
|
||||||
|
|
||||||
IdCollection<ESM::Faction>& getFactions();
|
IdCollection<ESM::Faction>& getFactions();
|
||||||
|
|
Loading…
Reference in a new issue