1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 20:45:33 +00:00

Added Referencable checks class, added method to get refidcontainer, added method to get mBooks.

Currently only books are checked, and only if name is present.
This commit is contained in:
Marek Kochanowicz 2013-12-20 20:02:42 +01:00
parent 230bbf06ba
commit 8085fcc792
8 changed files with 111 additions and 3 deletions

View file

@ -38,7 +38,7 @@ opencs_units (model/tools
opencs_units_noqt (model/tools
mandatoryid skillcheck classcheck factioncheck racecheck soundcheck regioncheck
birthsigncheck spellcheck
birthsigncheck spellcheck referenceablecheck
)

View file

@ -0,0 +1,63 @@
#include "referenceablecheck.hpp"
#include <sstream>
#include <map>
#include <cassert>
#include <components/esm/loadbook.hpp>
#include "../world/record.hpp"
#include "../world/universalid.hpp"
CSMTools::ReferenceableCheckStage::ReferenceableCheckStage(const CSMWorld::RefIdData& referenceable) :
mReferencables(referenceable),
mBooksSize(0)
{
setSizeVariables();
}
void CSMTools::ReferenceableCheckStage::perform(int stage, std::vector< std::string >& messages)
{
//Checks for books, than, when stage is above mBooksSize goes to other checks, with stage - minus prev sizes as stage.
bool CheckPerformed = false;
if (stage <= mBooksSize)
{
bookCheck(stage, mReferencables.getBooks(), messages);
CheckPerformed = true;
}
if (CheckPerformed)
{
return;
}
}
int CSMTools::ReferenceableCheckStage::setup()
{
return mReferencables.getSize();
}
void CSMTools::ReferenceableCheckStage::bookCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Book >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Book& Book = (static_cast<const CSMWorld::Record<ESM::Book>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Book, Book.mId);
//Checking for name
if (Book.mName.empty())
{
messages.push_back(id.toString() + "|" + Book.mId + " has an empty name");
}
}
void CSMTools::ReferenceableCheckStage::setSizeVariables()
{
mBooksSize = mReferencables.getBooks().getSize();
}

View file

@ -0,0 +1,26 @@
#ifndef REFERENCEABLECHECKSTAGE_H
#define REFERENCEABLECHECKSTAGE_H
#include "../world/universalid.hpp"
#include "../doc/stage.hpp"
#include "../world/data.hpp"
#include "../world/refiddata.hpp"
namespace CSMTools
{
class ReferenceableCheckStage : public CSMDoc::Stage
{
public:
ReferenceableCheckStage(const CSMWorld::RefIdData& referenceable);
virtual void perform(int stage, std::vector< std::string >& messages);
virtual int setup();
private:
void bookCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Book >& records, std::vector< std::string >& messages);
void setSizeVariables();
const CSMWorld::RefIdData mReferencables;
int mBooksSize;
};
}
#endif // REFERENCEABLECHECKSTAGE_H

View file

@ -19,6 +19,7 @@
#include "regioncheck.hpp"
#include "birthsigncheck.hpp"
#include "spellcheck.hpp"
#include "referenceablecheck.hpp"
CSMDoc::Operation *CSMTools::Tools::get (int type)
{
@ -74,6 +75,8 @@ CSMDoc::Operation *CSMTools::Tools::getVerifier()
mVerifier->appendStage (new BirthsignCheckStage (mData.getBirthsigns()));
mVerifier->appendStage (new SpellCheckStage (mData.getSpells()));
mVerifier->appendStage( new ReferenceableCheckStage (mData.getReferenceables().getDataSet()));
}
return mVerifier;
@ -138,4 +141,4 @@ void CSMTools::Tools::verifierMessage (const QString& message, int type)
if (iter!=mActiveReports.end())
mReports[iter->second]->add (message.toStdString());
}
}

View file

@ -549,3 +549,9 @@ void CSMWorld::RefIdCollection::save (int index, ESM::ESMWriter& writer) const
{
mData.save (index, writer);
}
const CSMWorld::RefIdData& CSMWorld::RefIdCollection::getDataSet() const
{
return mData;
}

View file

@ -107,6 +107,8 @@ namespace CSMWorld
/// \return Success?
void save (int index, ESM::ESMWriter& writer) const;
const RefIdData& getDataSet() const; //I can't figure out a better name for this one :(
};
}

View file

@ -230,4 +230,9 @@ void CSMWorld::RefIdData::save (int index, ESM::ESMWriter& writer) const
throw std::logic_error ("invalid local index type");
iter->second->save (localIndex.first, writer);
}
}
const CSMWorld::RefIdDataContainer< ESM::Book >& CSMWorld::RefIdData::getBooks() const
{
return mBooks;
}

View file

@ -219,6 +219,9 @@ namespace CSMWorld
/// \param listDeleted include deleted record in the list
void save (int index, ESM::ESMWriter& writer) const;
//RECORD CONTAINERS ACCESS METHODS
const RefIdDataContainer<ESM::Book>& getBooks() const;
};
}