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

116 lines
4.3 KiB
C++
Raw Normal View History

2015-08-03 16:08:01 +00:00
#include "magiceffectcheck.hpp"
#include <components/misc/resourcehelpers.hpp>
#include "../prefs/state.hpp"
2015-08-03 16:08:01 +00:00
#include "../world/data.hpp"
namespace
{
2018-08-24 13:57:32 +00:00
void addMessage(CSMDoc::Messages &messages, const CSMWorld::UniversalId &id, const std::string& text)
2015-08-03 16:08:01 +00:00
{
if (!text.empty())
{
messages.push_back(std::make_pair(id, text));
}
}
}
2018-08-24 13:57:32 +00:00
std::string CSMTools::MagicEffectCheckStage::checkTexture(const std::string &texture, bool isIcon) const
2015-08-03 16:08:01 +00:00
{
2018-08-24 20:12:11 +00:00
if (texture.empty()) return (isIcon ? "Icon is missing" : std::string());
2018-08-24 13:57:32 +00:00
2015-08-03 16:08:01 +00:00
const CSMWorld::Resources &textures = isIcon ? mIcons : mTextures;
2018-08-24 13:57:32 +00:00
if (textures.searchId(texture) != -1) return std::string();
2015-08-03 16:08:01 +00:00
2018-08-24 13:57:32 +00:00
std::string ddsTexture = texture;
if (Misc::ResourceHelpers::changeExtensionToDds(ddsTexture) && textures.searchId(ddsTexture) != -1) return std::string();
2015-08-03 16:08:01 +00:00
2018-08-24 13:57:32 +00:00
return (isIcon ? "Icon '" : "Particle '") + texture + "' does not exist";
2015-08-03 16:08:01 +00:00
}
2018-08-24 13:57:32 +00:00
std::string CSMTools::MagicEffectCheckStage::checkObject(const std::string &id,
2015-08-03 16:08:01 +00:00
const CSMWorld::UniversalId &type,
const std::string &column) const
{
std::string error;
if (!id.empty())
{
2018-08-24 13:57:32 +00:00
CSMWorld::RefIdData::LocalIndex index = mObjects.getDataSet().searchId(id);
2015-08-03 16:08:01 +00:00
if (index.first == -1)
{
2018-08-24 13:57:32 +00:00
error = column + " '" + id + "' " + "does not exist";
2015-08-03 16:08:01 +00:00
}
else if (index.second != type.getType())
{
2018-08-24 13:57:32 +00:00
error = column + " '" + id + "' " + "does not have " + type.getTypeName() + " type";
2015-08-03 16:08:01 +00:00
}
}
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)
{
2018-08-24 13:57:32 +00:00
error = column + " '" + id + "' " + "does not exist";
2015-08-03 16:08:01 +00:00
}
return error;
}
CSMTools::MagicEffectCheckStage::MagicEffectCheckStage(const CSMWorld::IdCollection<ESM::MagicEffect> &effects,
const CSMWorld::IdCollection<ESM::Sound> &sounds,
2018-08-24 13:57:32 +00:00
const CSMWorld::RefIdCollection &objects,
2015-08-03 16:08:01 +00:00
const CSMWorld::Resources &icons,
const CSMWorld::Resources &textures)
: mMagicEffects(effects),
mSounds(sounds),
2018-08-24 13:57:32 +00:00
mObjects(objects),
2015-08-03 16:08:01 +00:00
mIcons(icons),
mTextures(textures)
{
mIgnoreBaseRecords = false;
}
2015-08-03 16:08:01 +00:00
int CSMTools::MagicEffectCheckStage::setup()
{
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
2015-08-03 16:08:01 +00:00
return mMagicEffects.getSize();
}
void CSMTools::MagicEffectCheckStage::perform(int stage, CSMDoc::Messages &messages)
{
const CSMWorld::Record<ESM::MagicEffect> &record = mMagicEffects.getRecord(stage);
// Skip "Base" records (setting!) and "Deleted" records
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
return;
ESM::MagicEffect effect = record.get();
2015-08-03 16:08:01 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_MagicEffect, effect.mId);
2018-08-24 13:57:32 +00:00
if (effect.mDescription.empty())
2015-08-03 16:08:01 +00:00
{
2018-08-24 13:57:32 +00:00
addMessage(messages, id, "Description is missing");
2015-08-03 16:08:01 +00:00
}
2018-08-24 20:12:11 +00:00
2018-08-24 13:57:32 +00:00
if (effect.mData.mBaseCost < 0.0f)
2015-08-03 16:08:01 +00:00
{
2018-08-24 13:57:32 +00:00
addMessage(messages, id, "Base cost is negative");
2015-08-03 16:08:01 +00:00
}
2018-08-24 13:57:32 +00:00
addMessage(messages, id, checkTexture(effect.mIcon, true));
addMessage(messages, id, checkTexture(effect.mParticle, false));
addMessage(messages, id, checkObject(effect.mCasting, CSMWorld::UniversalId::Type_Static, "Casting object"));
addMessage(messages, id, checkObject(effect.mHit, CSMWorld::UniversalId::Type_Static, "Hit object"));
addMessage(messages, id, checkObject(effect.mArea, CSMWorld::UniversalId::Type_Static, "Area object"));
addMessage(messages, id, checkObject(effect.mBolt, CSMWorld::UniversalId::Type_Weapon, "Bolt object"));
addMessage(messages, id, checkSound(effect.mCastSound, "Casting sound"));
addMessage(messages, id, checkSound(effect.mHitSound, "Hit sound"));
addMessage(messages, id, checkSound(effect.mAreaSound, "Area sound"));
addMessage(messages, id, checkSound(effect.mBoltSound, "Bolt sound"));
2015-08-03 16:08:01 +00:00
}