From 1b6d14dcc257369cbdde4cc863aaf37d23333984 Mon Sep 17 00:00:00 2001 From: Pursche Date: Sat, 6 Apr 2024 22:25:01 +0200 Subject: [PATCH] Change files to use spaces --- Source/Base/Base/Util/JsonUtils.cpp | 1874 +++++++++++++-------------- Source/Base/Base/Util/JsonUtils.h | 24 +- 2 files changed, 949 insertions(+), 949 deletions(-) diff --git a/Source/Base/Base/Util/JsonUtils.cpp b/Source/Base/Base/Util/JsonUtils.cpp index ddf3190f..63a44340 100644 --- a/Source/Base/Base/Util/JsonUtils.cpp +++ b/Source/Base/Base/Util/JsonUtils.cpp @@ -6,954 +6,954 @@ namespace glm { - void to_json(nlohmann::json& j, const vec4& P) - { - j = { { "x", P.x }, { "y", P.y }, { "z", P.z }, { "w", P.w } }; - }; - - void from_json(const nlohmann::json& j, vec4& P) - { - P.x = j.at("x").get(); - P.y = j.at("y").get(); - P.z = j.at("z").get(); - P.w = j.at("w").get(); - } - - void to_json(nlohmann::json& j, const ivec4& P) - { - j = { { "x", P.x }, { "y", P.y }, { "z", P.z }, { "w", P.w } }; - }; - - void from_json(const nlohmann::json& j, ivec4& P) - { - P.x = j.at("x").get(); - P.y = j.at("y").get(); - P.z = j.at("z").get(); - P.w = j.at("w").get(); - } + void to_json(nlohmann::json& j, const vec4& P) + { + j = { { "x", P.x }, { "y", P.y }, { "z", P.z }, { "w", P.w } }; + }; + + void from_json(const nlohmann::json& j, vec4& P) + { + P.x = j.at("x").get(); + P.y = j.at("y").get(); + P.z = j.at("z").get(); + P.w = j.at("w").get(); + } + + void to_json(nlohmann::json& j, const ivec4& P) + { + j = { { "x", P.x }, { "y", P.y }, { "z", P.z }, { "w", P.w } }; + }; + + void from_json(const nlohmann::json& j, ivec4& P) + { + P.x = j.at("x").get(); + P.y = j.at("y").get(); + P.z = j.at("z").get(); + P.w = j.at("w").get(); + } } namespace nlohmann { - template <> - struct adl_serializer { - static void to_json(json& j, const ShowFlag& flag) - { - j = flag == ShowFlag::ENABLED ? "ENABLED" : "DISABLED"; - } - - static void from_json(const json& j, ShowFlag& flag) - { - std::string s = j.get(); - if (s == "ENABLED") - { - flag = ShowFlag::ENABLED; - } - else if (s == "DISABLED") - { - flag = ShowFlag::DISABLED; - } - } - }; + template <> + struct adl_serializer { + static void to_json(json& j, const ShowFlag& flag) + { + j = flag == ShowFlag::ENABLED ? "ENABLED" : "DISABLED"; + } + + static void from_json(const json& j, ShowFlag& flag) + { + std::string s = j.get(); + if (s == "ENABLED") + { + flag = ShowFlag::ENABLED; + } + else if (s == "DISABLED") + { + flag = ShowFlag::DISABLED; + } + } + }; } namespace JsonUtils { - bool LoadFromPath(nlohmann::json& json, const std::filesystem::path& path) - { - std::ifstream fileStream(path, std::ifstream::in); - if (!fileStream) - return false; - - fileStream >> json; - fileStream.close(); - - return true; - } - - bool LoadFromPathOrCreate(nlohmann::json& json, const nlohmann::json& fallback, const std::filesystem::path& path) - { - if (std::filesystem::exists(path)) - return LoadFromPath(json, path); - - if (!SaveToPath(fallback, path)) - return false; - - json = fallback; - return true; - } - - bool SaveToPath(const nlohmann::json& json, const std::filesystem::path& path) - { - std::ofstream fileStream(path); - if (!fileStream) - return false; - - fileStream << json.dump(4); - fileStream.close(); - return true; - } - - bool LoadFromPath(nlohmann::ordered_json& json, const std::filesystem::path& path) - { - std::ifstream fileStream(path, std::ifstream::in); - if (!fileStream) - return false; - - fileStream >> json; - fileStream.close(); - - return true; - } - - bool LoadFromPathOrCreate(nlohmann::ordered_json& json, const nlohmann::ordered_json& fallback, const std::filesystem::path& path) - { - if (std::filesystem::exists(path)) - return LoadFromPath(json, path); - - if (!SaveToPath(fallback, path)) - return false; - - json = fallback; - return true; - } - - bool SaveToPath(const nlohmann::ordered_json& json, const std::filesystem::path& path) - { - std::ofstream fileStream(path); - if (!fileStream) - return false; - - fileStream << json.dump(4); - fileStream.close(); - return true; - } - - void VerifyCVarsOrFallback(nlohmann::json& json, const nlohmann::json& fallback) - { - // First implementation of CVARs didn't have a version field - if (json.find("version") == json.end()) - { + bool LoadFromPath(nlohmann::json& json, const std::filesystem::path& path) + { + std::ifstream fileStream(path, std::ifstream::in); + if (!fileStream) + return false; + + fileStream >> json; + fileStream.close(); + + return true; + } + + bool LoadFromPathOrCreate(nlohmann::json& json, const nlohmann::json& fallback, const std::filesystem::path& path) + { + if (std::filesystem::exists(path)) + return LoadFromPath(json, path); + + if (!SaveToPath(fallback, path)) + return false; + + json = fallback; + return true; + } + + bool SaveToPath(const nlohmann::json& json, const std::filesystem::path& path) + { + std::ofstream fileStream(path); + if (!fileStream) + return false; + + fileStream << json.dump(4); + fileStream.close(); + return true; + } + + bool LoadFromPath(nlohmann::ordered_json& json, const std::filesystem::path& path) + { + std::ifstream fileStream(path, std::ifstream::in); + if (!fileStream) + return false; + + fileStream >> json; + fileStream.close(); + + return true; + } + + bool LoadFromPathOrCreate(nlohmann::ordered_json& json, const nlohmann::ordered_json& fallback, const std::filesystem::path& path) + { + if (std::filesystem::exists(path)) + return LoadFromPath(json, path); + + if (!SaveToPath(fallback, path)) + return false; + + json = fallback; + return true; + } + + bool SaveToPath(const nlohmann::ordered_json& json, const std::filesystem::path& path) + { + std::ofstream fileStream(path); + if (!fileStream) + return false; + + fileStream << json.dump(4); + fileStream.close(); + return true; + } + + void VerifyCVarsOrFallback(nlohmann::json& json, const nlohmann::json& fallback) + { + // First implementation of CVARs didn't have a version field + if (json.find("version") == json.end()) + { json = fallback; - return; - } + return; + } - u32 version = json["version"].get(); - if (version != CVAR_VERSION) - { - json = fallback; - } - } - - void SaveCVarsToJson(nlohmann::json& json) - { - CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); - - // Save Integers - { - nlohmann::json& config = json["integer"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + u32 version = json["version"].get(); + if (version != CVAR_VERSION) + { + json = fallback; + } + } + + void SaveCVarsToJson(nlohmann::json& json) + { + CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); + + // Save Integers + { + nlohmann::json& config = json["integer"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Doubles + { + nlohmann::json& config = json["double"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Strings + { + nlohmann::json& config = json["string"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Vec4s + { + nlohmann::json& config = json["vec4"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save IVec4s + { + nlohmann::json& config = json["ivec4"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save ShowFlags + { + nlohmann::json& config = json["showflag"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + } + + void LoadCVarsFromJson(nlohmann::json& json) + { + CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); + + // Load Integers + { + nlohmann::json& config = json["integer"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + i32 initial = value["initial"].get(); + i32 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateIntCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = flags; + } + } + } + + // Load Doubles + { + nlohmann::json& config = json["double"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + f64 initial = value["initial"].get(); + f64 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load Strings + { + nlohmann::json& config = json["string"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + std::string& initial = value["initial"].get_ref(); + std::string& current = value["current"].get_ref(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateStringCVar(category, name.c_str(),description.c_str(), initial.c_str(), current.c_str(), flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load Vec4s + { + nlohmann::json& config = json["vec4"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + vec4 initial = value["initial"].get(); + vec4 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load IVec4s + { + nlohmann::json& config = json["ivec4"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + ivec4 initial = value["initial"].get(); + ivec4 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load ShowFlags + { + nlohmann::json& config = json["showflag"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + ShowFlag initial = value["initial"].get(); + ShowFlag current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateShowFlagCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + } + + void SaveCVarsToJson(nlohmann::ordered_json& json) + { + CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); + + // Save Integers + { + nlohmann::ordered_json& config = json["integer"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Doubles + { + nlohmann::ordered_json& config = json["double"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Strings + { + nlohmann::ordered_json& config = json["string"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save Vec4s + { + nlohmann::ordered_json& config = json["vec4"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save IVec4s + { + nlohmann::ordered_json& config = json["ivec4"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) + continue; + + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; + object["name"] = parameter->name; + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + + // Save ShowFlags + { + nlohmann::ordered_json& config = json["showflag"]; + for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) + { + CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; + CVarParameter* parameter = cvar.parameter; + + if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) continue; - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Doubles - { - nlohmann::json& config = json["double"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Strings - { - nlohmann::json& config = json["string"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Vec4s - { - nlohmann::json& config = json["vec4"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save IVec4s - { - nlohmann::json& config = json["ivec4"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save ShowFlags - { - nlohmann::json& config = json["showflag"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - } - - void LoadCVarsFromJson(nlohmann::json& json) - { - CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); - - // Load Integers - { - nlohmann::json& config = json["integer"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - i32 initial = value["initial"].get(); - i32 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateIntCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = flags; - } - } - } - - // Load Doubles - { - nlohmann::json& config = json["double"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - f64 initial = value["initial"].get(); - f64 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load Strings - { - nlohmann::json& config = json["string"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - std::string& initial = value["initial"].get_ref(); - std::string& current = value["current"].get_ref(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateStringCVar(category, name.c_str(),description.c_str(), initial.c_str(), current.c_str(), flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load Vec4s - { - nlohmann::json& config = json["vec4"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - vec4 initial = value["initial"].get(); - vec4 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load IVec4s - { - nlohmann::json& config = json["ivec4"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - ivec4 initial = value["initial"].get(); - ivec4 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load ShowFlags - { - nlohmann::json& config = json["showflag"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - ShowFlag initial = value["initial"].get(); - ShowFlag current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateShowFlagCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - } - - void SaveCVarsToJson(nlohmann::ordered_json& json) - { - CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); - - // Save Integers - { - nlohmann::ordered_json& config = json["integer"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; + nlohmann::json object = nlohmann::json::object(); + { + object["category"] = parameter->category; object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Doubles - { - nlohmann::ordered_json& config = json["double"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Strings - { - nlohmann::ordered_json& config = json["string"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save Vec4s - { - nlohmann::ordered_json& config = json["vec4"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save IVec4s - { - nlohmann::ordered_json& config = json["ivec4"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - - // Save ShowFlags - { - nlohmann::ordered_json& config = json["showflag"]; - for (i32 i = 0; i < cvarSystem->GetCVarArray()->lastCVar; i++) - { - CVarStorage& cvar = cvarSystem->GetCVarArray()->cvars[i]; - CVarParameter* parameter = cvar.parameter; - - if ((parameter->flags & CVarFlags::DoNotSave) != CVarFlags::None) - continue; - - nlohmann::json object = nlohmann::json::object(); - { - object["category"] = parameter->category; - object["name"] = parameter->name; - object["initial"] = cvar.initial; - object["current"] = cvar.current; - object["type"] = parameter->type; - object["flags"] = parameter->flags; - object["description"] = parameter->description; - } - - std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); - config[qualifiedName] = object; - } - } - } - - void LoadCVarsFromJson(nlohmann::ordered_json& json) - { - CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); - - // Load Integers - { - nlohmann::ordered_json& config = json["integer"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - i32 initial = value["initial"].get(); - i32 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateIntCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = flags; - } - } - } - - // Load Doubles - { - nlohmann::ordered_json& config = json["double"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - f64 initial = value["initial"].get(); - f64 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load Strings - { - nlohmann::ordered_json& config = json["string"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - std::string& initial = value["initial"].get_ref(); - std::string& current = value["current"].get_ref(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateStringCVar(category, name.c_str(), description.c_str(), initial.c_str(), current.c_str(), flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load Vec4s - { - nlohmann::ordered_json& config = json["vec4"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - vec4 initial = value["initial"].get(); - vec4 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load IVec4s - { - nlohmann::ordered_json& config = json["ivec4"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - ivec4 initial = value["initial"].get(); - ivec4 current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - - // Load ShowFlags - { - nlohmann::ordered_json& config = json["showflag"]; - - for (auto it = config.begin(); it != config.end(); it++) - { - const std::string& key = it.key(); - nlohmann::ordered_json& value = it.value(); - - CVarCategory category = value["category"].get(); - std::string& name = value["name"].get_ref(); - - u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); - ShowFlag initial = value["initial"].get(); - ShowFlag current = value["current"].get(); - std::string& description = value["description"].get_ref(); - CVarFlags flags = value["flags"].get(); - - CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); - if (!parameter) - { - if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) - { - parameter = cvarSystem->CreateShowFlagCVar(category, name.c_str(), description.c_str(), initial, current, flags); - } - } - else - { - CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); - - storage->initial = initial; - storage->current = current; - parameter->description = description; - parameter->type = value["type"].get(); - parameter->flags = value["flags"].get(); - } - } - } - } + object["initial"] = cvar.initial; + object["current"] = cvar.current; + object["type"] = parameter->type; + object["flags"] = parameter->flags; + object["description"] = parameter->description; + } + + std::string qualifiedName = CVarSystemImpl::GetQualifiedName(parameter->category, parameter->name.c_str()); + config[qualifiedName] = object; + } + } + } + + void LoadCVarsFromJson(nlohmann::ordered_json& json) + { + CVarSystemImpl* cvarSystem = CVarSystemImpl::Get(); + + // Load Integers + { + nlohmann::ordered_json& config = json["integer"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + i32 initial = value["initial"].get(); + i32 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateIntCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = flags; + } + } + } + + // Load Doubles + { + nlohmann::ordered_json& config = json["double"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + f64 initial = value["initial"].get(); + f64 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load Strings + { + nlohmann::ordered_json& config = json["string"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + std::string& initial = value["initial"].get_ref(); + std::string& current = value["current"].get_ref(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateStringCVar(category, name.c_str(), description.c_str(), initial.c_str(), current.c_str(), flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load Vec4s + { + nlohmann::ordered_json& config = json["vec4"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + vec4 initial = value["initial"].get(); + vec4 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load IVec4s + { + nlohmann::ordered_json& config = json["ivec4"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + ivec4 initial = value["initial"].get(); + ivec4 current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateVecFloatCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + + // Load ShowFlags + { + nlohmann::ordered_json& config = json["showflag"]; + + for (auto it = config.begin(); it != config.end(); it++) + { + const std::string& key = it.key(); + nlohmann::ordered_json& value = it.value(); + + CVarCategory category = value["category"].get(); + std::string& name = value["name"].get_ref(); + + u32 cvarQualifiedNameHash = StringUtils::fnv1a_32(key.c_str(), key.length()); + ShowFlag initial = value["initial"].get(); + ShowFlag current = value["current"].get(); + std::string& description = value["description"].get_ref(); + CVarFlags flags = value["flags"].get(); + + CVarParameter* parameter = cvarSystem->GetCVar(cvarQualifiedNameHash); + if (!parameter) + { + if ((flags & CVarFlags::RuntimeCreated) != CVarFlags::None) + { + parameter = cvarSystem->CreateShowFlagCVar(category, name.c_str(), description.c_str(), initial, current, flags); + } + } + else + { + CVarStorage* storage = cvarSystem->GetCVarArray()->GetCurrentStorage(parameter->arrayIndex); + + storage->initial = initial; + storage->current = current; + parameter->description = description; + parameter->type = value["type"].get(); + parameter->flags = value["flags"].get(); + } + } + } + } } \ No newline at end of file diff --git a/Source/Base/Base/Util/JsonUtils.h b/Source/Base/Base/Util/JsonUtils.h index 1db82cbd..b0db8cb9 100644 --- a/Source/Base/Base/Util/JsonUtils.h +++ b/Source/Base/Base/Util/JsonUtils.h @@ -7,19 +7,19 @@ class CVarSystem; namespace JsonUtils { - bool LoadFromPath(nlohmann::json& json, const std::filesystem::path& path); - bool LoadFromPathOrCreate(nlohmann::json& json, const nlohmann::json& fallback, const std::filesystem::path& path); - bool SaveToPath(const nlohmann::json& json, const std::filesystem::path& path); + bool LoadFromPath(nlohmann::json& json, const std::filesystem::path& path); + bool LoadFromPathOrCreate(nlohmann::json& json, const nlohmann::json& fallback, const std::filesystem::path& path); + bool SaveToPath(const nlohmann::json& json, const std::filesystem::path& path); - bool LoadFromPath(nlohmann::ordered_json& json, const std::filesystem::path& path); - bool LoadFromPathOrCreate(nlohmann::ordered_json& json, const nlohmann::ordered_json& fallback, const std::filesystem::path& path); - bool SaveToPath(const nlohmann::ordered_json& json, const std::filesystem::path& path); + bool LoadFromPath(nlohmann::ordered_json& json, const std::filesystem::path& path); + bool LoadFromPathOrCreate(nlohmann::ordered_json& json, const nlohmann::ordered_json& fallback, const std::filesystem::path& path); + bool SaveToPath(const nlohmann::ordered_json& json, const std::filesystem::path& path); - constexpr u32 CVAR_VERSION = 1u; - void VerifyCVarsOrFallback(nlohmann::json& json, const nlohmann::json& fallback); - void SaveCVarsToJson(nlohmann::json& json); - void LoadCVarsFromJson(nlohmann::json& json); + constexpr u32 CVAR_VERSION = 1u; + void VerifyCVarsOrFallback(nlohmann::json& json, const nlohmann::json& fallback); + void SaveCVarsToJson(nlohmann::json& json); + void LoadCVarsFromJson(nlohmann::json& json); - void SaveCVarsToJson(nlohmann::ordered_json& json); - void LoadCVarsFromJson(nlohmann::ordered_json& json); + void SaveCVarsToJson(nlohmann::ordered_json& json); + void LoadCVarsFromJson(nlohmann::ordered_json& json); } \ No newline at end of file