Simplified usage of jsonFindUserConfig

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-02-05 06:29:01 +01:00
parent 59bff58f5c
commit 9bb0a40bc5
8 changed files with 21 additions and 15 deletions

View File

@ -40,9 +40,9 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
std::string json = data.dump ();
auto id_it = jsonFindRequired (data, "id", "Objects must have id");
auto visible = jsonFindUserConfig <CUserSettingBoolean, bool> (data, "visible", true);
auto origin = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (data, "origin", {0, 0, 0});
auto scale = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (data, "scale", {0, 0, 0});
auto visible = jsonFindUserConfig <CUserSettingBoolean> (data, "visible", true);
auto origin = jsonFindUserConfig <CUserSettingVector3> (data, "origin", {0, 0, 0});
auto scale = jsonFindUserConfig <CUserSettingVector3> (data, "scale", {0, 0, 0});
auto angles_val = jsonFindDefault <std::string> (data, "angles", "0.0 0.0 0.0");
auto name_it = jsonFindRequired (data, "name", "Objects must have name");
auto effects_it = data.find ("effects");
@ -123,7 +123,7 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
{
for (const auto& cur : *effects_it)
{
auto effectVisible = jsonFindUserConfig <CUserSettingBoolean, bool> (data, "visible", true);
auto effectVisible = jsonFindUserConfig <CUserSettingBoolean> (data, "visible", true);
object->insertEffect (
Objects::CEffect::fromJSON (cur, effectVisible, object, container)

View File

@ -62,9 +62,9 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
// TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA PARALLAX ARE PRESENT
auto ambientcolor = jsonFindDefault <std::string> (*general_it, "ambientcolor", "0 0 0");
auto bloom = jsonFindUserConfig <CUserSettingBoolean, bool> (*general_it, "bloom", false);
auto bloomstrength = jsonFindUserConfig <CUserSettingFloat, double> (*general_it, "bloomstrength", 0.0);
auto bloomthreshold = jsonFindUserConfig <CUserSettingFloat, double> (*general_it, "bloomthreshold", 0.0);
auto bloom = jsonFindUserConfig <CUserSettingBoolean> (*general_it, "bloom", false);
auto bloomstrength = jsonFindUserConfig <CUserSettingFloat> (*general_it, "bloomstrength", 0.0);
auto bloomthreshold = jsonFindUserConfig <CUserSettingFloat> (*general_it, "bloomthreshold", 0.0);
auto camerafade = jsonFindDefault <bool> (*general_it, "camerafade", false);
auto cameraparallax = jsonFindDefault <bool> (*general_it, "cameraparallax", true);
auto cameraparallaxamount = jsonFindDefault <double> (*general_it, "cameraparallaxamount", 1.0f);
@ -75,7 +75,7 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
auto camerashakeamplitude = jsonFindDefault <double> (*general_it, "camerashakeamplitude", 0.0f);
auto camerashakeroughness = jsonFindDefault <double> (*general_it, "camerashakeroughness", 0.0f);
auto camerashakespeed = jsonFindDefault <double> (*general_it, "camerashakespeed", 0.0f);
auto clearcolor = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (*general_it, "clearcolor", {1, 1, 1});
auto clearcolor = jsonFindUserConfig <CUserSettingVector3> (*general_it, "clearcolor", {1, 1, 1});
auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info");
auto skylightcolor = jsonFindDefault <std::string> (*general_it, "skylightcolor", "0 0 0");

View File

@ -144,7 +144,7 @@ template uint64_t Core::jsonFindDefault (nlohmann::json& data, const char *key,
template float Core::jsonFindDefault (nlohmann::json& data, const char *key, float defaultValue);
template double Core::jsonFindDefault (nlohmann::json& data, const char *key, double defaultValue);
template <typename T, typename S> T* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, S defaultValue)
template <typename T> T* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, typename T::data_type defaultValue)
{
auto it = data.find (key);
@ -154,6 +154,6 @@ template <typename T, typename S> T* Core::jsonFindUserConfig (nlohmann::json& d
return T::fromJSON (*it);
}
template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, bool defaultValue);
template CUserSettingVector3* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, glm::vec3 defaultValue);
template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, double defaultValue);
template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, CUserSettingBoolean::data_type defaultValue);
template CUserSettingVector3* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, CUserSettingVector3::data_type defaultValue);
template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, CUserSettingFloat::data_type defaultValue);

View File

@ -25,5 +25,5 @@ namespace WallpaperEngine::Core
nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg);
nlohmann::json::iterator jsonFindRequired (nlohmann::json::iterator& data, const char *key, const char *notFoundMsg);
template <typename T> T jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue);
template <typename T, typename S> T* jsonFindUserConfig (nlohmann::json& data, const char *key, S defaultValue);
template <typename T> T* jsonFindUserConfig (nlohmann::json& data, const char *key, typename T::data_type defaultValue);
};

View File

@ -55,8 +55,8 @@ WallpaperEngine::Core::CObject* CImage::fromJSON (
auto image_it = data.find ("image");
auto size_val = jsonFindDefault <std::string> (data, "size", "0.0 0.0"); // this one might need some adjustment
auto alignment = jsonFindDefault <std::string> (data, "alignment", "center");
auto alpha = jsonFindUserConfig <CUserSettingFloat, double> (data, "alpha", 1.0);
auto color = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (data, "color", {1, 1, 1});
auto alpha = jsonFindUserConfig <CUserSettingFloat> (data, "alpha", 1.0);
auto color = jsonFindUserConfig <CUserSettingVector3> (data, "color", {1, 1, 1});
auto brightness_val = jsonFindDefault <float> (data, "brightness", 1.0);
auto colorBlendMode_val = jsonFindDefault <uint32_t> (data, "colorBlendMode", 0);
auto parallaxDepth_val = jsonFindDefault <std::string> (data, "parallaxDepth", "0 0");

View File

@ -12,6 +12,8 @@ namespace WallpaperEngine::Core::UserSettings
class CUserSettingBoolean : public CUserSettingValue
{
public:
typedef bool data_type;
static CUserSettingBoolean* fromJSON (nlohmann::json& data);
static CUserSettingBoolean* fromScalar (bool value);
static std::string Type;

View File

@ -12,6 +12,8 @@ namespace WallpaperEngine::Core::UserSettings
class CUserSettingFloat : public CUserSettingValue
{
public:
typedef double data_type;
static CUserSettingFloat* fromJSON (nlohmann::json& data);
static CUserSettingFloat* fromScalar (double value);
static std::string Type;

View File

@ -14,6 +14,8 @@ namespace WallpaperEngine::Core::UserSettings
class CUserSettingVector3 : public CUserSettingValue
{
public:
typedef glm::vec3 data_type;
static CUserSettingVector3* fromJSON (nlohmann::json& data);
static CUserSettingVector3* fromScalar (glm::vec3 value);
static std::string Type;