parse fallback with boost program option custom validators

actorid
Sebastian Wick 13 years ago
parent d87dffa948
commit 73705dadf6

@ -341,7 +341,7 @@ void OMW::Engine::go()
// Create the world
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
MWScript::registerExtensions (mExtensions);
@ -509,7 +509,7 @@ void OMW::Engine::setEncoding(const std::string& 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;
float mFocusTDiff;
std::string mFocusName;
std::vector<std::string> mFallbackPairs;
std::map<std::string,std::string> mFallbackMap;
MWWorld::Environment mEnvironment;
Compiler::Extensions mExtensions;
@ -164,7 +164,7 @@ namespace OMW
void setAnimationVerbose(bool animverbose);
void setFallbackValues(std::vector<std::string> pairs);
void setFallbackValues(std::map<std::string,std::string> map);
private:
Files::ConfigurationManager& mCfgMgr;

@ -56,31 +56,33 @@ using namespace std;
struct FallbackMap {
std::map<std::string,std::string> mMap;
};
static void
validate(boost::any &v, std::vector<std::string> const &tokens)
void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
{
if(v.empty())
{
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++)
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())
{
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));
}
map->mMap.insert(std::make_pair<std::string,std::string>(key,value));
}
}
};
}
}
/**
@ -265,7 +267,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setCompileAll(variables["script-all"].as<bool>());
engine.setReportFocus(variables["report-focus"].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;
}

@ -152,24 +152,9 @@ namespace MWWorld
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++)
{
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));
}
}
mFallback = fallbackMap;
}
std::string World::getFallback(std::string key)
@ -185,7 +170,7 @@ namespace MWWorld
World::World (OEngine::Render::OgreRenderer& renderer,
const Files::Collections& fileCollections,
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),
mSky (true), mEnvironment (environment), mNextDynamicRecord (0), mCells (mStore, mEsm, *this),
mNumFacing(0)
@ -221,7 +206,8 @@ namespace MWWorld
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,
const Files::Collections& fileCollections,
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();
@ -126,7 +126,7 @@ namespace MWWorld
void adjustSky();
void setFallbackValues(std::vector<std::string> pairs);
void setFallbackValues(std::map<std::string,std::string> fallbackMap);
std::string getFallback(std::string key);

Loading…
Cancel
Save