~ changed some json data to have a default value if it's null or not-existant

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-09-08 21:17:02 +02:00
parent 73c40c3d4e
commit 3f4996234e
2 changed files with 9 additions and 11 deletions

View File

@ -61,10 +61,10 @@ 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 // TODO: FIND IF THESE DEFAULTS ARE SENSIBLE OR NOT AND PERFORM PROPER VALIDATION WHEN CAMERA PREVIEW AND CAMERA PARALLAX ARE PRESENT
auto ambientcolor_it = jsonFindRequired (*general_it, "ambientcolor", "General section must have ambient color"); auto ambientcolor_it = jsonFindRequired (*general_it, "ambientcolor", "General section must have ambient color");
auto bloom_it = jsonFindRequired (*general_it, "bloom", "General section must have bloom flag"); auto bloom = jsonFindDefault <bool> (*general_it, "bloom", false);
auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength"); auto bloomstrength = jsonFindDefault <double> (*general_it, "bloomstrength", 0.0f);
auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold"); auto bloomthreshold = jsonFindDefault <double> (*general_it, "bloomthreshold", 0.0f);
auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade"); auto camerafade = jsonFindDefault <bool> (*general_it, "camerafade", false);
auto cameraparallax = jsonFindDefault <bool> (*general_it, "cameraparallax", true); auto cameraparallax = jsonFindDefault <bool> (*general_it, "cameraparallax", true);
auto cameraparallaxamount = jsonFindDefault <double> (*general_it, "cameraparallaxamount", 1.0f); auto cameraparallaxamount = jsonFindDefault <double> (*general_it, "cameraparallaxamount", 1.0f);
auto cameraparallaxdelay = jsonFindDefault <double> (*general_it, "cameraparallaxdelay", 0.0f); auto cameraparallaxdelay = jsonFindDefault <double> (*general_it, "cameraparallaxdelay", 0.0f);
@ -82,10 +82,10 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
container, container,
Scenes::CCamera::fromJSON (*camera_it), Scenes::CCamera::fromJSON (*camera_it),
WallpaperEngine::Core::aToColorf(*ambientcolor_it), WallpaperEngine::Core::aToColorf(*ambientcolor_it),
*bloom_it, bloom,
*bloomstrength_it, bloomstrength,
*bloomthreshold_it, bloomthreshold,
*camerafade_it, camerafade,
cameraparallax, cameraparallax,
cameraparallaxamount, cameraparallaxamount,
cameraparallaxdelay, cameraparallaxdelay,

View File

@ -89,10 +89,8 @@ template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char
{ {
auto value = data.find (key); auto value = data.find (key);
if (value == data.end ()) if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
{
return defaultValue; return defaultValue;
}
return *value; return *value;
} }