|
@@ -1,7 +1,7 @@
|
|
|
-#include "StdInc.h"
|
|
|
+#include "StdInc.h"
|
|
|
#include "CConfigHandler.h"
|
|
|
|
|
|
-#include "../lib/GameConstants.h"
|
|
|
+#include "../lib/GameConstants.h"
|
|
|
#include "../lib/VCMIDirs.h"
|
|
|
|
|
|
using namespace config;
|
|
@@ -15,17 +15,17 @@ using namespace config;
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
*
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
SettingsStorage settings;
|
|
|
CConfigHandler conf;
|
|
|
-
|
|
|
+
|
|
|
template<typename Accessor>
|
|
|
SettingsStorage::NodeAccessor<Accessor>::NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path):
|
|
|
parent(_parent),
|
|
|
path(_path)
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
template<typename Accessor>
|
|
|
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator [](std::string nextNode) const
|
|
|
{
|
|
@@ -33,42 +33,42 @@ SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>:
|
|
|
newPath.push_back(nextNode);
|
|
|
return NodeAccessor(parent, newPath);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
template<typename Accessor>
|
|
|
SettingsStorage::NodeAccessor<Accessor>::operator Accessor() const
|
|
|
{
|
|
|
return Accessor(parent, path);
|
|
|
}
|
|
|
-
|
|
|
-template<typename Accessor>
|
|
|
-SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator () (std::vector<std::string> _path)
|
|
|
-{
|
|
|
- std::vector<std::string> newPath = path;
|
|
|
- newPath.insert( newPath.end(), _path.begin(), _path.end());
|
|
|
- return NodeAccessor(parent, newPath);
|
|
|
-}
|
|
|
+
|
|
|
+template<typename Accessor>
|
|
|
+SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator () (std::vector<std::string> _path)
|
|
|
+{
|
|
|
+ std::vector<std::string> newPath = path;
|
|
|
+ newPath.insert( newPath.end(), _path.begin(), _path.end());
|
|
|
+ return NodeAccessor(parent, newPath);
|
|
|
+}
|
|
|
|
|
|
SettingsStorage::SettingsStorage():
|
|
|
- write(NodeAccessor<Settings>(*this, std::vector<std::string>() )),
|
|
|
+ write(NodeAccessor<Settings>(*this, std::vector<std::string>() )),
|
|
|
listen(NodeAccessor<SettingsListener>(*this, std::vector<std::string>() ))
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
-void SettingsStorage::init()
|
|
|
-{
|
|
|
- JsonNode(GVCMIDirs.UserPath + "/config/settings.json").swap(config);
|
|
|
- JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
|
|
- config.validate(schema);
|
|
|
-}
|
|
|
+
|
|
|
+void SettingsStorage::init()
|
|
|
+{
|
|
|
+ JsonNode(GVCMIDirs.UserPath + "/config/settings.json").swap(config);
|
|
|
+ JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
|
|
+ config.validate(schema);
|
|
|
+}
|
|
|
|
|
|
void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath)
|
|
|
{
|
|
|
BOOST_FOREACH(SettingsListener * listener, listeners)
|
|
|
- listener->nodeInvalidated(changedPath);
|
|
|
+ listener->nodeInvalidated(changedPath);
|
|
|
|
|
|
JsonNode savedConf = config;
|
|
|
JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
|
|
-
|
|
|
+
|
|
|
savedConf.Struct().erase("session");
|
|
|
savedConf.minimize(schema);
|
|
|
std::ofstream file((GVCMIDirs.UserPath + "/config/settings.json").c_str(), std::ofstream::trunc | std::ofstream::out);
|
|
@@ -107,20 +107,20 @@ SettingsListener::~SettingsListener()
|
|
|
}
|
|
|
|
|
|
void SettingsListener::nodeInvalidated(const std::vector<std::string> changedPath)
|
|
|
-{
|
|
|
- if (!callback)
|
|
|
- return;
|
|
|
+{
|
|
|
+ if (!callback)
|
|
|
+ return;
|
|
|
|
|
|
size_t min = std::min(path.size(), changedPath.size());
|
|
|
size_t mismatch = std::mismatch(path.begin(), path.begin()+min, changedPath.begin()).first - path.begin();
|
|
|
|
|
|
if (min == mismatch)
|
|
|
callback(parent.getNode(path));
|
|
|
-}
|
|
|
-
|
|
|
-void SettingsListener::operator() (boost::function<void(const JsonNode&)> _callback)
|
|
|
-{
|
|
|
- callback = _callback;
|
|
|
+}
|
|
|
+
|
|
|
+void SettingsListener::operator() (boost::function<void(const JsonNode&)> _callback)
|
|
|
+{
|
|
|
+ callback = _callback;
|
|
|
}
|
|
|
|
|
|
Settings::Settings(SettingsStorage &_parent, const std::vector<std::string> &_path):
|
|
@@ -156,9 +156,9 @@ JsonNode& Settings::operator [](std::string value)
|
|
|
{
|
|
|
return node[value];
|
|
|
}
|
|
|
-
|
|
|
-template struct SettingsStorage::NodeAccessor<SettingsListener>;
|
|
|
-template struct SettingsStorage::NodeAccessor<Settings>;
|
|
|
+
|
|
|
+template struct SettingsStorage::NodeAccessor<SettingsListener>;
|
|
|
+template struct SettingsStorage::NodeAccessor<Settings>;
|
|
|
|
|
|
static void setButton(ButtonInfo &button, const JsonNode &g)
|
|
|
{
|
|
@@ -273,7 +273,7 @@ void config::CConfigHandler::init()
|
|
|
const JsonNode& gameRes = settings["video"]["gameRes"];
|
|
|
|
|
|
//fixing screenx / screeny
|
|
|
- if (screenRes["width"].Float() != gameRes["width"].Float()
|
|
|
+ if (screenRes["width"].Float() != gameRes["width"].Float()
|
|
|
|| screenRes["height"].Float() != gameRes["height"].Float())
|
|
|
{
|
|
|
Settings screen = settings.write["video"]["screenRes"];
|