forked from mirror/openmw-tes3mp
added mandatory ID check stage
This commit is contained in:
parent
72623652e4
commit
9fe7ff9690
11 changed files with 148 additions and 12 deletions
|
@ -8,6 +8,7 @@ set (OPENCS_SRC
|
||||||
model/world/commands.cpp model/world/idtableproxymodel.cpp model/world/record.cpp
|
model/world/commands.cpp model/world/idtableproxymodel.cpp model/world/record.cpp
|
||||||
|
|
||||||
model/tools/tools.cpp model/tools/operation.cpp model/tools/stage.cpp model/tools/verifier.cpp
|
model/tools/tools.cpp model/tools/operation.cpp model/tools/stage.cpp model/tools/verifier.cpp
|
||||||
|
model/tools/mandatoryid.cpp
|
||||||
|
|
||||||
view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp
|
view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ set (OPENCS_HDR
|
||||||
model/world/commands.hpp
|
model/world/commands.hpp
|
||||||
|
|
||||||
model/tools/tools.hpp model/tools/operation.hpp model/tools/stage.hpp model/tools/verifier.hpp
|
model/tools/tools.hpp model/tools/operation.hpp model/tools/stage.hpp model/tools/verifier.hpp
|
||||||
|
model/tools/mandatoryid.hpp
|
||||||
|
|
||||||
view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp
|
view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "document.hpp"
|
#include "document.hpp"
|
||||||
|
|
||||||
CSMDoc::Document::Document (const std::string& name)
|
CSMDoc::Document::Document (const std::string& name)
|
||||||
|
: mTools (mData)
|
||||||
{
|
{
|
||||||
mName = name; ///< \todo replace with ESX list
|
mName = name; ///< \todo replace with ESX list
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,13 @@ namespace CSMDoc
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string mName; ///< \todo replace name with ESX list
|
std::string mName; ///< \todo replace name with ESX list
|
||||||
QUndoStack mUndoStack;
|
|
||||||
CSMWorld::Data mData;
|
CSMWorld::Data mData;
|
||||||
CSMTools::Tools mTools;
|
CSMTools::Tools mTools;
|
||||||
|
|
||||||
|
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
||||||
|
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
||||||
|
QUndoStack mUndoStack;
|
||||||
|
|
||||||
int mSaveCount; ///< dummy implementation -> remove when proper save is implemented.
|
int mSaveCount; ///< dummy implementation -> remove when proper save is implemented.
|
||||||
QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented.
|
QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented.
|
||||||
|
|
||||||
|
|
21
apps/opencs/model/tools/mandatoryid.cpp
Normal file
21
apps/opencs/model/tools/mandatoryid.cpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
#include "mandatoryid.hpp"
|
||||||
|
|
||||||
|
#include "../world/idcollection.hpp"
|
||||||
|
|
||||||
|
CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection,
|
||||||
|
const CSMWorld::UniversalId& collectionId, const std::vector<std::string>& ids)
|
||||||
|
: mIdCollection (idCollection), mCollectionId (collectionId), mIds (ids)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int CSMTools::MandatoryIdStage::setup()
|
||||||
|
{
|
||||||
|
return mIds.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMTools::MandatoryIdStage::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
if (mIdCollection.searchId (mIds.at (stage))==-1 ||
|
||||||
|
mIdCollection.getRecord (mIds.at (stage)).isDeleted())
|
||||||
|
messages.push_back (mCollectionId.toString() + " Missing mandatory record: " + mIds.at (stage));
|
||||||
|
}
|
38
apps/opencs/model/tools/mandatoryid.hpp
Normal file
38
apps/opencs/model/tools/mandatoryid.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef CSM_TOOLS_MANDATORYID_H
|
||||||
|
#define CSM_TOOLS_MANDATORYID_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../world/universalid.hpp"
|
||||||
|
|
||||||
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
namespace CSMWorld
|
||||||
|
{
|
||||||
|
class IdCollectionBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace CSMTools
|
||||||
|
{
|
||||||
|
/// \brief Verify stage: make sure that records with specific IDs exist.
|
||||||
|
class MandatoryIdStage : public Stage
|
||||||
|
{
|
||||||
|
const CSMWorld::IdCollectionBase& mIdCollection;
|
||||||
|
CSMWorld::UniversalId mCollectionId;
|
||||||
|
std::vector<std::string> mIds;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection, const CSMWorld::UniversalId& collectionId,
|
||||||
|
const std::vector<std::string>& ids);
|
||||||
|
|
||||||
|
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
|
|
@ -19,8 +19,8 @@ void CSMTools::Operation::prepareStages()
|
||||||
|
|
||||||
for (std::vector<std::pair<Stage *, int> >::iterator iter (mStages.begin()); iter!=mStages.end(); ++iter)
|
for (std::vector<std::pair<Stage *, int> >::iterator iter (mStages.begin()); iter!=mStages.end(); ++iter)
|
||||||
{
|
{
|
||||||
iter->second = mTotalSteps;
|
iter->second = iter->first->setup();
|
||||||
mTotalSteps += iter->first->setup();
|
mTotalSteps += iter->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,15 @@ namespace CSMTools
|
||||||
{
|
{
|
||||||
class Stage
|
class Stage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Stage();
|
virtual ~Stage();
|
||||||
|
|
||||||
virtual int setup() = 0;
|
virtual int setup() = 0;
|
||||||
///< \return number of steps
|
///< \return number of steps
|
||||||
|
|
||||||
virtual void perform (int stage, std::vector<std::string>& messages) = 0;
|
virtual void perform (int stage, std::vector<std::string>& messages) = 0;
|
||||||
///< Messages resulting from this tage will be appended to \a messages.
|
///< Messages resulting from this tage will be appended to \a messages.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#include "../doc/state.hpp"
|
#include "../doc/state.hpp"
|
||||||
|
|
||||||
|
#include "../world/data.hpp"
|
||||||
|
|
||||||
|
#include "mandatoryid.hpp"
|
||||||
|
|
||||||
CSMTools::Operation *CSMTools::Tools::get (int type)
|
CSMTools::Operation *CSMTools::Tools::get (int type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
@ -32,12 +36,25 @@ CSMTools::Verifier *CSMTools::Tools::getVerifier()
|
||||||
connect (mVerifier, SIGNAL (finished()), this, SLOT (verifierDone()));
|
connect (mVerifier, SIGNAL (finished()), this, SLOT (verifierDone()));
|
||||||
connect (mVerifier, SIGNAL (reportMessage (const QString&, int)),
|
connect (mVerifier, SIGNAL (reportMessage (const QString&, int)),
|
||||||
this, SLOT (verifierMessage (const QString&, int)));
|
this, SLOT (verifierMessage (const QString&, int)));
|
||||||
|
|
||||||
|
std::vector<std::string> mandatoryIds; // I want C++11, damn it!
|
||||||
|
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");
|
||||||
|
|
||||||
|
mVerifier->appendStage (new MandatoryIdStage (mData.getGlobals(),
|
||||||
|
CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Globals), mandatoryIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mVerifier;
|
return mVerifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Tools::Tools() : mVerifier (0)
|
CSMTools::Tools::Tools (CSMWorld::Data& data) : mData (data), mVerifier (0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace CSMWorld
|
||||||
|
{
|
||||||
|
class Data;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMTools
|
namespace CSMTools
|
||||||
{
|
{
|
||||||
class Verifier;
|
class Verifier;
|
||||||
|
@ -12,6 +17,7 @@ namespace CSMTools
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
CSMWorld::Data& mData;
|
||||||
Verifier *mVerifier;
|
Verifier *mVerifier;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
|
@ -28,7 +34,7 @@ namespace CSMTools
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Tools();
|
Tools (CSMWorld::Data& data);
|
||||||
|
|
||||||
virtual ~Tools();
|
virtual ~Tools();
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,52 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSMWorld::UniversalId::UniversalId (const std::string& universalId)
|
||||||
|
{
|
||||||
|
std::string::size_type index = universalId.find (':');
|
||||||
|
|
||||||
|
if (index!=std::string::npos)
|
||||||
|
{
|
||||||
|
std::string type = universalId.substr (0, index);
|
||||||
|
|
||||||
|
for (int i=0; sNoArg[i].mName; ++i)
|
||||||
|
if (type==sNoArg[i].mName)
|
||||||
|
{
|
||||||
|
mArgumentType = ArgumentType_None;
|
||||||
|
mType = sNoArg[i].mType;
|
||||||
|
mClass = sNoArg[i].mClass;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; sIdArg[i].mName; ++i)
|
||||||
|
if (type==sIdArg[i].mName)
|
||||||
|
{
|
||||||
|
mArgumentType = ArgumentType_Id;
|
||||||
|
mType = sIdArg[i].mType;
|
||||||
|
mClass = sIdArg[i].mClass;
|
||||||
|
mId = universalId.substr (0, index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; sIndexArg[i].mName; ++i)
|
||||||
|
if (type==sIndexArg[i].mName)
|
||||||
|
{
|
||||||
|
mArgumentType = ArgumentType_Index;
|
||||||
|
mType = sIndexArg[i].mType;
|
||||||
|
mClass = sIndexArg[i].mClass;
|
||||||
|
|
||||||
|
std::istringstream stream (universalId.substr (0, index));
|
||||||
|
|
||||||
|
if (stream >> mIndex)
|
||||||
|
return;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error ("invalid UniversalId: " + universalId);
|
||||||
|
}
|
||||||
|
|
||||||
CSMWorld::UniversalId::UniversalId (Type type) : mArgumentType (ArgumentType_None), mType (type), mIndex (0)
|
CSMWorld::UniversalId::UniversalId (Type type) : mArgumentType (ArgumentType_None), mType (type), mIndex (0)
|
||||||
{
|
{
|
||||||
for (int i=0; sNoArg[i].mName; ++i)
|
for (int i=0; sNoArg[i].mName; ++i)
|
||||||
|
@ -151,7 +197,7 @@ std::string CSMWorld::UniversalId::toString() const
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
|
|
||||||
stream << getTypeName();
|
stream << getTypeName() << ":";
|
||||||
|
|
||||||
switch (mArgumentType)
|
switch (mArgumentType)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,8 @@ namespace CSMWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
UniversalId (const std::string& universalId);
|
||||||
|
|
||||||
UniversalId (Type type = Type_None);
|
UniversalId (Type type = Type_None);
|
||||||
///< Using a type for a non-argument-less UniversalId will throw an exception.
|
///< Using a type for a non-argument-less UniversalId will throw an exception.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue