Renamed CUserSettingColor to CUserSettingVector3 as it makes more sense

CUserSettingVector3 are initializable with just one float value
Objects' origin and scale are now UserSettings too

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-02-01 03:02:24 +01:00
parent 885221d602
commit 92bdde2bd1
16 changed files with 85 additions and 78 deletions

View File

@ -117,8 +117,8 @@ add_executable(
src/WallpaperEngine/Core/UserSettings/CUserSettingValue.h
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.cpp
src/WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h
src/WallpaperEngine/Core/UserSettings/CUserSettingColor.cpp
src/WallpaperEngine/Core/UserSettings/CUserSettingColor.h
src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.cpp
src/WallpaperEngine/Core/UserSettings/CUserSettingVector3.h
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.cpp
src/WallpaperEngine/Core/UserSettings/CUserSettingFloat.h

View File

@ -20,8 +20,8 @@ CObject::CObject (
uint32_t id,
std::string name,
std::string type,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles) :
m_scene (scene),
m_visible (visible),
@ -40,8 +40,8 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
auto id_it = jsonFindRequired (data, "id", "Objects must have id");
auto visible = jsonFindUserConfig <CUserSettingBoolean, bool> (data, "visible", true);
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 origin = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (data, "origin", {0, 0, 0});
auto scale = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (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");
@ -64,8 +64,8 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
visible,
*id_it,
*name_it,
WallpaperEngine::Core::aToVector3 (origin_val),
WallpaperEngine::Core::aToVector3 (scale_val),
origin,
scale,
WallpaperEngine::Core::aToVector3 (angles_val)
);
}
@ -77,8 +77,8 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
visible,
*id_it,
*name_it,
WallpaperEngine::Core::aToVector3 (origin_val),
WallpaperEngine::Core::aToVector3 (scale_val),
origin,
scale,
WallpaperEngine::Core::aToVector3 (angles_val)
);
}
@ -94,8 +94,8 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
visible,
*id_it,
*name_it,
WallpaperEngine::Core::aToVector3 (origin_val),
WallpaperEngine::Core::aToVector3 (scale_val)
origin,
scale
);
}
catch (std::runtime_error ex)
@ -153,14 +153,14 @@ CObject* CObject::fromJSON (json data, CScene* scene, const CContainer* containe
return object;
}
const glm::vec3& CObject::getOrigin () const
glm::vec3 CObject::getOrigin () const
{
return this->m_origin;
return this->m_origin->processValue (this->getScene ()->getProject ()->getProperties ());
}
const glm::vec3& CObject::getScale () const
glm::vec3 CObject::getScale () const
{
return this->m_scale;
return this->m_scale->processValue (this->getScene ()->getProject ()->getProperties ());
}
const glm::vec3& CObject::getAngles () const

View File

@ -2,11 +2,11 @@
#include "Core.h"
#include "WallpaperEngine/Core/Objects/CEffect.h"
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/Objects/CEffect.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
namespace WallpaperEngine::Core
{
@ -44,8 +44,8 @@ namespace WallpaperEngine::Core
const std::vector<uint32_t>& getDependencies () const;
const int getId () const;
const glm::vec3& getOrigin () const;
const glm::vec3& getScale () const;
glm::vec3 getOrigin () const;
glm::vec3 getScale () const;
const glm::vec3& getAngles () const;
const std::string& getName () const;
@ -58,8 +58,8 @@ namespace WallpaperEngine::Core
uint32_t id,
std::string name,
std::string type,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles
);
@ -71,8 +71,8 @@ namespace WallpaperEngine::Core
CUserSettingBoolean* m_visible;
uint32_t m_id;
std::string m_name;
glm::vec3 m_origin;
glm::vec3 m_scale;
CUserSettingVector3* m_origin;
CUserSettingVector3* m_scale;
glm::vec3 m_angles;
std::vector<Objects::CEffect*> m_effects;

View File

@ -1,10 +1,10 @@
#include "CScene.h"
#include "CProject.h"
#include "WallpaperEngine/FileSystem/FileSystem.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
#include "WallpaperEngine/FileSystem/FileSystem.h"
using namespace WallpaperEngine::Core;
@ -25,7 +25,7 @@ CScene::CScene (
double cameraShakeAmplitude,
double cameraShakeRoughness,
double cameraShakeSpeed,
CUserSettingColor* clearColor,
CUserSettingVector3* clearColor,
Scenes::CProjection* orthogonalProjection,
glm::vec3 skylightColor) :
CWallpaper (Type),
@ -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 <CUserSettingColor, glm::vec3> (*general_it, "clearcolor", {1, 1, 1});
auto clearcolor = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (*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

@ -61,7 +61,7 @@ namespace WallpaperEngine::Core
double cameraShakeAmplitude,
double cameraShakeRoughness,
double cameraShakeSpeed,
CUserSettingColor* clearColor,
CUserSettingVector3* clearColor,
Scenes::CProjection* orthogonalProjection,
glm::vec3 skylightColor
);
@ -90,7 +90,7 @@ namespace WallpaperEngine::Core
double m_cameraShakeAmplitude;
double m_cameraShakeRoughness;
double m_cameraShakeSpeed;
CUserSettingColor* m_clearColor;
CUserSettingVector3* m_clearColor;
Scenes::CProjection* m_orthogonalProjection;
glm::vec3 m_skylightColor;

View File

@ -1,8 +1,8 @@
#include "Core.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
using namespace WallpaperEngine;
using namespace WallpaperEngine::Core::UserSettings;
@ -157,5 +157,5 @@ template <typename T, typename S> T* Core::jsonFindUserConfig (nlohmann::json& d
}
template CUserSettingBoolean* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, bool defaultValue);
template CUserSettingColor* Core::jsonFindUserConfig (nlohmann::json& data, const char *key, glm::vec3 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);

View File

@ -1,11 +1,11 @@
#include "CImage.h"
#include <utility>
#include "WallpaperEngine/Core/CScene.h"
#include "WallpaperEngine/Core/Objects/Images/CMaterial.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
#include <utility>
#include "WallpaperEngine/FileSystem/FileSystem.h"
@ -18,12 +18,12 @@ CImage::CImage (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles,
const glm::vec2& size,
std::string alignment,
CUserSettingColor* color,
CUserSettingVector3* color,
CUserSettingFloat* alpha,
float brightness,
uint32_t colorBlendMode,
@ -48,15 +48,15 @@ WallpaperEngine::Core::CObject* CImage::fromJSON (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles)
{
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 <CUserSettingColor, glm::vec3> (data, "color", {1, 1, 1});
auto color = jsonFindUserConfig <CUserSettingVector3, glm::vec3> (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

@ -8,8 +8,8 @@
#include "WallpaperEngine/Assets/CContainer.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingBoolean.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingColor.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingFloat.h"
#include "WallpaperEngine/Core/UserSettings/CUserSettingVector3.h"
namespace WallpaperEngine::Core
{
@ -33,8 +33,8 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles
);
@ -54,12 +54,12 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles,
const glm::vec2& size,
std::string alignment,
CUserSettingColor* color,
CUserSettingVector3* color,
CUserSettingFloat* alpha,
float brightness,
uint32_t colorBlendMode,
@ -75,7 +75,7 @@ namespace WallpaperEngine::Core::Objects
std::string m_alignment;
CUserSettingFloat* m_alpha;
float m_brightness;
CUserSettingColor* m_color;
CUserSettingVector3* m_color;
uint32_t m_colorBlendMode;
};
};

View File

@ -10,8 +10,8 @@ CParticle* CParticle::fromFile (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale)
CUserSettingVector3* origin,
CUserSettingVector3* scale)
{
json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
auto controlpoint_it = data.find ("controlpoint");
@ -74,8 +74,8 @@ CParticle::CParticle (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale):
CUserSettingVector3* origin,
CUserSettingVector3* scale):
CObject (scene, visible, id, std::move(name), Type, origin, scale, glm::vec3 ()),
m_starttime (starttime),
m_maxcount (maxcount)

View File

@ -23,8 +23,8 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale
CUserSettingVector3* origin,
CUserSettingVector3* scale
);
const std::vector<Particles::CEmitter*>& getEmitters () const;
@ -39,8 +39,8 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale
CUserSettingVector3* origin,
CUserSettingVector3* scale
);
void insertControlPoint (Particles::CControlPoint* controlpoint);
void insertEmitter (Particles::CEmitter* emitter);

View File

@ -8,8 +8,8 @@ CSound::CSound (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles) :
CObject (scene, visible, id, std::move(name), Type, origin, scale, angles)
{
@ -21,8 +21,8 @@ WallpaperEngine::Core::CObject* CSound::fromJSON (
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles)
{
auto sound_it = jsonFindRequired (data, "sound", "Sound information not present");

View File

@ -20,8 +20,8 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles
);
@ -34,8 +34,8 @@ namespace WallpaperEngine::Core::Objects
CUserSettingBoolean* visible,
uint32_t id,
std::string name,
const glm::vec3& origin,
const glm::vec3& scale,
CUserSettingVector3* origin,
CUserSettingVector3* scale,
const glm::vec3& angles
);

View File

@ -50,7 +50,7 @@ CUserSettingBoolean* CUserSettingBoolean::fromJSON (nlohmann::json& data)
}
else
{
fprintf (stderr, "Boolean property doesn't have user member, this could mean an scripted value");
fprintf (stderr, "Boolean property doesn't have user member, this could mean an scripted value\n");
}
}
else

View File

@ -47,7 +47,7 @@ CUserSettingFloat* CUserSettingFloat::fromJSON (nlohmann::json& data)
}
else
{
fprintf (stderr, "Boolean property doesn't have user member, this could mean an scripted value");
fprintf (stderr, "Boolean property doesn't have user member, this could mean an scripted value\n");
}
}
else

View File

@ -1,14 +1,15 @@
#include "CUserSettingColor.h"
#include "CUserSettingVector3.h"
#include "WallpaperEngine/Core/Core.h"
#include "WallpaperEngine/Core/Projects/CProperty.h"
#include "WallpaperEngine/Core/Projects/CPropertyColor.h"
#include "WallpaperEngine/Core/Projects/CPropertySlider.h"
using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Core::Projects;
using namespace WallpaperEngine::Core::UserSettings;
CUserSettingColor::CUserSettingColor (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue) :
CUserSettingVector3::CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue) :
CUserSettingValue (Type),
m_hasCondition (hasCondition),
m_hasSource(hasSource),
@ -18,7 +19,7 @@ CUserSettingColor::CUserSettingColor (bool hasCondition, bool hasSource, glm::ve
{
}
CUserSettingColor* CUserSettingColor::fromJSON (nlohmann::json& data)
CUserSettingVector3* CUserSettingVector3::fromJSON (nlohmann::json& data)
{
bool hasCondition = false;
bool hasSource = false;
@ -58,20 +59,20 @@ CUserSettingColor* CUserSettingColor::fromJSON (nlohmann::json& data)
defaultValue = WallpaperEngine::Core::aToColorf (data.get <std::string> ().c_str ());
}
return new CUserSettingColor (hasCondition, hasSource, defaultValue, source, expectedValue);
return new CUserSettingVector3 (hasCondition, hasSource, defaultValue, source, expectedValue);
}
CUserSettingColor* CUserSettingColor::fromScalar (glm::vec3 value)
CUserSettingVector3* CUserSettingVector3::fromScalar (glm::vec3 value)
{
return new CUserSettingColor (false, false, value, "", "");
return new CUserSettingVector3 (false, false, value, "", "");
}
glm::vec3 CUserSettingColor::getDefaultValue ()
glm::vec3 CUserSettingVector3::getDefaultValue ()
{
return this->m_default;
}
glm::vec3 CUserSettingColor::processValue (const std::vector<Projects::CProperty*>& properties)
glm::vec3 CUserSettingVector3::processValue (const std::vector<Projects::CProperty*>& properties)
{
if (this->m_hasSource == false && this->m_hasCondition == false)
return this->getDefaultValue ();
@ -85,6 +86,12 @@ glm::vec3 CUserSettingColor::processValue (const std::vector<Projects::CProperty
{
if (cur->is <CPropertyColor> ())
return cur->as <CPropertyColor> ()->getValue ();
if (cur->is <CPropertySlider> ())
return {
cur->as <CPropertySlider> ()->getValue (),
cur->as <CPropertySlider> ()->getValue (),
cur->as <CPropertySlider> ()->getValue ()
};
throw std::runtime_error ("Property without condition must match type (color)");
}
@ -95,4 +102,4 @@ glm::vec3 CUserSettingColor::processValue (const std::vector<Projects::CProperty
return this->m_default;
}
std::string CUserSettingColor::Type = "color";
std::string CUserSettingVector3::Type = "color";

View File

@ -11,18 +11,18 @@ namespace WallpaperEngine::Core::Projects
namespace WallpaperEngine::Core::UserSettings
{
class CUserSettingColor : public CUserSettingValue
class CUserSettingVector3 : public CUserSettingValue
{
public:
static CUserSettingColor* fromJSON (nlohmann::json& data);
static CUserSettingColor* fromScalar (glm::vec3 value);
static CUserSettingVector3* fromJSON (nlohmann::json& data);
static CUserSettingVector3* fromScalar (glm::vec3 value);
static std::string Type;
glm::vec3 processValue (const std::vector<Projects::CProperty*>& properties);
glm::vec3 getDefaultValue ();
private:
CUserSettingColor (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue);
CUserSettingVector3 (bool hasCondition, bool hasSource, glm::vec3 defaultValue, std::string source, std::string expectedValue);
glm::vec3 m_default;
bool m_hasCondition;