mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Compile fix for #847
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CConfigHandler.h"
|
#include "CConfigHandler.h"
|
||||||
|
|
||||||
#include "../lib/GameConstants.h"
|
#include "../lib/GameConstants.h"
|
||||||
#include "../lib/VCMIDirs.h"
|
#include "../lib/VCMIDirs.h"
|
||||||
|
|
||||||
using namespace config;
|
using namespace config;
|
||||||
@ -15,17 +15,17 @@ using namespace config;
|
|||||||
* Full text of license available in license.txt file, in main folder
|
* Full text of license available in license.txt file, in main folder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
SettingsStorage settings;
|
SettingsStorage settings;
|
||||||
CConfigHandler conf;
|
CConfigHandler conf;
|
||||||
|
|
||||||
template<typename Accessor>
|
template<typename Accessor>
|
||||||
SettingsStorage::NodeAccessor<Accessor>::NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path):
|
SettingsStorage::NodeAccessor<Accessor>::NodeAccessor(SettingsStorage & _parent, std::vector<std::string> _path):
|
||||||
parent(_parent),
|
parent(_parent),
|
||||||
path(_path)
|
path(_path)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Accessor>
|
template<typename Accessor>
|
||||||
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator [](std::string nextNode) const
|
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);
|
newPath.push_back(nextNode);
|
||||||
return NodeAccessor(parent, newPath);
|
return NodeAccessor(parent, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Accessor>
|
template<typename Accessor>
|
||||||
SettingsStorage::NodeAccessor<Accessor>::operator Accessor() const
|
SettingsStorage::NodeAccessor<Accessor>::operator Accessor() const
|
||||||
{
|
{
|
||||||
return Accessor(parent, path);
|
return Accessor(parent, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Accessor>
|
template<typename Accessor>
|
||||||
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator () (std::vector<std::string> _path)
|
SettingsStorage::NodeAccessor<Accessor> SettingsStorage::NodeAccessor<Accessor>::operator () (std::vector<std::string> _path)
|
||||||
{
|
{
|
||||||
std::vector<std::string> newPath = path;
|
std::vector<std::string> newPath = path;
|
||||||
newPath.insert( newPath.end(), _path.begin(), _path.end());
|
newPath.insert( newPath.end(), _path.begin(), _path.end());
|
||||||
return NodeAccessor(parent, newPath);
|
return NodeAccessor(parent, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsStorage::SettingsStorage():
|
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>() ))
|
listen(NodeAccessor<SettingsListener>(*this, std::vector<std::string>() ))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsStorage::init()
|
void SettingsStorage::init()
|
||||||
{
|
{
|
||||||
JsonNode(GVCMIDirs.UserPath + "/config/settings.json").swap(config);
|
JsonNode(GVCMIDirs.UserPath + "/config/settings.json").swap(config);
|
||||||
JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
||||||
config.validate(schema);
|
config.validate(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath)
|
void SettingsStorage::invalidateNode(const std::vector<std::string> &changedPath)
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(SettingsListener * listener, listeners)
|
BOOST_FOREACH(SettingsListener * listener, listeners)
|
||||||
listener->nodeInvalidated(changedPath);
|
listener->nodeInvalidated(changedPath);
|
||||||
|
|
||||||
JsonNode savedConf = config;
|
JsonNode savedConf = config;
|
||||||
JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
JsonNode schema(GameConstants::DATA_DIR + "/config/defaultSettings.json");
|
||||||
|
|
||||||
savedConf.Struct().erase("session");
|
savedConf.Struct().erase("session");
|
||||||
savedConf.minimize(schema);
|
savedConf.minimize(schema);
|
||||||
std::ofstream file((GVCMIDirs.UserPath + "/config/settings.json").c_str(), std::ofstream::trunc | std::ofstream::out);
|
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)
|
void SettingsListener::nodeInvalidated(const std::vector<std::string> changedPath)
|
||||||
{
|
{
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t min = std::min(path.size(), changedPath.size());
|
size_t min = std::min(path.size(), changedPath.size());
|
||||||
size_t mismatch = std::mismatch(path.begin(), path.begin()+min, changedPath.begin()).first - path.begin();
|
size_t mismatch = std::mismatch(path.begin(), path.begin()+min, changedPath.begin()).first - path.begin();
|
||||||
|
|
||||||
if (min == mismatch)
|
if (min == mismatch)
|
||||||
callback(parent.getNode(path));
|
callback(parent.getNode(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsListener::operator() (boost::function<void(const JsonNode&)> _callback)
|
void SettingsListener::operator() (boost::function<void(const JsonNode&)> _callback)
|
||||||
{
|
{
|
||||||
callback = _callback;
|
callback = _callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::Settings(SettingsStorage &_parent, const std::vector<std::string> &_path):
|
Settings::Settings(SettingsStorage &_parent, const std::vector<std::string> &_path):
|
||||||
@ -156,9 +156,9 @@ JsonNode& Settings::operator [](std::string value)
|
|||||||
{
|
{
|
||||||
return node[value];
|
return node[value];
|
||||||
}
|
}
|
||||||
|
|
||||||
template struct SettingsStorage::NodeAccessor<SettingsListener>;
|
template struct SettingsStorage::NodeAccessor<SettingsListener>;
|
||||||
template struct SettingsStorage::NodeAccessor<Settings>;
|
template struct SettingsStorage::NodeAccessor<Settings>;
|
||||||
|
|
||||||
static void setButton(ButtonInfo &button, const JsonNode &g)
|
static void setButton(ButtonInfo &button, const JsonNode &g)
|
||||||
{
|
{
|
||||||
@ -273,7 +273,7 @@ void config::CConfigHandler::init()
|
|||||||
const JsonNode& gameRes = settings["video"]["gameRes"];
|
const JsonNode& gameRes = settings["video"]["gameRes"];
|
||||||
|
|
||||||
//fixing screenx / screeny
|
//fixing screenx / screeny
|
||||||
if (screenRes["width"].Float() != gameRes["width"].Float()
|
if (screenRes["width"].Float() != gameRes["width"].Float()
|
||||||
|| screenRes["height"].Float() != gameRes["height"].Float())
|
|| screenRes["height"].Float() != gameRes["height"].Float())
|
||||||
{
|
{
|
||||||
Settings screen = settings.write["video"]["screenRes"];
|
Settings screen = settings.write["video"]["screenRes"];
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
* Full text of license available in license.txt file, in main folder
|
* Full text of license available in license.txt file, in main folder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Settings;
|
class Settings;
|
||||||
class SettingsListener;
|
class SettingsListener;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
JsonWriter(std::ostream &output, const JsonNode &node);
|
JsonWriter(std::ostream &output, const JsonNode &node);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream & operator<<(std::ostream &out, const JsonNode &node);
|
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const JsonNode &node);
|
||||||
|
|
||||||
//Tiny string class that uses const char* as data for speed, members are private
|
//Tiny string class that uses const char* as data for speed, members are private
|
||||||
//for ease of debugging and some compatibility with std::string
|
//for ease of debugging and some compatibility with std::string
|
||||||
@ -184,3 +184,5 @@ public:
|
|||||||
// validate with external schema
|
// validate with external schema
|
||||||
JsonValidator(JsonNode &root, const JsonNode &schema, bool minimize=false);
|
JsonValidator(JsonNode &root, const JsonNode &schema, bool minimize=false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -550,7 +550,6 @@ DLL_LINKAGE const CArtifactInstance *ArtifactLocation::getArt() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DLL_LINKAGE CArtifactInstance *ArtifactLocation::getArt()
|
DLL_LINKAGE CArtifactInstance *ArtifactLocation::getArt()
|
||||||
|
Reference in New Issue
Block a user