Skip to content

Commit

Permalink
Modify CVarClearBlock to properly save and reload changes to CVars.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian committed Oct 18, 2024
1 parent 0302eab commit ac85e25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ void Config::Erase(const std::string& key) {
void Config::EraseBlock(const std::string& key) {
nlohmann::json gjson = mFlattenedJson.unflatten();
if (key.find(".") != std::string::npos) {
nlohmann::json& gjson2 = gjson;
nlohmann::json* gjson2 = &gjson;
std::vector<std::string> dots = StringHelper::Split(key, ".");
if (dots.size() > 1) {
size_t curDot = 0;
for (auto& dot : dots) {
if (gjson2.contains(dot)) {
if (curDot == dots.size()) {
gjson2.erase(dot);
if (gjson2->contains(dot)) {
if (curDot == dots.size() - 1) {
gjson2->at(dot).clear();
gjson2->erase(dot);
} else {
gjson2 = gjson2[dot];
gjson2 = &gjson2->at(dot);
curDot++;
}
}
}
Expand All @@ -154,6 +156,7 @@ void Config::EraseBlock(const std::string& key) {
}
}
mFlattenedJson = gjson.flatten();
Save();
}

void Config::Copy(const std::string& fromKey, const std::string& toKey) {
Expand Down Expand Up @@ -296,7 +299,6 @@ void Config::RunVersionUpdates() {
SetUInt("ConfigVersion", versionUpdater->GetVersion());
}
}
Save();
}

ConfigVersionUpdater::ConfigVersionUpdater(uint32_t toVersion) : mVersion(toVersion) {
Expand Down
1 change: 1 addition & 0 deletions src/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Config {
void SetInt(const std::string& key, int32_t value);
void SetUInt(const std::string& key, uint32_t value);
void Erase(const std::string& key);
void EraseChild(nlohmann::json& block);
void EraseBlock(const std::string& key);
void Copy(const std::string& fromKey, const std::string& toKey);
bool Contains(const std::string& key);
Expand Down

0 comments on commit ac85e25

Please sign in to comment.