linux-wallpaperengine/wallpaperengine/core/objects/effect.cpp
Alexis Maiquez e80ce94331 + Support for null textures in material passes
+ Basic parsing for object's effects (missing passes specified in the scene.json)

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
2019-08-14 10:42:10 +02:00

122 lines
2.9 KiB
C++

#include "effect.h"
#include <utility>
#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 <std::string> ().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 <std::string> ().c_str ())
);
}
cur = (*dependencies_it).begin ();
end = (*dependencies_it).end ();
for (; cur != end; cur ++)
{
effect->insertDependency (*cur);
}
return effect;
}
std::vector<std::string>* effect::getDependencies ()
{
return &this->m_dependencies;
}
std::vector<images::material*>* 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);
}