feat(Globals): Added auto saving on change
This commit is contained in:
parent
9e34eb083b
commit
65d28a2da3
@ -7,10 +7,13 @@ namespace big
|
|||||||
{
|
{
|
||||||
void backend::loop()
|
void backend::loop()
|
||||||
{
|
{
|
||||||
|
g.attempt_save();
|
||||||
|
|
||||||
QUEUE_JOB_BEGIN_CLAUSE()
|
QUEUE_JOB_BEGIN_CLAUSE()
|
||||||
{
|
{
|
||||||
looped::self_godmode();
|
looped::self_godmode();
|
||||||
}QUEUE_JOB_END_CLAUSE
|
}QUEUE_JOB_END_CLAUSE
|
||||||
|
|
||||||
QUEUE_JOB_BEGIN_CLAUSE()
|
QUEUE_JOB_BEGIN_CLAUSE()
|
||||||
{
|
{
|
||||||
looped::self_noclip();
|
looped::self_noclip();
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
using namespace big;
|
using namespace big;
|
||||||
struct globals {
|
struct globals {
|
||||||
|
nlohmann::json default_options;
|
||||||
|
nlohmann::json options;
|
||||||
|
|
||||||
struct self {
|
struct self {
|
||||||
bool godmode = false;
|
bool godmode = false;
|
||||||
bool noclip = false;
|
bool noclip = false;
|
||||||
@ -59,8 +62,21 @@ struct globals {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void attempt_save()
|
||||||
|
{
|
||||||
|
nlohmann::json& j = this->to_json();
|
||||||
|
if (j != this->options)
|
||||||
|
{
|
||||||
|
this->save();
|
||||||
|
|
||||||
|
this->options = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool load()
|
bool load()
|
||||||
{
|
{
|
||||||
|
this->default_options = this->to_json();
|
||||||
|
|
||||||
std::string settings_file = std::getenv("appdata");
|
std::string settings_file = std::getenv("appdata");
|
||||||
settings_file += "\\BigBaseV2\\settings.json";
|
settings_file += "\\BigBaseV2\\settings.json";
|
||||||
|
|
||||||
@ -73,31 +89,25 @@ struct globals {
|
|||||||
file.open(settings_file);
|
file.open(settings_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json j;
|
file >> this->options;
|
||||||
file >> j;
|
|
||||||
|
|
||||||
nlohmann::json default_j = this->to_json();
|
|
||||||
|
|
||||||
bool should_save = false;
|
bool should_save = false;
|
||||||
for (auto& e : default_j.items())
|
for (auto& e : this->default_options.items())
|
||||||
{
|
{
|
||||||
if (j.count(e.key()) == 0)
|
if (this->options.count(e.key()) == 0)
|
||||||
{
|
{
|
||||||
should_save = true;
|
should_save = true;
|
||||||
j[e.key()] = e.value();
|
this->options[e.key()] = e.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->from_json(this->options);
|
||||||
|
|
||||||
if (should_save)
|
if (should_save)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "Updating settings.";
|
LOG(INFO) << "Updating settings.";
|
||||||
|
|
||||||
default_j.merge_patch(j);
|
|
||||||
j = default_j;
|
|
||||||
|
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
this->from_json(j);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user