mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 13:22:23 +08:00
~ some settings for the camera are optional, so treat them that way (camera shake and parallax)
+ added helper functions to get optional values in an easy way Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
d5ee71540d
commit
27b50ffac9
@ -48,26 +48,28 @@ CScene::CScene (
|
|||||||
|
|
||||||
CScene* CScene::fromFile (const irr::io::path& filename)
|
CScene* CScene::fromFile (const irr::io::path& filename)
|
||||||
{
|
{
|
||||||
|
std::string stringContent = WallpaperEngine::FileSystem::loadFullFile (filename);
|
||||||
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename));
|
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename));
|
||||||
|
|
||||||
auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
|
auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera");
|
||||||
auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
|
auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section");
|
||||||
auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display");
|
auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display");
|
||||||
|
|
||||||
|
// 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_it = jsonFindRequired (*general_it, "bloom", "General section must have bloom flag");
|
||||||
auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength");
|
auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength");
|
||||||
auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold");
|
auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold");
|
||||||
auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade");
|
auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade");
|
||||||
auto cameraparallax_it = jsonFindRequired (*general_it, "cameraparallax", "General section must have camera parallax");
|
auto cameraparallax = jsonFindDefault <bool> (*general_it, "cameraparallax", true);
|
||||||
auto cameraparallaxamount_it = jsonFindRequired (*general_it, "cameraparallaxamount", "General section must have camera parallax amount");
|
auto cameraparallaxamount = jsonFindDefault <irr::f64> (*general_it, "cameraparallaxamount", 1.0f);
|
||||||
auto cameraparallaxdelay_it = jsonFindRequired (*general_it, "cameraparallaxdelay", "General section must have camera parallax delay");
|
auto cameraparallaxdelay = jsonFindDefault <irr::f64> (*general_it, "cameraparallaxdelay", 0.0f);
|
||||||
auto cameraparallaxmouseinfluence_it = jsonFindRequired (*general_it, "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence");
|
auto cameraparallaxmouseinfluence = jsonFindDefault <irr::f64> (*general_it, "cameraparallaxmouseinfluence", 1.0f);
|
||||||
auto camerapreview_it = jsonFindRequired (*general_it, "camerapreview", "General section must have camera preview");
|
auto camerapreview = jsonFindDefault <bool> (*general_it, "camerapreview", false);
|
||||||
auto camerashake_it = jsonFindRequired (*general_it, "camerashake", "General section must have camera shake");
|
auto camerashake = jsonFindDefault <bool> (*general_it, "camerashake", false);
|
||||||
auto camerashakeamplitude_it = jsonFindRequired (*general_it, "camerashakeamplitude", "General section must have camera shake amplitude");
|
auto camerashakeamplitude = jsonFindDefault <irr::f64> (*general_it, "camerashakeamplitude", 0.0f);
|
||||||
auto camerashakeroughness_it = jsonFindRequired (*general_it, "camerashakeroughness", "General section must have camera shake roughness");
|
auto camerashakeroughness = jsonFindDefault <irr::f64> (*general_it, "camerashakeroughness", 0.0f);
|
||||||
auto camerashakespeed_it = jsonFindRequired (*general_it, "camerashakespeed", "General section must have camera shake speed");
|
auto camerashakespeed = jsonFindDefault <irr::f64> (*general_it, "camerashakespeed", 0.0f);
|
||||||
auto clearcolor_it = jsonFindRequired (*general_it, "clearcolor", "General section must have clear color");
|
auto clearcolor_it = jsonFindRequired (*general_it, "clearcolor", "General section must have clear color");
|
||||||
auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info");
|
auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info");
|
||||||
auto skylightcolor_it = jsonFindRequired (*general_it, "skylightcolor", "General section must have skylight color");
|
auto skylightcolor_it = jsonFindRequired (*general_it, "skylightcolor", "General section must have skylight color");
|
||||||
@ -79,15 +81,15 @@ CScene* CScene::fromFile (const irr::io::path& filename)
|
|||||||
*bloomstrength_it,
|
*bloomstrength_it,
|
||||||
*bloomthreshold_it,
|
*bloomthreshold_it,
|
||||||
*camerafade_it,
|
*camerafade_it,
|
||||||
*cameraparallax_it,
|
cameraparallax,
|
||||||
*cameraparallaxamount_it,
|
cameraparallaxamount,
|
||||||
*cameraparallaxdelay_it,
|
cameraparallaxdelay,
|
||||||
*cameraparallaxmouseinfluence_it,
|
cameraparallaxmouseinfluence,
|
||||||
*camerapreview_it,
|
camerapreview,
|
||||||
*camerashake_it,
|
camerashake,
|
||||||
*camerashakeamplitude_it,
|
camerashakeamplitude,
|
||||||
*camerashakeroughness_it,
|
camerashakeroughness,
|
||||||
*camerashakespeed_it,
|
camerashakespeed,
|
||||||
WallpaperEngine::Core::atoSColorf (*clearcolor_it),
|
WallpaperEngine::Core::atoSColorf (*clearcolor_it),
|
||||||
Scenes::CProjection::fromJSON (*orthogonalprojection_it),
|
Scenes::CProjection::fromJSON (*orthogonalprojection_it),
|
||||||
WallpaperEngine::Core::atoSColorf (*skylightcolor_it)
|
WallpaperEngine::Core::atoSColorf (*skylightcolor_it)
|
||||||
|
@ -71,3 +71,26 @@ nlohmann::json::iterator Core::jsonFindRequired (nlohmann::json& data, const cha
|
|||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue)
|
||||||
|
{
|
||||||
|
auto value = data.find (key);
|
||||||
|
|
||||||
|
if (value == data.end ())
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template bool Core::jsonFindDefault (nlohmann::json& data, const char *key, bool defaultValue);
|
||||||
|
template std::string Core::jsonFindDefault (nlohmann::json& data, const char *key, std::string defaultValue);
|
||||||
|
template irr::s16 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::s16 defaultValue);
|
||||||
|
template irr::u16 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::u16 defaultValue);
|
||||||
|
template irr::s32 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::s32 defaultValue);
|
||||||
|
template irr::u32 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::u32 defaultValue);
|
||||||
|
template irr::s64 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::s64 defaultValue);
|
||||||
|
template irr::u64 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::u64 defaultValue);
|
||||||
|
template irr::f32 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::f32 defaultValue);
|
||||||
|
template irr::f64 Core::jsonFindDefault (nlohmann::json& data, const char *key, irr::f64 defaultValue);
|
@ -19,4 +19,5 @@ namespace WallpaperEngine::Core
|
|||||||
irr::video::SColor atoSColor (const std::string& str);
|
irr::video::SColor atoSColor (const std::string& str);
|
||||||
|
|
||||||
nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg);
|
nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg);
|
||||||
|
template <typename T> T jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user