1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:19:55 +00:00
openmw-tes3mp/apps/opencs/model/tools/tools.cpp

145 lines
4.2 KiB
C++
Raw Normal View History

#include "tools.hpp"
#include <QThreadPool>
#include "../doc/state.hpp"
#include "../doc/operation.hpp"
2012-12-08 22:27:59 +00:00
#include "../world/data.hpp"
2012-12-11 14:35:47 +00:00
#include "../world/universalid.hpp"
2012-12-08 22:27:59 +00:00
2012-12-11 14:35:47 +00:00
#include "reportmodel.hpp"
2012-12-08 22:27:59 +00:00
#include "mandatoryid.hpp"
2013-03-25 10:07:04 +00:00
#include "skillcheck.hpp"
2013-04-04 08:10:26 +00:00
#include "classcheck.hpp"
2013-04-04 08:39:43 +00:00
#include "factioncheck.hpp"
2013-04-06 15:35:36 +00:00
#include "racecheck.hpp"
2013-04-06 19:48:52 +00:00
#include "soundcheck.hpp"
2013-04-07 17:39:13 +00:00
#include "regioncheck.hpp"
2013-04-07 21:25:35 +00:00
#include "birthsigncheck.hpp"
2013-04-09 10:44:49 +00:00
#include "spellcheck.hpp"
#include "referenceablecheck.hpp"
2012-12-08 22:27:59 +00:00
2013-12-30 12:23:16 +00:00
CSMDoc::Operation* CSMTools::Tools::get(int type)
{
switch (type)
{
case CSMDoc::State_Verifying: return mVerifier;
}
return 0;
}
2013-12-30 12:23:16 +00:00
const CSMDoc::Operation* CSMTools::Tools::get(int type) const
{
2013-12-30 12:23:16 +00:00
return const_cast<Tools*>(this)->get(type);
}
2013-12-30 12:23:16 +00:00
CSMDoc::Operation* CSMTools::Tools::getVerifier()
{
if (!mVerifier)
{
2013-12-30 12:23:16 +00:00
mVerifier = new CSMDoc::Operation(CSMDoc::State_Verifying, false);
2013-12-30 12:23:16 +00:00
connect(mVerifier, SIGNAL(progress(int, int, int)), this, SIGNAL(progress(int, int, int)));
connect(mVerifier, SIGNAL(done(int)), this, SIGNAL(done(int)));
connect(mVerifier, SIGNAL(reportMessage(const QString&, int)),
this, SLOT(verifierMessage(const QString&, int)));
2012-12-08 22:27:59 +00:00
std::vector<std::string> mandatoryIds; // I want C++11, damn it!
2013-12-30 12:23:16 +00:00
mandatoryIds.push_back("Day");
mandatoryIds.push_back("DaysPassed");
mandatoryIds.push_back("GameHour");
mandatoryIds.push_back("Month");
mandatoryIds.push_back("PCRace");
mandatoryIds.push_back("PCVampire");
mandatoryIds.push_back("PCWerewolf");
mandatoryIds.push_back("PCYear");
2012-12-08 22:27:59 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new MandatoryIdStage(mData.getGlobals(),
CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Globals), mandatoryIds));
2013-03-25 10:07:04 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new SkillCheckStage(mData.getSkills()));
2013-04-04 08:10:26 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new ClassCheckStage(mData.getClasses()));
2013-04-04 08:39:43 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new FactionCheckStage(mData.getFactions()));
2013-04-06 15:35:36 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new RaceCheckStage(mData.getRaces()));
2013-04-06 19:48:52 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new SoundCheckStage(mData.getSounds()));
2013-04-07 17:39:13 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new RegionCheckStage(mData.getRegions()));
2013-04-07 21:25:35 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new BirthsignCheckStage(mData.getBirthsigns()));
2013-04-09 10:44:49 +00:00
2013-12-30 12:23:16 +00:00
mVerifier->appendStage(new SpellCheckStage(mData.getSpells()));
mVerifier->appendStage(new ReferenceableCheckStage(mData.getReferenceables().getDataSet(), mData.getRaces(), mData.getClasses(), mData.getFactions()));
}
return mVerifier;
}
2013-12-30 12:23:16 +00:00
CSMTools::Tools::Tools(CSMWorld::Data& data) : mData(data), mVerifier(0), mNextReportNumber(0)
{
2013-12-30 12:23:16 +00:00
for (std::map<int, ReportModel*>::iterator iter(mReports.begin()); iter != mReports.end(); ++iter)
2012-12-11 14:35:47 +00:00
delete iter->second;
}
CSMTools::Tools::~Tools()
{
delete mVerifier;
}
2012-12-11 14:35:47 +00:00
CSMWorld::UniversalId CSMTools::Tools::runVerifier()
{
2013-12-30 12:23:16 +00:00
mReports.insert(std::make_pair(mNextReportNumber++, new ReportModel));
mActiveReports[CSMDoc::State_Verifying] = mNextReportNumber - 1;
2012-12-11 14:35:47 +00:00
getVerifier()->start();
2012-12-11 14:35:47 +00:00
2013-12-30 12:23:16 +00:00
return CSMWorld::UniversalId(CSMWorld::UniversalId::Type_VerificationResults, mNextReportNumber - 1);
}
2013-12-30 12:23:16 +00:00
void CSMTools::Tools::abortOperation(int type)
{
2013-12-30 12:23:16 +00:00
if (CSMDoc::Operation* operation = get(type))
operation->abort();
}
int CSMTools::Tools::getRunningOperations() const
{
static const int sOperations[] =
{
2013-12-30 12:23:16 +00:00
CSMDoc::State_Verifying,
-1
};
int result = 0;
2013-12-30 12:23:16 +00:00
for (int i = 0; sOperations[i] != -1; ++i)
if (const CSMDoc::Operation* operation = get(sOperations[i]))
if (operation->isRunning())
result |= sOperations[i];
return result;
}
2013-12-30 12:23:16 +00:00
CSMTools::ReportModel* CSMTools::Tools::getReport(const CSMWorld::UniversalId& id)
2012-12-11 14:35:47 +00:00
{
2013-12-30 12:23:16 +00:00
if (id.getType() != CSMWorld::UniversalId::Type_VerificationResults)
throw std::logic_error("invalid request for report model: " + id.toString());
2012-12-11 14:35:47 +00:00
2013-12-30 12:23:16 +00:00
return mReports.at(id.getIndex());
2012-12-11 14:35:47 +00:00
}
2013-12-30 12:23:16 +00:00
void CSMTools::Tools::verifierMessage(const QString& message, int type)
{
2013-12-30 12:23:16 +00:00
std::map<int, int>::iterator iter = mActiveReports.find(type);
2013-12-30 12:23:16 +00:00
if (iter != mActiveReports.end())
mReports[iter->second]->add(message.toStdString());
}