Add magic effect verifier
parent
06f170a8e1
commit
0ea4d1981a
@ -0,0 +1,137 @@
|
||||
#include "magiceffectcheck.hpp"
|
||||
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
|
||||
#include "../world/resources.hpp"
|
||||
#include "../world/data.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
void addMessageIfNotEmpty(CSMDoc::Messages &messages, const CSMWorld::UniversalId &id, const std::string text)
|
||||
{
|
||||
if (!text.empty())
|
||||
{
|
||||
messages.push_back(std::make_pair(id, text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CSMTools::MagicEffectCheckStage::isTextureExists(const std::string &texture, bool isIcon) const
|
||||
{
|
||||
const CSMWorld::Resources &textures = isIcon ? mIcons : mTextures;
|
||||
bool exists = false;
|
||||
|
||||
if (textures.searchId(texture) != -1)
|
||||
{
|
||||
exists = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string ddsTexture = texture;
|
||||
if (Misc::ResourceHelpers::changeExtensionToDds(ddsTexture) && textures.searchId(ddsTexture) != -1)
|
||||
{
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
std::string CSMTools::MagicEffectCheckStage::checkReferenceable(const std::string &id,
|
||||
const CSMWorld::UniversalId &type,
|
||||
const std::string &column) const
|
||||
{
|
||||
std::string error;
|
||||
if (!id.empty())
|
||||
{
|
||||
CSMWorld::RefIdData::LocalIndex index = mReferenceables.getDataSet().searchId(id);
|
||||
if (index.first == -1)
|
||||
{
|
||||
error = "No such " + column + " '" + id + "'";
|
||||
}
|
||||
else if (index.second != type.getType())
|
||||
{
|
||||
error = column + " is not of type " + type.getTypeName();
|
||||
}
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
std::string CSMTools::MagicEffectCheckStage::checkSound(const std::string &id, const std::string &column) const
|
||||
{
|
||||
std::string error;
|
||||
if (!id.empty() && mSounds.searchId(id) == -1)
|
||||
{
|
||||
error = "No such " + column + " '" + id + "'";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
CSMTools::MagicEffectCheckStage::MagicEffectCheckStage(const CSMWorld::IdCollection<ESM::MagicEffect> &effects,
|
||||
const CSMWorld::IdCollection<ESM::Sound> &sounds,
|
||||
const CSMWorld::RefIdCollection &referenceables,
|
||||
const CSMWorld::Resources &icons,
|
||||
const CSMWorld::Resources &textures)
|
||||
: mMagicEffects(effects),
|
||||
mSounds(sounds),
|
||||
mReferenceables(referenceables),
|
||||
mIcons(icons),
|
||||
mTextures(textures)
|
||||
{}
|
||||
|
||||
int CSMTools::MagicEffectCheckStage::setup()
|
||||
{
|
||||
return mMagicEffects.getSize();
|
||||
}
|
||||
|
||||
void CSMTools::MagicEffectCheckStage::perform(int stage, CSMDoc::Messages &messages)
|
||||
{
|
||||
ESM::MagicEffect effect = mMagicEffects.getRecord(stage).get();
|
||||
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_MagicEffect, effect.mId);
|
||||
|
||||
if (effect.mData.mBaseCost < 0.0f)
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "Base Cost is negative"));
|
||||
}
|
||||
|
||||
if (effect.mIcon.empty())
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "Icon is not specified"));
|
||||
}
|
||||
else if (!isTextureExists(effect.mIcon, true))
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "No such Icon '" + effect.mIcon + "'"));
|
||||
}
|
||||
|
||||
if (effect.mParticle.empty())
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "Particle is not specified"));
|
||||
}
|
||||
else if (!isTextureExists(effect.mParticle, false))
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "No such Particle '" + effect.mParticle + "'"));
|
||||
}
|
||||
|
||||
addMessageIfNotEmpty(messages,
|
||||
id,
|
||||
checkReferenceable(effect.mCasting, CSMWorld::UniversalId::Type_Static, "Casting Object"));
|
||||
addMessageIfNotEmpty(messages,
|
||||
id,
|
||||
checkReferenceable(effect.mHit, CSMWorld::UniversalId::Type_Static, "Hit Object"));
|
||||
addMessageIfNotEmpty(messages,
|
||||
id,
|
||||
checkReferenceable(effect.mArea, CSMWorld::UniversalId::Type_Static, "Area Object"));
|
||||
addMessageIfNotEmpty(messages,
|
||||
id,
|
||||
checkReferenceable(effect.mBolt, CSMWorld::UniversalId::Type_Weapon, "Bolt Object"));
|
||||
|
||||
addMessageIfNotEmpty(messages, id, checkSound(effect.mCastSound, "Casting Sound"));
|
||||
addMessageIfNotEmpty(messages, id, checkSound(effect.mHitSound, "Hit Sound"));
|
||||
addMessageIfNotEmpty(messages, id, checkSound(effect.mAreaSound, "Area Sound"));
|
||||
addMessageIfNotEmpty(messages, id, checkSound(effect.mBoltSound, "Bolt Sound"));
|
||||
|
||||
if (effect.mDescription.empty())
|
||||
{
|
||||
messages.push_back(std::make_pair(id, "Description is empty"));
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
#ifndef CSM_TOOLS_MAGICEFFECTCHECK_HPP
|
||||
#define CSM_TOOLS_MAGICEFFECTCHECK_HPP
|
||||
|
||||
#include <components/esm/loadmgef.hpp>
|
||||
#include <components/esm/loadsoun.hpp>
|
||||
|
||||
#include "../world/idcollection.hpp"
|
||||
#include "../world/refidcollection.hpp"
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Resources;
|
||||
}
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
/// \brief VerifyStage: make sure that magic effect records are internally consistent
|
||||
class MagicEffectCheckStage : public CSMDoc::Stage
|
||||
{
|
||||
const CSMWorld::IdCollection<ESM::MagicEffect> &mMagicEffects;
|
||||
const CSMWorld::IdCollection<ESM::Sound> &mSounds;
|
||||
const CSMWorld::RefIdCollection &mReferenceables;
|
||||
const CSMWorld::Resources &mIcons;
|
||||
const CSMWorld::Resources &mTextures;
|
||||
|
||||
private:
|
||||
bool isTextureExists(const std::string &texture, bool isIcon) const;
|
||||
|
||||
std::string checkReferenceable(const std::string &id,
|
||||
const CSMWorld::UniversalId &type,
|
||||
const std::string &column) const;
|
||||
std::string checkSound(const std::string &id, const std::string &column) const;
|
||||
|
||||
public:
|
||||
MagicEffectCheckStage(const CSMWorld::IdCollection<ESM::MagicEffect> &effects,
|
||||
const CSMWorld::IdCollection<ESM::Sound> &sounds,
|
||||
const CSMWorld::RefIdCollection &referenceables,
|
||||
const CSMWorld::Resources &icons,
|
||||
const CSMWorld::Resources &textures);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
virtual void perform (int stage, CSMDoc::Messages &messages);
|
||||
///< Messages resulting from this tage will be appended to \a messages.
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue