Преглед на файлове

+ Added parsing of general section of the JSON for the scene and the needed getters for the scene

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez преди 7 години
родител
ревизия
7d2c4a76ed

+ 16 - 0
wallpaperengine/core.cpp

@@ -26,4 +26,20 @@ irr::core::vector3df wp::core::ato3vf (const std::string& str)
 irr::core::vector2df wp::core::ato2vf (const std::string& str)
 {
     return wp::core::ato2vf (str.c_str ());
+}
+
+irr::video::SColorf wp::core::atoSColorf (const char *str)
+{
+    irr::core::vector3df vector = wp::core::ato3vf (str);
+
+    return irr::video::SColorf (
+        vector.X,
+        vector.Y,
+        vector.Z
+    );
+}
+
+irr::video::SColorf wp::core::atoSColorf (const std::string& str)
+{
+    return wp::core::atoSColorf (str.c_str ());
 }

+ 3 - 0
wallpaperengine/core.h

@@ -11,4 +11,7 @@ namespace wp::core
 
     irr::core::vector3df ato3vf (const std::string& str);
     irr::core::vector2df ato2vf (const std::string& str);
+
+    irr::video::SColorf atoSColorf (const char *str);
+    irr::video::SColorf atoSColorf (const std::string& str);
 };

+ 252 - 6
wallpaperengine/core/scene.cpp

@@ -1,29 +1,190 @@
 #include "scene.h"
 #include "project.h"
 
+#include "../core.h"
 #include "../fs/utils.h"
 
 using namespace wp::core;
 
-scene::scene (scenes::camera* camera) :
-    m_camera (camera)
+scene::scene (
+        scenes::camera* camera,
+        irr::video::SColorf ambientColor,
+        bool bloom,
+        irr::f64 bloomStrength,
+        irr::f64 bloomThreshold,
+        bool cameraFade,
+        bool cameraParallax,
+        irr::f64 cameraParallaxAmount,
+        irr::f64 cameraParallaxDelay,
+        irr::f64 cameraParallaxMouseInfluence,
+        bool cameraPreview,
+        bool cameraShake,
+        irr::f64 cameraShakeAmplitude,
+        irr::f64 cameraShakeRoughness,
+        irr::f64 cameraShakeSpeed,
+        irr::video::SColorf clearColor,
+        scenes::projection* orthogonalProjection,
+        irr::video::SColorf skylightColor) :
+    m_camera (camera),
+    m_ambientColor (ambientColor),
+    m_bloom (bloom),
+    m_bloomStrength (bloomStrength),
+    m_bloomThreshold (bloomThreshold),
+    m_cameraFade (cameraFade),
+    m_cameraParallax (cameraParallax),
+    m_cameraParallaxAmount (cameraParallaxAmount),
+    m_cameraParallaxDelay (cameraParallaxDelay),
+    m_cameraParallaxMouseInfluence (cameraParallaxMouseInfluence),
+    m_cameraPreview (cameraPreview),
+    m_cameraShake (cameraShake),
+    m_cameraShakeAmplitude (cameraShakeAmplitude),
+    m_cameraShakeRoughness (cameraShakeRoughness),
+    m_cameraShakeSpeed (cameraShakeSpeed),
+    m_clearColor (clearColor),
+    m_orthogonalProjection (orthogonalProjection),
+    m_skylightColor (skylightColor)
 {
-
 }
 
-scene* scene::fromFile (irr::io::path filename)
+scene* scene::fromFile (const irr::io::path& filename)
 {
     json content = json::parse (wp::fs::utils::loadFullFile (filename));
 
     json::const_iterator camera_it = content.find ("camera");
+    json::const_iterator general_it = content.find ("general");
 
     if (camera_it == content.end ())
     {
         throw std::runtime_error ("Scenes must have a defined camera");
     }
 
+    if (general_it == content.end ())
+    {
+        throw std::runtime_error ("Scenes must have a general section");
+    }
+
+    json::const_iterator ambientcolor_it = (*general_it).find ("ambientcolor");
+    json::const_iterator bloom_it = (*general_it).find ("bloom");
+    json::const_iterator bloomstrength_it = (*general_it).find ("bloomstrength");
+    json::const_iterator bloomthreshold_it = (*general_it).find ("bloomthreshold");
+    json::const_iterator camerafade_it = (*general_it).find ("camerafade");
+    json::const_iterator cameraparallax_it = (*general_it).find ("cameraparallax");
+    json::const_iterator cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount");
+    json::const_iterator cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay");
+    json::const_iterator cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence");
+    json::const_iterator camerapreview_it = (*general_it).find ("camerapreview");
+    json::const_iterator camerashake_it = (*general_it).find ("camerashake");
+    json::const_iterator camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude");
+    json::const_iterator camerashakeroughness_it = (*general_it).find ("camerashakeroughness");
+    json::const_iterator camerashakespeed_it = (*general_it).find ("camerashakespeed");
+    json::const_iterator clearcolor_it = (*general_it).find ("clearcolor");
+    json::const_iterator orthogonalprojection_it = (*general_it).find ("orthogonalprojection");
+    json::const_iterator skylightcolor_it = (*general_it).find ("skylightcolor");
+
+    if (ambientcolor_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have ambient color");
+    }
+
+    if (bloom_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have bloom flag");
+    }
+
+    if (bloomstrength_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have bloom strength");
+    }
+
+    if (bloomthreshold_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have bloom threshold");
+    }
+
+    if (camerafade_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera fade");
+    }
+
+    if (cameraparallax_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera parallax");
+    }
+
+    if (cameraparallaxamount_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera parallax amount");
+    }
+
+    if (cameraparallaxdelay_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera parallax delay");
+    }
+
+    if (cameraparallaxmouseinfluence_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera parallax mouse influence");
+    }
+
+    if (camerapreview_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera preview");
+    }
+
+    if (camerashake_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera shake");
+    }
+
+    if (camerashakeamplitude_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera shake amplitude");
+    }
+
+    if (camerashakeroughness_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera shake roughness");
+    }
+
+    if (camerashakespeed_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have camera shake speed");
+    }
+
+    if (clearcolor_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have clear color");
+    }
+
+    if (orthogonalprojection_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have orthogonal projection info");
+    }
+
+    if (skylightcolor_it == (*general_it).end ())
+    {
+        throw std::runtime_error ("General section must have skylight color");
+    }
+
     return new scene (
-        scenes::camera::fromJSON (*camera_it)
+        scenes::camera::fromJSON (*camera_it),
+        wp::core::atoSColorf (*ambientcolor_it),
+        *bloom_it,
+        *bloomstrength_it,
+        *bloomthreshold_it,
+        *camerafade_it,
+        *cameraparallax_it,
+        *cameraparallaxamount_it,
+        *cameraparallaxdelay_it,
+        *cameraparallaxmouseinfluence_it,
+        *camerapreview_it,
+        *camerashake_it,
+        *camerashakeamplitude_it,
+        *camerashakeroughness_it,
+        *camerashakespeed_it,
+        wp::core::atoSColorf (*clearcolor_it),
+        scenes::projection::fromJSON (*orthogonalprojection_it),
+        wp::core::atoSColorf (*skylightcolor_it)
     );
 }
 
@@ -40,4 +201,89 @@ void scene::setProject (project* project)
 scenes::camera* scene::getCamera ()
 {
     return this->m_camera;
-}
+}
+
+const irr::video::SColorf &scene::getAmbientColor() const
+{
+    return this->m_ambientColor;
+}
+
+bool scene::isBloom () const
+{
+    return this->m_bloom;
+}
+
+irr::f64 scene::getBloomStrength () const
+{
+    return this->m_bloomStrength;
+}
+
+irr::f64 scene::getBloomThreshold () const
+{
+    return this->m_bloomThreshold;
+}
+
+bool scene::isCameraFade () const
+{
+    return this->m_cameraFade;
+}
+
+bool scene::isCameraParallax () const
+{
+    return this->m_cameraParallax;
+}
+
+irr::f64 scene::getCameraParallaxAmount () const
+{
+    return this->m_cameraParallaxAmount;
+}
+
+irr::f64 scene::getCameraParallaxDelay () const
+{
+    return this->m_cameraParallaxDelay;
+}
+
+irr::f64 scene::getCameraParallaxMouseInfluence () const
+{
+    return this->m_cameraParallaxMouseInfluence;
+}
+
+bool scene::isCameraPreview () const
+{
+    return this->m_cameraPreview;
+}
+
+bool scene::isCameraShake () const
+{
+    return this->m_cameraShake;
+}
+
+irr::f64 scene::getCameraShakeAmplitude () const
+{
+    return this->m_cameraShakeAmplitude;
+}
+
+irr::f64 scene::getCameraShakeRoughness () const
+{
+    return this->m_cameraShakeRoughness;
+}
+
+irr::f64 scene::getCameraShakeSpeed () const
+{
+    return this->m_cameraShakeSpeed;
+}
+
+const irr::video::SColorf &scene::getClearColor () const
+{
+    return this->m_clearColor;
+}
+
+scenes::projection *scene::getOrthogonalProjection () const
+{
+    return this->m_orthogonalProjection;
+}
+
+const irr::video::SColorf &scene::getSkylightColor () const
+{
+    return this->m_skylightColor;
+}

+ 63 - 2
wallpaperengine/core/scene.h

@@ -4,7 +4,9 @@
 #include <nlohmann/json.hpp>
 
 #include "project.h"
+
 #include "scenes/camera.h"
+#include "scenes/projection.h"
 
 namespace wp::core
 {
@@ -15,18 +17,77 @@ namespace wp::core
     class scene
     {
     public:
-        static scene* fromFile (irr::io::path filename);
+        static scene* fromFile (const irr::io::path& filename);
 
         project* getProject ();
+
+
+        const irr::video::SColorf &getAmbientColor() const;
+        bool isBloom() const;
+        irr::f64 getBloomStrength() const;
+        irr::f64 getBloomThreshold() const;
+        bool isCameraFade() const;
+        bool isCameraParallax() const;
+        irr::f64 getCameraParallaxAmount() const;
+        irr::f64 getCameraParallaxDelay() const;
+        irr::f64 getCameraParallaxMouseInfluence() const;
+        bool isCameraPreview() const;
+        bool isCameraShake() const;
+        irr::f64 getCameraShakeAmplitude() const;
+        irr::f64 getCameraShakeRoughness() const;
+        irr::f64 getCameraShakeSpeed() const;
+        const irr::video::SColorf &getClearColor() const;
+        scenes::projection *getOrthogonalProjection() const;
+        const irr::video::SColorf &getSkylightColor() const;
+
     protected:
         friend class project;
 
         void setProject (project* project);
         scenes::camera* getCamera ();
 
-        scene (scenes::camera* camera);
+        scene (
+            scenes::camera* camera,
+            irr::video::SColorf ambientColor,
+            bool bloom,
+            irr::f64 bloomStrength,
+            irr::f64 bloomThreshold,
+            bool cameraFade,
+            bool cameraParallax,
+            irr::f64 cameraParallaxAmount,
+            irr::f64 cameraParallaxDelay,
+            irr::f64 cameraParallaxMouseInfluence,
+            bool cameraPreview,
+            bool cameraShake,
+            irr::f64 cameraShakeAmplitude,
+            irr::f64 cameraShakeRoughness,
+            irr::f64 cameraShakeSpeed,
+            irr::video::SColorf clearColor,
+            scenes::projection* orthogonalProjection,
+            irr::video::SColorf skylightColor
+        );
+
     private:
         project* m_project;
         scenes::camera* m_camera;
+
+        // data from general section on the json
+        irr::video::SColorf m_ambientColor;
+        bool m_bloom;
+        irr::f64 m_bloomStrength;
+        irr::f64 m_bloomThreshold;
+        bool m_cameraFade;
+        bool m_cameraParallax;
+        irr::f64 m_cameraParallaxAmount;
+        irr::f64 m_cameraParallaxDelay;
+        irr::f64 m_cameraParallaxMouseInfluence;
+        bool m_cameraPreview;
+        bool m_cameraShake;
+        irr::f64 m_cameraShakeAmplitude;
+        irr::f64 m_cameraShakeRoughness;
+        irr::f64 m_cameraShakeSpeed;
+        irr::video::SColorf m_clearColor;
+        scenes::projection* m_orthogonalProjection;
+        irr::video::SColorf m_skylightColor;
     };
 };

+ 41 - 0
wallpaperengine/core/scenes/projection.cpp

@@ -0,0 +1,41 @@
+#include "projection.h"
+#include "../../core.h"
+
+using namespace wp::core::scenes;
+
+projection::projection (irr::u32 width, irr::u32 height) :
+    m_width (width),
+    m_height (height)
+{
+}
+
+irr::u32 projection::getWidth ()
+{
+    return this->m_width;
+}
+
+irr::u32 projection::getHeight ()
+{
+    return this->m_height;
+}
+
+projection* projection::fromJSON (json data)
+{
+    json::const_iterator width_it = data.find ("width");
+    json::const_iterator height_it = data.find ("height");
+
+    if (width_it == data.end ())
+    {
+        throw std::runtime_error ("Projection must have width");
+    }
+
+    if (height_it == data.end ())
+    {
+        throw std::runtime_error ("Projection must have height");
+    }
+
+    return new projection (
+        *width_it,
+        *height_it
+    );
+}

+ 23 - 0
wallpaperengine/core/scenes/projection.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include <nlohmann/json.hpp>
+#include <irrlicht/irrlicht.h>
+
+namespace wp::core::scenes
+{
+    using json = nlohmann::json;
+
+    class projection
+    {
+    public:
+        static projection* fromJSON (json data);
+
+        irr::u32 getWidth ();
+        irr::u32 getHeight ();
+    protected:
+        projection (irr::u32 width, irr::u32 height);
+    private:
+        irr::u32 m_width;
+        irr::u32 m_height;
+    };
+};