diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cc4e1b..d1388c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,8 @@ add_executable( wallpaperengine/core/objects/image.h wallpaperengine/core/objects/sound.cpp wallpaperengine/core/objects/sound.h + wallpaperengine/core/objects/effect.cpp + wallpaperengine/core/objects/effect.h wallpaperengine/core/objects/images/material.cpp wallpaperengine/core/objects/images/material.h diff --git a/wallpaperengine/core/object.cpp b/wallpaperengine/core/object.cpp index 694553a..0eb2b1f 100644 --- a/wallpaperengine/core/object.cpp +++ b/wallpaperengine/core/object.cpp @@ -32,6 +32,7 @@ object* object::fromJSON (json data) json::const_iterator size_it = data.find ("size"); json::const_iterator angles_it = data.find ("angles"); json::const_iterator name_it = data.find ("name"); + json::const_iterator effects_it = data.find ("effects"); bool visible = true; @@ -96,5 +97,28 @@ object* object::fromJSON (json data) ); } + if (effects_it != data.end () && (*effects_it).is_array () == true && object != nullptr) + { + json::const_iterator cur = (*effects_it).begin (); + json::const_iterator end = (*effects_it).end (); + + for (; cur != end; cur ++) + { + object->insertEffect ( + objects::effect::fromJSON (*cur) + ); + } + } + return object; +} + +std::vector* object::getEffects () +{ + return &this->m_effects; +} + +void object::insertEffect (objects::effect* effect) +{ + this->m_effects.push_back (effect); } \ No newline at end of file diff --git a/wallpaperengine/core/object.h b/wallpaperengine/core/object.h index 001fc7d..e6775b4 100644 --- a/wallpaperengine/core/object.h +++ b/wallpaperengine/core/object.h @@ -3,6 +3,8 @@ #include #include +#include "objects/effect.h" + namespace wp::core { using json = nlohmann::json; @@ -11,6 +13,8 @@ namespace wp::core { public: static object* fromJSON (json data); + + std::vector* getEffects (); protected: object ( bool visible, @@ -20,6 +24,8 @@ namespace wp::core const irr::core::vector3df& scale, const irr::core::vector3df& angles ); + + void insertEffect (objects::effect* effect); private: bool m_visible; irr::u32 m_id; @@ -27,5 +33,7 @@ namespace wp::core irr::core::vector3df m_origin; irr::core::vector3df m_scale; irr::core::vector3df m_angles; + + std::vector m_effects; }; }; diff --git a/wallpaperengine/core/objects/effect.cpp b/wallpaperengine/core/objects/effect.cpp new file mode 100644 index 0000000..1fda148 --- /dev/null +++ b/wallpaperengine/core/objects/effect.cpp @@ -0,0 +1,122 @@ +#include "effect.h" + +#include + +#include "../../fs/utils.h" + +using namespace wp::core::objects; + +effect::effect ( + std::string name, + std::string description, + std::string group, + std::string preview): + m_name (std::move(name)), + m_description (std::move(description)), + m_group (std::move(group)), + m_preview (std::move(preview)) +{ +} + +effect* effect::fromJSON (json data) +{ + json::const_iterator file_it = data.find ("file"); + + if (file_it == data.end ()) + { + throw std::runtime_error ("Object effect must have a file"); + } + + json content = json::parse (wp::fs::utils::loadFullFile ((*file_it).get ().c_str ())); + + json::const_iterator name_it = content.find ("name"); + json::const_iterator description_it = content.find ("description"); + json::const_iterator group_it = content.find ("group"); + json::const_iterator preview_it = content.find ("preview"); + json::const_iterator passes_it = content.find ("passes"); + json::const_iterator dependencies_it = content.find ("dependencies"); + + if (name_it == content.end ()) + { + throw std::runtime_error ("Effect must have a name"); + } + + if (description_it == content.end ()) + { + throw std::runtime_error ("Effect must have a description"); + } + + if (group_it == content.end ()) + { + throw std::runtime_error ("Effect must have a group"); + } + + if (preview_it == content.end ()) + { + throw std::runtime_error ("Effect must have a preview"); + } + + if (passes_it == content.end ()) + { + throw std::runtime_error ("Effect must have a pass list"); + } + + if (dependencies_it == content.end ()) + { + throw std::runtime_error ("Effect must have dependencies"); + } + + effect* effect = new class effect ( + *name_it, + *description_it, + *group_it, + *preview_it + ); + + json::const_iterator cur = (*passes_it).begin (); + json::const_iterator end = (*passes_it).end (); + + for (; cur != end; cur ++) + { + json::const_iterator materialfile = (*cur).find ("material"); + + if (materialfile == (*cur).end ()) + { + throw std::runtime_error ("Effect pass must have a material file"); + } + + effect->insertMaterial ( + images::material::fromFile ((*materialfile).get ().c_str ()) + ); + } + + cur = (*dependencies_it).begin (); + end = (*dependencies_it).end (); + + for (; cur != end; cur ++) + { + effect->insertDependency (*cur); + } + + return effect; +} + +std::vector* effect::getDependencies () +{ + return &this->m_dependencies; +} + +std::vector* effect::getMaterials () +{ + return &this->m_materials; +} + +void effect::insertDependency (const std::string& dep) +{ + this->m_dependencies.push_back (dep); +} + +void effect::insertMaterial (images::material* material) +{ + this->m_materials.push_back (material); +} \ No newline at end of file diff --git a/wallpaperengine/core/objects/effect.h b/wallpaperengine/core/objects/effect.h new file mode 100644 index 0000000..141d1ce --- /dev/null +++ b/wallpaperengine/core/objects/effect.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include + +#include "images/material.h" + +namespace wp::core::objects +{ + using json = nlohmann::json; + + class effect + { + public: + effect ( + std::string name, + std::string description, + std::string group, + std::string preview + ); + + static effect* fromJSON (json data); + + std::vector* getDependencies (); + std::vector* getMaterials (); + protected: + void insertDependency (const std::string& dep); + void insertMaterial (images::material* material); + private: + std::string m_name; + std::string m_description; + std::string m_group; + std::string m_preview; + + std::vector m_dependencies; + std::vector m_materials; + }; +} diff --git a/wallpaperengine/core/objects/images/material.cpp b/wallpaperengine/core/objects/images/material.cpp index c17bf0f..d78e935 100644 --- a/wallpaperengine/core/objects/images/material.cpp +++ b/wallpaperengine/core/objects/images/material.cpp @@ -13,11 +13,16 @@ material::material () material* material::fromFile (irr::io::path filename) { - json content = json::parse (wp::fs::utils::loadFullFile (filename)); + return fromJSON ( + json::parse (wp::fs::utils::loadFullFile (filename)) + ); +} - json::const_iterator passes_it = content.find ("passes"); +material* material::fromJSON (json data) +{ + json::const_iterator passes_it = data.find ("passes"); - if (passes_it == content.end ()) + if (passes_it == data.end ()) { throw std::runtime_error ("Material must have at least one pass"); } diff --git a/wallpaperengine/core/objects/images/material.h b/wallpaperengine/core/objects/images/material.h index 00b513c..1b8dc64 100644 --- a/wallpaperengine/core/objects/images/material.h +++ b/wallpaperengine/core/objects/images/material.h @@ -13,6 +13,7 @@ namespace wp::core::objects::images { public: static material* fromFile (irr::io::path filename); + static material* fromJSON (json data); void insertPass (materials::passes* mass); diff --git a/wallpaperengine/core/objects/images/materials/passes.cpp b/wallpaperengine/core/objects/images/materials/passes.cpp index 42bf010..f55311c 100644 --- a/wallpaperengine/core/objects/images/materials/passes.cpp +++ b/wallpaperengine/core/objects/images/materials/passes.cpp @@ -80,7 +80,14 @@ passes* passes::fromJSON (json data) for (;cur != end; cur ++) { - pass->insertTexture (*cur); + if ((*cur).is_null () == true) + { + pass->insertTexture (""); + } + else + { + pass->insertTexture (*cur); + } } return pass; diff --git a/wallpaperengine/core/scene.h b/wallpaperengine/core/scene.h index 668053d..fa7b269 100644 --- a/wallpaperengine/core/scene.h +++ b/wallpaperengine/core/scene.h @@ -24,7 +24,6 @@ namespace wp::core project* getProject (); std::vector* getObjects (); - const irr::video::SColorf &getAmbientColor() const; bool isBloom() const; irr::f64 getBloomStrength() const;