mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:45:33 +00:00
Add a default way to store arrays in the settings.cfg
This commit is contained in:
parent
26bd907b0b
commit
8ff64ca176
4 changed files with 41 additions and 10 deletions
|
@ -23,7 +23,7 @@ namespace
|
|||
{
|
||||
auto* processor = MWBase::Environment::get().getWorld()->getPostProcessor();
|
||||
|
||||
std::ostringstream chain;
|
||||
std::vector<std::string> chain;
|
||||
|
||||
for (size_t i = 1; i < processor->getTechniques().size(); ++i)
|
||||
{
|
||||
|
@ -32,13 +32,10 @@ namespace
|
|||
if (!technique || technique->getDynamic())
|
||||
continue;
|
||||
|
||||
chain << technique->getName();
|
||||
|
||||
if (i < processor-> getTechniques().size() - 1)
|
||||
chain << ",";
|
||||
chain.push_back(technique->getName());
|
||||
}
|
||||
|
||||
Settings::Manager::setString("chain", "Post Processing", chain.str());
|
||||
Settings::Manager::setStringArray("chain", "Post Processing", chain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -830,8 +830,7 @@ namespace MWRender
|
|||
|
||||
mTechniques.clear();
|
||||
|
||||
std::vector<std::string> techniqueStrings;
|
||||
Misc::StringUtils::split(Settings::Manager::getString("chain", "Post Processing"), techniqueStrings, ",");
|
||||
std::vector<std::string> techniqueStrings = Settings::Manager::getStringArray("chain", "Post Processing");
|
||||
|
||||
const std::string mainIdentifier = "main";
|
||||
|
||||
|
@ -844,8 +843,6 @@ namespace MWRender
|
|||
|
||||
for (auto& techniqueName : techniqueStrings)
|
||||
{
|
||||
Misc::StringUtils::trim(techniqueName);
|
||||
|
||||
if (techniqueName.empty() || Misc::StringUtils::ciEqual(techniqueName, mainIdentifier))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -88,6 +88,22 @@ std::string Manager::getString(std::string_view setting, std::string_view catego
|
|||
throw std::runtime_error(error);
|
||||
}
|
||||
|
||||
std::vector<std::string> Manager::getStringArray(std::string_view setting, std::string_view category)
|
||||
{
|
||||
// TODO: it is unclear how to handle empty value -
|
||||
// there is no difference between empty serialized array
|
||||
// and a serialized array which has one empty value
|
||||
std::vector<std::string> values;
|
||||
const std::string& value = getString(setting, category);
|
||||
if (value.empty())
|
||||
return values;
|
||||
|
||||
Misc::StringUtils::split(value, values, ",");
|
||||
for (auto& item : values)
|
||||
Misc::StringUtils::trim(item);
|
||||
return values;
|
||||
}
|
||||
|
||||
float Manager::getFloat(std::string_view setting, std::string_view category)
|
||||
{
|
||||
const std::string& value = getString(setting, category);
|
||||
|
@ -168,6 +184,24 @@ void Manager::setString(std::string_view setting, std::string_view category, con
|
|||
mChangedSettings.insert(std::move(key));
|
||||
}
|
||||
|
||||
void Manager::setStringArray(std::string_view setting, std::string_view category, const std::vector<std::string> &value)
|
||||
{
|
||||
std::stringstream stream;
|
||||
|
||||
// TODO: escape delimeters, new line characters, etc.
|
||||
for (size_t i = 0; i < value.size(); ++i)
|
||||
{
|
||||
std::string item = value[i];
|
||||
Misc::StringUtils::trim(item);
|
||||
stream << item;
|
||||
|
||||
if (i < value.size() - 1)
|
||||
stream << ",";
|
||||
}
|
||||
|
||||
setString(setting, category, stream.str());
|
||||
}
|
||||
|
||||
void Manager::setInt(std::string_view setting, std::string_view category, const int value)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <osg/Vec2f>
|
||||
#include <osg/Vec3f>
|
||||
|
@ -63,6 +64,7 @@ namespace Settings
|
|||
static float getFloat(std::string_view setting, std::string_view category);
|
||||
static double getDouble(std::string_view setting, std::string_view category);
|
||||
static std::string getString(std::string_view setting, std::string_view category);
|
||||
static std::vector<std::string> getStringArray(std::string_view setting, std::string_view category);
|
||||
static bool getBool(std::string_view setting, std::string_view category);
|
||||
static osg::Vec2f getVector2(std::string_view setting, std::string_view category);
|
||||
static osg::Vec3f getVector3(std::string_view setting, std::string_view category);
|
||||
|
@ -72,6 +74,7 @@ namespace Settings
|
|||
static void setFloat(std::string_view setting, std::string_view category, float value);
|
||||
static void setDouble(std::string_view setting, std::string_view category, double value);
|
||||
static void setString(std::string_view setting, std::string_view category, const std::string& value);
|
||||
static void setStringArray(std::string_view setting, std::string_view category, const std::vector<std::string> &value);
|
||||
static void setBool(std::string_view setting, std::string_view category, bool value);
|
||||
static void setVector2(std::string_view setting, std::string_view category, osg::Vec2f value);
|
||||
static void setVector3(std::string_view setting, std::string_view category, osg::Vec3f value);
|
||||
|
|
Loading…
Reference in a new issue