forked from mirror/openmw-tes3mp
parse fallback with boost program option custom validators
This commit is contained in:
parent
d87dffa948
commit
73705dadf6
5 changed files with 39 additions and 51 deletions
|
@ -341,7 +341,7 @@ void OMW::Engine::go()
|
||||||
|
|
||||||
// Create the world
|
// Create the world
|
||||||
mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster,
|
mEnvironment.mWorld = new MWWorld::World (*mOgre, mFileCollections, mMaster,
|
||||||
mResDir, mNewGame, mEnvironment, mEncoding, mFallbackPairs);
|
mResDir, mNewGame, mEnvironment, mEncoding, mFallbackMap);
|
||||||
|
|
||||||
// Create window manager - this manages all the MW-specific GUI windows
|
// Create window manager - this manages all the MW-specific GUI windows
|
||||||
MWScript::registerExtensions (mExtensions);
|
MWScript::registerExtensions (mExtensions);
|
||||||
|
@ -509,7 +509,7 @@ void OMW::Engine::setEncoding(const std::string& encoding)
|
||||||
mEncoding = encoding;
|
mEncoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OMW::Engine::setFallbackValues(std::vector<std::string> pairs)
|
void OMW::Engine::setFallbackValues(std::map<std::string,std::string> fallbackMap)
|
||||||
{
|
{
|
||||||
mFallbackPairs = pairs;
|
mFallbackMap = fallbackMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace OMW
|
||||||
bool mReportFocus;
|
bool mReportFocus;
|
||||||
float mFocusTDiff;
|
float mFocusTDiff;
|
||||||
std::string mFocusName;
|
std::string mFocusName;
|
||||||
std::vector<std::string> mFallbackPairs;
|
std::map<std::string,std::string> mFallbackMap;
|
||||||
|
|
||||||
MWWorld::Environment mEnvironment;
|
MWWorld::Environment mEnvironment;
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
|
@ -164,7 +164,7 @@ namespace OMW
|
||||||
|
|
||||||
void setAnimationVerbose(bool animverbose);
|
void setAnimationVerbose(bool animverbose);
|
||||||
|
|
||||||
void setFallbackValues(std::vector<std::string> pairs);
|
void setFallbackValues(std::map<std::string,std::string> map);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Files::ConfigurationManager& mCfgMgr;
|
Files::ConfigurationManager& mCfgMgr;
|
||||||
|
|
|
@ -56,32 +56,34 @@ using namespace std;
|
||||||
|
|
||||||
struct FallbackMap {
|
struct FallbackMap {
|
||||||
std::map<std::string,std::string> mMap;
|
std::map<std::string,std::string> mMap;
|
||||||
|
|
||||||
static void
|
|
||||||
validate(boost::any &v, std::vector<std::string> const &tokens)
|
|
||||||
{
|
|
||||||
if(v.empty())
|
|
||||||
{
|
|
||||||
v = boost::any(FallbackMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
|
||||||
|
|
||||||
std::map<std::string,std::string>::iterator mapIt;
|
|
||||||
for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); it++)
|
|
||||||
{
|
|
||||||
int sep = it->find(",");
|
|
||||||
std::string key(it->substr(0,sep-1));
|
|
||||||
std::string value(it->substr(sep));
|
|
||||||
|
|
||||||
if((mapIt = map->mMap.find(key)) == map->mMap.end())
|
|
||||||
{
|
|
||||||
map->mMap.insert(std::make_pair<std::string,std::string>(key,value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
|
||||||
|
{
|
||||||
|
if(v.empty())
|
||||||
|
{
|
||||||
|
v = boost::any(FallbackMap());
|
||||||
|
}
|
||||||
|
|
||||||
|
FallbackMap *map = boost::any_cast<FallbackMap>(&v);
|
||||||
|
|
||||||
|
std::map<std::string,std::string>::iterator mapIt;
|
||||||
|
for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); it++)
|
||||||
|
{
|
||||||
|
int sep = it->find(",");
|
||||||
|
if(sep < 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string key(it->substr(0,sep));
|
||||||
|
std::string value(it->substr(sep+1));
|
||||||
|
|
||||||
|
if((mapIt = map->mMap.find(key)) == map->mMap.end())
|
||||||
|
{
|
||||||
|
map->mMap.insert(std::make_pair<std::string,std::string>(key,value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Parses application command line and calls \ref Cfg::ConfigurationManager
|
* \brief Parses application command line and calls \ref Cfg::ConfigurationManager
|
||||||
|
@ -265,7 +267,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
engine.setCompileAll(variables["script-all"].as<bool>());
|
engine.setCompileAll(variables["script-all"].as<bool>());
|
||||||
engine.setReportFocus(variables["report-focus"].as<bool>());
|
engine.setReportFocus(variables["report-focus"].as<bool>());
|
||||||
engine.setAnimationVerbose(variables["anim-verbose"].as<bool>());
|
engine.setAnimationVerbose(variables["anim-verbose"].as<bool>());
|
||||||
//engine.setFallbackValues(variables["fallback"].as<std::vector<std::string> >());
|
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,24 +152,9 @@ namespace MWWorld
|
||||||
mRendering->skyDisable();
|
mRendering->skyDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::setFallbackValues(std::vector<std::string> pairs)
|
void World::setFallbackValues(std::map<std::string,std::string> fallbackMap)
|
||||||
{
|
{
|
||||||
for(std::vector<std::string>::iterator it = pairs.begin(); it != pairs.end(); it++)
|
mFallback = fallbackMap;
|
||||||
{
|
|
||||||
std::string kv = *it;
|
|
||||||
int seperator = kv.find("=");
|
|
||||||
if(seperator < 1 || seperator == (kv.length()-1))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string key = it->substr(0,seperator);
|
|
||||||
std::string value = it->substr(seperator+1);
|
|
||||||
if(mFallback.find(key) == mFallback.end()) {
|
|
||||||
std::cout << "insert " << key << ":" << value << std::endl;
|
|
||||||
mFallback.insert(std::make_pair<std::string,std::string>(key,value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string World::getFallback(std::string key)
|
std::string World::getFallback(std::string key)
|
||||||
|
@ -185,7 +170,7 @@ namespace MWWorld
|
||||||
World::World (OEngine::Render::OgreRenderer& renderer,
|
World::World (OEngine::Render::OgreRenderer& renderer,
|
||||||
const Files::Collections& fileCollections,
|
const Files::Collections& fileCollections,
|
||||||
const std::string& master, const boost::filesystem::path& resDir,
|
const std::string& master, const boost::filesystem::path& resDir,
|
||||||
bool newGame, Environment& environment, const std::string& encoding, std::vector<std::string> fallbackPairs)
|
bool newGame, Environment& environment, const std::string& encoding, std::map<std::string,std::string> fallbackMap)
|
||||||
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
||||||
mSky (true), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this),
|
mSky (true), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this),
|
||||||
mNumFacing(0)
|
mNumFacing(0)
|
||||||
|
@ -221,7 +206,8 @@ namespace MWWorld
|
||||||
|
|
||||||
mWorldScene = new Scene(environment, this, *mRendering, mPhysics);
|
mWorldScene = new Scene(environment, this, *mRendering, mPhysics);
|
||||||
|
|
||||||
setFallbackValues(fallbackPairs);
|
setFallbackValues(fallbackMap);
|
||||||
|
std::cout << "Weather_Sunrise_Time=" << getFallback("Weather_Sunrise_Time") << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ namespace MWWorld
|
||||||
World (OEngine::Render::OgreRenderer& renderer,
|
World (OEngine::Render::OgreRenderer& renderer,
|
||||||
const Files::Collections& fileCollections,
|
const Files::Collections& fileCollections,
|
||||||
const std::string& master, const boost::filesystem::path& resDir, bool newGame,
|
const std::string& master, const boost::filesystem::path& resDir, bool newGame,
|
||||||
Environment& environment, const std::string& encoding, std::vector<std::string> fallbackPairs);
|
Environment& environment, const std::string& encoding, std::map<std::string,std::string> fallbackMap);
|
||||||
|
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ namespace MWWorld
|
||||||
|
|
||||||
void adjustSky();
|
void adjustSky();
|
||||||
|
|
||||||
void setFallbackValues(std::vector<std::string> pairs);
|
void setFallbackValues(std::map<std::string,std::string> fallbackMap);
|
||||||
|
|
||||||
std::string getFallback(std::string key);
|
std::string getFallback(std::string key);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue