mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 15:45:37 +00:00
Add a default way to store arrays in the settings.cfg
This commit is contained in:
parent
26bd907b0b
commit
8ff64ca176
@ -23,7 +23,7 @@ namespace
|
|||||||
{
|
{
|
||||||
auto* processor = MWBase::Environment::get().getWorld()->getPostProcessor();
|
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)
|
for (size_t i = 1; i < processor->getTechniques().size(); ++i)
|
||||||
{
|
{
|
||||||
@ -32,13 +32,10 @@ namespace
|
|||||||
if (!technique || technique->getDynamic())
|
if (!technique || technique->getDynamic())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
chain << technique->getName();
|
chain.push_back(technique->getName());
|
||||||
|
|
||||||
if (i < processor-> getTechniques().size() - 1)
|
|
||||||
chain << ",";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::Manager::setString("chain", "Post Processing", chain.str());
|
Settings::Manager::setStringArray("chain", "Post Processing", chain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -830,8 +830,7 @@ namespace MWRender
|
|||||||
|
|
||||||
mTechniques.clear();
|
mTechniques.clear();
|
||||||
|
|
||||||
std::vector<std::string> techniqueStrings;
|
std::vector<std::string> techniqueStrings = Settings::Manager::getStringArray("chain", "Post Processing");
|
||||||
Misc::StringUtils::split(Settings::Manager::getString("chain", "Post Processing"), techniqueStrings, ",");
|
|
||||||
|
|
||||||
const std::string mainIdentifier = "main";
|
const std::string mainIdentifier = "main";
|
||||||
|
|
||||||
@ -844,8 +843,6 @@ namespace MWRender
|
|||||||
|
|
||||||
for (auto& techniqueName : techniqueStrings)
|
for (auto& techniqueName : techniqueStrings)
|
||||||
{
|
{
|
||||||
Misc::StringUtils::trim(techniqueName);
|
|
||||||
|
|
||||||
if (techniqueName.empty() || Misc::StringUtils::ciEqual(techniqueName, mainIdentifier))
|
if (techniqueName.empty() || Misc::StringUtils::ciEqual(techniqueName, mainIdentifier))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -88,6 +88,22 @@ std::string Manager::getString(std::string_view setting, std::string_view catego
|
|||||||
throw std::runtime_error(error);
|
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)
|
float Manager::getFloat(std::string_view setting, std::string_view category)
|
||||||
{
|
{
|
||||||
const std::string& value = getString(setting, 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));
|
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)
|
void Manager::setInt(std::string_view setting, std::string_view category, const int value)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <osg/Vec2f>
|
#include <osg/Vec2f>
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
@ -63,6 +64,7 @@ namespace Settings
|
|||||||
static float getFloat(std::string_view setting, std::string_view category);
|
static float getFloat(std::string_view setting, std::string_view category);
|
||||||
static double getDouble(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::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 bool getBool(std::string_view setting, std::string_view category);
|
||||||
static osg::Vec2f getVector2(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);
|
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 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 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 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 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 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);
|
static void setVector3(std::string_view setting, std::string_view category, osg::Vec3f value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user