mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Removed old jsonFindUserConfig and updated to a new version using the CUserSetting classes
Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
176470dad9
commit
fdd5bcb0b5
@ -39,14 +39,7 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
|
|||||||
std::string json = data.dump ();
|
std::string json = data.dump ();
|
||||||
|
|
||||||
auto id_it = jsonFindRequired (data, "id", "Objects must have id");
|
auto id_it = jsonFindRequired (data, "id", "Objects must have id");
|
||||||
auto visible_it = data.find ("visible");
|
auto visible = jsonFindUserConfig <CUserSettingBoolean, bool> (data, "visible", true);
|
||||||
CUserSettingBoolean* visible;
|
|
||||||
|
|
||||||
if (visible_it == data.end ())
|
|
||||||
visible = CUserSettingBoolean::fromScalar (true);
|
|
||||||
else
|
|
||||||
visible = CUserSettingBoolean::fromJSON (*visible_it);
|
|
||||||
|
|
||||||
auto origin_val = jsonFindDefault <std::string> (data, "origin", "0.0 0.0 0.0");
|
auto origin_val = jsonFindDefault <std::string> (data, "origin", "0.0 0.0 0.0");
|
||||||
auto scale_val = jsonFindDefault <std::string> (data, "scale", "0.0 0.0 0.0");
|
auto scale_val = jsonFindDefault <std::string> (data, "scale", "0.0 0.0 0.0");
|
||||||
auto angles_val = jsonFindDefault <std::string> (data, "angles", "0.0 0.0 0.0");
|
auto angles_val = jsonFindDefault <std::string> (data, "angles", "0.0 0.0 0.0");
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include "WallpaperEngine/Core/Objects/CEffect.h"
|
#include "WallpaperEngine/Core/Objects/CEffect.h"
|
||||||
#include "WallpaperEngine/Assets/CContainer.h"
|
#include "WallpaperEngine/Assets/CContainer.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
|
||||||
|
|
||||||
namespace WallpaperEngine::Core
|
namespace WallpaperEngine::Core
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
#include "WallpaperEngine/FileSystem/FileSystem.h"
|
||||||
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine::Core;
|
using namespace WallpaperEngine::Core;
|
||||||
|
|
||||||
@ -11,8 +13,8 @@ CScene::CScene (
|
|||||||
Scenes::CCamera* camera,
|
Scenes::CCamera* camera,
|
||||||
glm::vec3 ambientColor,
|
glm::vec3 ambientColor,
|
||||||
CUserSettingBoolean* bloom,
|
CUserSettingBoolean* bloom,
|
||||||
double bloomStrength,
|
CUserSettingFloat* bloomStrength,
|
||||||
double bloomThreshold,
|
CUserSettingFloat* bloomThreshold,
|
||||||
bool cameraFade,
|
bool cameraFade,
|
||||||
bool cameraParallax,
|
bool cameraParallax,
|
||||||
double cameraParallaxAmount,
|
double cameraParallaxAmount,
|
||||||
@ -23,7 +25,7 @@ CScene::CScene (
|
|||||||
double cameraShakeAmplitude,
|
double cameraShakeAmplitude,
|
||||||
double cameraShakeRoughness,
|
double cameraShakeRoughness,
|
||||||
double cameraShakeSpeed,
|
double cameraShakeSpeed,
|
||||||
glm::vec3 clearColor,
|
CUserSettingColor* clearColor,
|
||||||
Scenes::CProjection* orthogonalProjection,
|
Scenes::CProjection* orthogonalProjection,
|
||||||
glm::vec3 skylightColor) :
|
glm::vec3 skylightColor) :
|
||||||
CWallpaper (Type),
|
CWallpaper (Type),
|
||||||
@ -60,16 +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
|
// 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 ambientcolor = jsonFindDefault <std::string> (*general_it, "ambientcolor", "0 0 0");
|
||||||
auto bloom_it = (*general_it).find ("bloom");
|
auto bloom = jsonFindUserConfig <CUserSettingBoolean, bool> (*general_it, "bloom", false);
|
||||||
CUserSettingBoolean* bloom;
|
auto bloomstrength = jsonFindUserConfig <CUserSettingFloat, double> (*general_it, "bloomstrength", 0.0);
|
||||||
|
auto bloomthreshold = jsonFindUserConfig <CUserSettingFloat, double> (*general_it, "bloomthreshold", 0.0);
|
||||||
if (bloom_it == (*general_it).end ())
|
|
||||||
bloom = CUserSettingBoolean::fromScalar (false);
|
|
||||||
else
|
|
||||||
bloom = CUserSettingBoolean::fromJSON (*bloom_it);
|
|
||||||
|
|
||||||
auto bloomstrength = jsonFindUserConfig <float> (*general_it, "bloomstrength", 0.0);
|
|
||||||
auto bloomthreshold = jsonFindUserConfig <float> (*general_it, "bloomthreshold", 0.0);
|
|
||||||
auto camerafade = jsonFindDefault <bool> (*general_it, "camerafade", false);
|
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);
|
||||||
@ -80,7 +75,7 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
|
|||||||
auto camerashakeamplitude = jsonFindDefault <double> (*general_it, "camerashakeamplitude", 0.0f);
|
auto camerashakeamplitude = jsonFindDefault <double> (*general_it, "camerashakeamplitude", 0.0f);
|
||||||
auto camerashakeroughness = jsonFindDefault <double> (*general_it, "camerashakeroughness", 0.0f);
|
auto camerashakeroughness = jsonFindDefault <double> (*general_it, "camerashakeroughness", 0.0f);
|
||||||
auto camerashakespeed = jsonFindDefault <double> (*general_it, "camerashakespeed", 0.0f);
|
auto camerashakespeed = jsonFindDefault <double> (*general_it, "camerashakespeed", 0.0f);
|
||||||
auto clearcolor = jsonFindUserConfig <std::string> (*general_it, "clearcolor", "1 1 1");
|
auto clearcolor = jsonFindUserConfig <CUserSettingColor, glm::vec3> (*general_it, "clearcolor", {1, 1, 1});
|
||||||
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 = jsonFindDefault <std::string> (*general_it, "skylightcolor", "0 0 0");
|
auto skylightcolor = jsonFindDefault <std::string> (*general_it, "skylightcolor", "0 0 0");
|
||||||
|
|
||||||
@ -101,7 +96,7 @@ CScene* CScene::fromFile (const std::string& filename, CContainer* container)
|
|||||||
camerashakeamplitude,
|
camerashakeamplitude,
|
||||||
camerashakeroughness,
|
camerashakeroughness,
|
||||||
camerashakespeed,
|
camerashakespeed,
|
||||||
WallpaperEngine::Core::aToColorf(clearcolor),
|
clearcolor,
|
||||||
Scenes::CProjection::fromJSON (*orthogonalprojection_it),
|
Scenes::CProjection::fromJSON (*orthogonalprojection_it),
|
||||||
WallpaperEngine::Core::aToColorf(skylightcolor)
|
WallpaperEngine::Core::aToColorf(skylightcolor)
|
||||||
);
|
);
|
||||||
@ -158,14 +153,14 @@ const bool CScene::isBloom () const
|
|||||||
return this->m_bloom->processValue (this->getProject ()->getProperties ());
|
return this->m_bloom->processValue (this->getProject ()->getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getBloomStrength () const
|
double CScene::getBloomStrength () const
|
||||||
{
|
{
|
||||||
return this->m_bloomStrength;
|
return this->m_bloomStrength->processValue (this->getProject ()->getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
const double CScene::getBloomThreshold () const
|
double CScene::getBloomThreshold () const
|
||||||
{
|
{
|
||||||
return this->m_bloomThreshold;
|
return this->m_bloomThreshold->processValue (this->getProject ()->getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool CScene::isCameraFade () const
|
const bool CScene::isCameraFade () const
|
||||||
@ -218,9 +213,9 @@ const double CScene::getCameraShakeSpeed () const
|
|||||||
return this->m_cameraShakeSpeed;
|
return this->m_cameraShakeSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3& CScene::getClearColor () const
|
glm::vec3 CScene::getClearColor () const
|
||||||
{
|
{
|
||||||
return this->m_clearColor;
|
return this->m_clearColor->processValue (this->getProject ()->getProperties ());
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenes::CProjection* CScene::getOrthogonalProjection () const
|
Scenes::CProjection* CScene::getOrthogonalProjection () const
|
||||||
|
@ -24,8 +24,8 @@ namespace WallpaperEngine::Core
|
|||||||
|
|
||||||
const glm::vec3& getAmbientColor() const;
|
const glm::vec3& getAmbientColor() const;
|
||||||
const bool isBloom() const;
|
const bool isBloom() const;
|
||||||
const double getBloomStrength() const;
|
double getBloomStrength() const;
|
||||||
const double getBloomThreshold() const;
|
double getBloomThreshold() const;
|
||||||
const bool isCameraFade() const;
|
const bool isCameraFade() const;
|
||||||
const bool isCameraParallax() const;
|
const bool isCameraParallax() const;
|
||||||
const double getCameraParallaxAmount() const;
|
const double getCameraParallaxAmount() const;
|
||||||
@ -36,7 +36,7 @@ namespace WallpaperEngine::Core
|
|||||||
const double getCameraShakeAmplitude() const;
|
const double getCameraShakeAmplitude() const;
|
||||||
const double getCameraShakeRoughness() const;
|
const double getCameraShakeRoughness() const;
|
||||||
const double getCameraShakeSpeed() const;
|
const double getCameraShakeSpeed() const;
|
||||||
const glm::vec3& getClearColor() const;
|
glm::vec3 getClearColor() const;
|
||||||
Scenes::CProjection* getOrthogonalProjection() const;
|
Scenes::CProjection* getOrthogonalProjection() const;
|
||||||
const glm::vec3& getSkylightColor() const;
|
const glm::vec3& getSkylightColor() const;
|
||||||
const Scenes::CCamera* getCamera () const;
|
const Scenes::CCamera* getCamera () const;
|
||||||
@ -49,8 +49,8 @@ namespace WallpaperEngine::Core
|
|||||||
Scenes::CCamera* camera,
|
Scenes::CCamera* camera,
|
||||||
glm::vec3 ambientColor,
|
glm::vec3 ambientColor,
|
||||||
CUserSettingBoolean* bloom,
|
CUserSettingBoolean* bloom,
|
||||||
double bloomStrength,
|
CUserSettingFloat* bloomStrength,
|
||||||
double bloomThreshold,
|
CUserSettingFloat* bloomThreshold,
|
||||||
bool cameraFade,
|
bool cameraFade,
|
||||||
bool cameraParallax,
|
bool cameraParallax,
|
||||||
double cameraParallaxAmount,
|
double cameraParallaxAmount,
|
||||||
@ -61,7 +61,7 @@ namespace WallpaperEngine::Core
|
|||||||
double cameraShakeAmplitude,
|
double cameraShakeAmplitude,
|
||||||
double cameraShakeRoughness,
|
double cameraShakeRoughness,
|
||||||
double cameraShakeSpeed,
|
double cameraShakeSpeed,
|
||||||
glm::vec3 clearColor,
|
CUserSettingColor* clearColor,
|
||||||
Scenes::CProjection* orthogonalProjection,
|
Scenes::CProjection* orthogonalProjection,
|
||||||
glm::vec3 skylightColor
|
glm::vec3 skylightColor
|
||||||
);
|
);
|
||||||
@ -78,8 +78,8 @@ namespace WallpaperEngine::Core
|
|||||||
// data from general section on the json
|
// data from general section on the json
|
||||||
glm::vec3 m_ambientColor;
|
glm::vec3 m_ambientColor;
|
||||||
CUserSettingBoolean* m_bloom;
|
CUserSettingBoolean* m_bloom;
|
||||||
double m_bloomStrength;
|
CUserSettingFloat* m_bloomStrength;
|
||||||
double m_bloomThreshold;
|
CUserSettingFloat* m_bloomThreshold;
|
||||||
bool m_cameraFade;
|
bool m_cameraFade;
|
||||||
bool m_cameraParallax;
|
bool m_cameraParallax;
|
||||||
double m_cameraParallaxAmount;
|
double m_cameraParallaxAmount;
|
||||||
@ -90,7 +90,7 @@ namespace WallpaperEngine::Core
|
|||||||
double m_cameraShakeAmplitude;
|
double m_cameraShakeAmplitude;
|
||||||
double m_cameraShakeRoughness;
|
double m_cameraShakeRoughness;
|
||||||
double m_cameraShakeSpeed;
|
double m_cameraShakeSpeed;
|
||||||
glm::vec3 m_clearColor;
|
CUserSettingColor* m_clearColor;
|
||||||
Scenes::CProjection* m_orthogonalProjection;
|
Scenes::CProjection* m_orthogonalProjection;
|
||||||
glm::vec3 m_skylightColor;
|
glm::vec3 m_skylightColor;
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
|
||||||
|
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
using namespace WallpaperEngine;
|
||||||
|
using namespace WallpaperEngine::Core::UserSettings;
|
||||||
|
|
||||||
glm::vec4 Core::aToVector4 (const char* str)
|
glm::vec4 Core::aToVector4 (const char* str)
|
||||||
{
|
{
|
||||||
@ -141,33 +146,16 @@ template uint64_t Core::jsonFindDefault (nlohmann::json& data, const char *key,
|
|||||||
template float Core::jsonFindDefault (nlohmann::json& data, const char *key, float defaultValue);
|
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 double Core::jsonFindDefault (nlohmann::json& data, const char *key, double defaultValue);
|
||||||
|
|
||||||
template <typename T> T Core::jsonFindUserConfig (nlohmann::json& data, const char *key, T defaultValue)
|
template <typename T, typename S> T* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, S defaultValue)
|
||||||
{
|
{
|
||||||
auto value = data.find (key);
|
auto it = data.find (key);
|
||||||
|
|
||||||
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
|
if (it == data.end () || it->type () == nlohmann::detail::value_t::null)
|
||||||
return defaultValue;
|
return T::fromScalar (defaultValue);
|
||||||
|
|
||||||
if (value->is_object () == true)
|
return T::fromJSON (*it);
|
||||||
{
|
|
||||||
auto internal = value->find ("value");
|
|
||||||
|
|
||||||
if (internal == value->end ())
|
|
||||||
return defaultValue;
|
|
||||||
|
|
||||||
value = internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template bool Core::jsonFindUserConfig (nlohmann::json& data, const char *key, bool defaultValue);
|
template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, bool defaultValue);
|
||||||
template std::string Core::jsonFindUserConfig (nlohmann::json& data, const char *key, std::string defaultValue);
|
template CUserSettingColor* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, glm::vec3 defaultValue);
|
||||||
template int16_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, int16_t defaultValue);
|
template CUserSettingFloat* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, double defaultValue);
|
||||||
template uint16_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, uint16_t defaultValue);
|
|
||||||
template int32_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, int32_t defaultValue);
|
|
||||||
template uint32_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, uint32_t defaultValue);
|
|
||||||
template int64_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, int64_t defaultValue);
|
|
||||||
template uint64_t Core::jsonFindUserConfig (nlohmann::json& data, const char *key, uint64_t defaultValue);
|
|
||||||
template float Core::jsonFindUserConfig (nlohmann::json& data, const char *key, float defaultValue);
|
|
||||||
template double Core::jsonFindUserConfig (nlohmann::json& data, const char *key, double defaultValue);
|
|
@ -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& data, const char *key, const char *notFoundMsg);
|
||||||
nlohmann::json::iterator jsonFindRequired (nlohmann::json::iterator& 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> T jsonFindDefault (nlohmann::json& data, const char *key, T defaultValue);
|
||||||
template <typename T> T jsonFindUserConfig (nlohmann::json& data, const char *key, T defaultValue);
|
template <typename T, typename S> T* jsonFindUserConfig (nlohmann::json& data, const char *key, S defaultValue);
|
||||||
};
|
};
|
||||||
|
@ -55,22 +55,8 @@ WallpaperEngine::Core::CObject* CImage::fromJSON (
|
|||||||
auto image_it = data.find ("image");
|
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 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 alignment = jsonFindDefault <std::string> (data, "alignment", "center");
|
||||||
auto alpha_it = data.find ("alpha");
|
auto alpha = jsonFindUserConfig <CUserSettingFloat, double> (data, "alpha", 1.0);
|
||||||
CUserSettingFloat* alpha;
|
auto color = jsonFindUserConfig <CUserSettingColor, glm::vec3> (data, "color", {1, 1, 1});
|
||||||
|
|
||||||
if (alpha_it == data.end ())
|
|
||||||
alpha = CUserSettingFloat::fromScalar (1.0);
|
|
||||||
else
|
|
||||||
alpha = CUserSettingFloat::fromJSON (*alpha_it);
|
|
||||||
|
|
||||||
auto color_it = data.find ("color");
|
|
||||||
CUserSettingColor* color;
|
|
||||||
|
|
||||||
if (color_it == data.end ())
|
|
||||||
color = CUserSettingColor::fromScalar ({1, 1, 1});
|
|
||||||
else
|
|
||||||
color = CUserSettingColor::fromJSON (*color_it);
|
|
||||||
|
|
||||||
auto brightness_val = jsonFindDefault <float> (data, "brightness", 1.0);
|
auto brightness_val = jsonFindDefault <float> (data, "brightness", 1.0);
|
||||||
auto colorBlendMode_val = jsonFindDefault <uint32_t> (data, "colorBlendMode", 0);
|
auto colorBlendMode_val = jsonFindDefault <uint32_t> (data, "colorBlendMode", 0);
|
||||||
auto parallaxDepth_val = jsonFindDefault <std::string> (data, "parallaxDepth", "0 0");
|
auto parallaxDepth_val = jsonFindDefault <std::string> (data, "parallaxDepth", "0 0");
|
||||||
|
Loading…
Reference in New Issue
Block a user