From 11496b8075afeee21c93d0837f71ccec47c6d08f Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 6 Jan 2016 12:58:36 +0100 Subject: [PATCH] Read fallback settings in OpenCS --- apps/opencs/editor.cpp | 8 ++++++++ apps/opencs/model/doc/document.cpp | 3 ++- apps/opencs/model/doc/document.hpp | 8 +++++++- apps/opencs/model/doc/documentmanager.cpp | 7 ++++++- apps/opencs/model/doc/documentmanager.hpp | 4 ++++ components/fallback/fallback.hpp | 4 +++- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 92f1082b7..54e323956 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include "model/doc/document.hpp" @@ -17,6 +19,8 @@ #include #endif +using namespace Fallback; + CS::Editor::Editor () : mSettingsState (mCfgMgr), mDocumentManager (mCfgMgr), mViewManager (mDocumentManager), mPid(""), @@ -100,6 +104,8 @@ std::pair > CS::Editor::readConfi ("resources", boost::program_options::value()->default_value("resources")) ("fallback-archive", boost::program_options::value >()-> default_value(std::vector(), "fallback-archive")->multitoken()) + ("fallback", boost::program_options::value()->default_value(FallbackMap(), "") + ->multitoken()->composing(), "fallback values") ("script-blacklist", boost::program_options::value >()->default_value(std::vector(), "") ->multitoken(), "exclude specified script from the verifier (if the use of the blacklist is enabled)") ("script-blacklist-use", boost::program_options::value()->implicit_value(true) @@ -114,6 +120,8 @@ std::pair > CS::Editor::readConfi mDocumentManager.setResourceDir (mResources = variables["resources"].as()); + mDocumentManager.setFallbackMap (variables["fallback"].as().mMap); + if (variables["script-blacklist-use"].as()) mDocumentManager.setBlacklistedScripts ( variables["script-blacklist"].as >()); diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 8cafa7ae1..59d66f36c 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -2247,6 +2247,7 @@ void CSMDoc::Document::createBase() CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationManager& configuration, const std::vector< boost::filesystem::path >& files, bool new_, const boost::filesystem::path& savePath, const boost::filesystem::path& resDir, + const Fallback::Map* fallback, ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager, const std::vector& blacklistedScripts) : mVFS(vfs), mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, resourcesManager), @@ -2255,7 +2256,7 @@ CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationM (savePath.filename().string() + ".project")), mSavingOperation (*this, mProjectPath, encoding), mSaving (&mSavingOperation), - mResDir(resDir), + mResDir(resDir), mFallbackMap(fallback), mRunner (mProjectPath), mDirty (false), mIdCompletionManager(mData) { if (mContentFiles.empty()) diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 0e8ae6d45..41640f66d 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -25,9 +25,13 @@ class QAbstractItemModel; -namespace VFS +namespace Fallback { + class Map; +} +namespace VFS +{ class Manager; } @@ -66,6 +70,7 @@ namespace CSMDoc Saving mSavingOperation; OperationHolder mSaving; boost::filesystem::path mResDir; + const Fallback::Map* mFallbackMap; Blacklist mBlacklist; Runner mRunner; bool mDirty; @@ -101,6 +106,7 @@ namespace CSMDoc Document (const VFS::Manager* vfs, const Files::ConfigurationManager& configuration, const std::vector< boost::filesystem::path >& files, bool new_, const boost::filesystem::path& savePath, const boost::filesystem::path& resDir, + const Fallback::Map* fallback, ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager, const std::vector& blacklistedScripts); diff --git a/apps/opencs/model/doc/documentmanager.cpp b/apps/opencs/model/doc/documentmanager.cpp index 407a608ca..cbb255ebb 100644 --- a/apps/opencs/model/doc/documentmanager.cpp +++ b/apps/opencs/model/doc/documentmanager.cpp @@ -64,7 +64,7 @@ CSMDoc::Document *CSMDoc::DocumentManager::makeDocument ( const std::vector< boost::filesystem::path >& files, const boost::filesystem::path& savePath, bool new_) { - return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts); + return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, &mFallbackMap, mEncoding, mResourcesManager, mBlacklistedScripts); } void CSMDoc::DocumentManager::insertDocument (CSMDoc::Document *document) @@ -100,6 +100,11 @@ void CSMDoc::DocumentManager::setResourceDir (const boost::filesystem::path& par mResDir = boost::filesystem::system_complete(parResDir); } +void CSMDoc::DocumentManager::setFallbackMap(const std::map& fallbackMap) +{ + mFallbackMap = Fallback::Map(fallbackMap); +} + void CSMDoc::DocumentManager::setEncoding (ToUTF8::FromType encoding) { mEncoding = encoding; diff --git a/apps/opencs/model/doc/documentmanager.hpp b/apps/opencs/model/doc/documentmanager.hpp index 4f6b2b2c9..ed8e327d7 100644 --- a/apps/opencs/model/doc/documentmanager.hpp +++ b/apps/opencs/model/doc/documentmanager.hpp @@ -10,6 +10,7 @@ #include #include +#include #include "../world/resourcesmanager.hpp" @@ -67,6 +68,8 @@ namespace CSMDoc void setResourceDir (const boost::filesystem::path& parResDir); + void setFallbackMap (const std::map& fallbackMap); + void setEncoding (ToUTF8::FromType encoding); void setBlacklistedScripts (const std::vector& scriptIds); @@ -78,6 +81,7 @@ namespace CSMDoc private: boost::filesystem::path mResDir; + Fallback::Map mFallbackMap; private slots: diff --git a/components/fallback/fallback.hpp b/components/fallback/fallback.hpp index b44483fbc..e64936531 100644 --- a/components/fallback/fallback.hpp +++ b/components/fallback/fallback.hpp @@ -11,9 +11,11 @@ namespace Fallback /// @brief contains settings imported from the Morrowind INI file. class Map { - const std::map mFallbackMap; + std::map mFallbackMap; public: Map(const std::map& fallback); + Map() {} + std::string getFallbackString(const std::string& fall) const; float getFallbackFloat(const std::string& fall) const; int getFallbackInt(const std::string& fall) const;