From d3aa5840ec380fcb029e795f31f7158f46d195a7 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Fri, 24 Aug 2018 16:57:32 +0300 Subject: [PATCH] Refactor magic effect record verifying --- apps/opencs/model/tools/magiceffectcheck.cpp | 93 +++++++------------- apps/opencs/model/tools/magiceffectcheck.hpp | 11 +-- 2 files changed, 36 insertions(+), 68 deletions(-) diff --git a/apps/opencs/model/tools/magiceffectcheck.cpp b/apps/opencs/model/tools/magiceffectcheck.cpp index 531bd9e1d..448e4d28c 100644 --- a/apps/opencs/model/tools/magiceffectcheck.cpp +++ b/apps/opencs/model/tools/magiceffectcheck.cpp @@ -9,7 +9,7 @@ namespace { - void addMessageIfNotEmpty(CSMDoc::Messages &messages, const CSMWorld::UniversalId &id, const std::string& text) + void addMessage(CSMDoc::Messages &messages, const CSMWorld::UniversalId &id, const std::string& text) { if (!text.empty()) { @@ -18,42 +18,34 @@ namespace } } -bool CSMTools::MagicEffectCheckStage::isTextureExists(const std::string &texture, bool isIcon) const +std::string CSMTools::MagicEffectCheckStage::checkTexture(const std::string &texture, bool isIcon) const { + if (texture.empty()) return (isIcon ? "Icon is not specified" : std::string()); + const CSMWorld::Resources &textures = isIcon ? mIcons : mTextures; - bool exists = false; + if (textures.searchId(texture) != -1) return std::string(); - if (textures.searchId(texture) != -1) - { - exists = true; - } - else - { - std::string ddsTexture = texture; - if (Misc::ResourceHelpers::changeExtensionToDds(ddsTexture) && textures.searchId(ddsTexture) != -1) - { - exists = true; - } - } + std::string ddsTexture = texture; + if (Misc::ResourceHelpers::changeExtensionToDds(ddsTexture) && textures.searchId(ddsTexture) != -1) return std::string(); - return exists; + return (isIcon ? "Icon '" : "Particle '") + texture + "' does not exist"; } -std::string CSMTools::MagicEffectCheckStage::checkReferenceable(const std::string &id, +std::string CSMTools::MagicEffectCheckStage::checkObject(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); + CSMWorld::RefIdData::LocalIndex index = mObjects.getDataSet().searchId(id); if (index.first == -1) { - error = "No such " + column + " '" + id + "'"; + error = column + " '" + id + "' " + "does not exist"; } else if (index.second != type.getType()) { - error = column + " is not of type " + type.getTypeName(); + error = column + " '" + id + "' " + "does not have " + type.getTypeName() + " type"; } } return error; @@ -64,19 +56,19 @@ std::string CSMTools::MagicEffectCheckStage::checkSound(const std::string &id, c std::string error; if (!id.empty() && mSounds.searchId(id) == -1) { - error = "No such " + column + " '" + id + "'"; + error = column + " '" + id + "' " + "does not exist"; } return error; } CSMTools::MagicEffectCheckStage::MagicEffectCheckStage(const CSMWorld::IdCollection &effects, const CSMWorld::IdCollection &sounds, - const CSMWorld::RefIdCollection &referenceables, + const CSMWorld::RefIdCollection &objects, const CSMWorld::Resources &icons, const CSMWorld::Resources &textures) : mMagicEffects(effects), mSounds(sounds), - mReferenceables(referenceables), + mObjects(objects), mIcons(icons), mTextures(textures) { @@ -100,46 +92,25 @@ void CSMTools::MagicEffectCheckStage::perform(int stage, CSMDoc::Messages &messa ESM::MagicEffect effect = record.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() && !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")); + addMessage(messages, id, "Description is missing"); } + + if (effect.mData.mBaseCost < 0.0f) + { + addMessage(messages, id, "Base cost is negative"); + } + + 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")); } diff --git a/apps/opencs/model/tools/magiceffectcheck.hpp b/apps/opencs/model/tools/magiceffectcheck.hpp index 28a406283..3e45495c1 100644 --- a/apps/opencs/model/tools/magiceffectcheck.hpp +++ b/apps/opencs/model/tools/magiceffectcheck.hpp @@ -21,23 +21,20 @@ namespace CSMTools { const CSMWorld::IdCollection &mMagicEffects; const CSMWorld::IdCollection &mSounds; - const CSMWorld::RefIdCollection &mReferenceables; + const CSMWorld::RefIdCollection &mObjects; const CSMWorld::Resources &mIcons; const CSMWorld::Resources &mTextures; bool mIgnoreBaseRecords; 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 checkTexture(const std::string &texture, bool isIcon) const; + std::string checkObject(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 &effects, const CSMWorld::IdCollection &sounds, - const CSMWorld::RefIdCollection &referenceables, + const CSMWorld::RefIdCollection &objects, const CSMWorld::Resources &icons, const CSMWorld::Resources &textures);