diff --git a/src/WallpaperEngine/Core/CObject.cpp b/src/WallpaperEngine/Core/CObject.cpp index 6cf6f88..a0f67af 100644 --- a/src/WallpaperEngine/Core/CObject.cpp +++ b/src/WallpaperEngine/Core/CObject.cpp @@ -5,8 +5,6 @@ #include "WallpaperEngine/Core/Objects/CSound.h" #include "WallpaperEngine/Core/Objects/CParticle.h" -#include "Core.h" - using namespace WallpaperEngine::Core; CObject::CObject ( @@ -29,42 +27,17 @@ CObject::CObject ( CObject* CObject::fromJSON (json data) { - auto id_it = data.find ("id"); + auto id_it = jsonFindRequired (data, "id", "Objects must have id"); auto visible_it = data.find ("visible"); - auto origin_it = data.find ("origin"); - auto scale_it = data.find ("scale"); - auto angles_it = data.find ("angles"); - auto name_it = data.find ("name"); + auto origin_it = jsonFindRequired (data, "origin", "Objects must have origin point"); + auto scale_it = jsonFindRequired (data, "scale", "Objects must have scale"); + auto angles_it = jsonFindRequired (data, "angles", "Objects must have angles"); + auto name_it = jsonFindRequired (data, "name", "Objects must have name"); auto effects_it = data.find ("effects"); auto dependencies_it = data.find ("dependencies"); bool visible = true; - if (id_it == data.end ()) - { - throw std::runtime_error ("Objects must have id"); - } - - if (origin_it == data.end ()) - { - throw std::runtime_error ("Objects must have origin point"); - } - - if (scale_it == data.end ()) - { - throw std::runtime_error ("Objects must have scale"); - } - - if (angles_it == data.end ()) - { - throw std::runtime_error ("Objects must have angles"); - } - - if (name_it == data.end ()) - { - throw std::runtime_error ("Objects must have name"); - } - // visibility is optional if (visible_it != data.end ()) { diff --git a/src/WallpaperEngine/Core/CObject.h b/src/WallpaperEngine/Core/CObject.h index 67fb78a..4e036b9 100644 --- a/src/WallpaperEngine/Core/CObject.h +++ b/src/WallpaperEngine/Core/CObject.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "Core.h" + #include "WallpaperEngine/Core/Objects/CEffect.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/CProject.cpp b/src/WallpaperEngine/Core/CProject.cpp index af8f6e0..0fb84f7 100644 --- a/src/WallpaperEngine/Core/CProject.cpp +++ b/src/WallpaperEngine/Core/CProject.cpp @@ -16,26 +16,11 @@ CProject* CProject::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto title = content.find ("title"); - auto type = content.find ("type"); - auto file = content.find ("file"); + auto title = jsonFindRequired (content, "title", "Project title missing"); + auto type = jsonFindRequired (content, "type", "Project type missing"); + auto file = jsonFindRequired (content, "file", "Project's main file missing"); auto general = content.find ("general"); - if (title == content.end ()) - { - throw std::runtime_error ("Project title missing"); - } - - if (type == content.end ()) - { - throw std::runtime_error ("Project type missing"); - } - - if (file == content.end ()) - { - throw std::runtime_error ("Project's main file missing"); - } - CProject* project = new CProject ( *title, *type, diff --git a/src/WallpaperEngine/Core/CProject.h b/src/WallpaperEngine/Core/CProject.h index 570b50b..aee6396 100644 --- a/src/WallpaperEngine/Core/CProject.h +++ b/src/WallpaperEngine/Core/CProject.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include "CScene.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Projects/CProperty.h" namespace WallpaperEngine::Core diff --git a/src/WallpaperEngine/Core/CScene.cpp b/src/WallpaperEngine/Core/CScene.cpp index c7112d4..b1339ff 100644 --- a/src/WallpaperEngine/Core/CScene.cpp +++ b/src/WallpaperEngine/Core/CScene.cpp @@ -1,7 +1,6 @@ #include "CScene.h" #include "CProject.h" -#include "Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core; @@ -50,127 +49,27 @@ CScene* CScene::fromFile (const irr::io::path& filename) { json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); - auto camera_it = content.find ("camera"); - auto general_it = content.find ("general"); - auto objects_it = content.find ("objects"); + auto camera_it = jsonFindRequired (content, "camera", "Scenes must have a defined camera"); + auto general_it = jsonFindRequired (content, "general", "Scenes must have a general section"); + auto objects_it = jsonFindRequired (content, "objects", "Scenes must have a list of objects to display"); - 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"); - } - - if (objects_it == content.end ()) - { - throw std::runtime_error ("Scenes must have a list of objects to display"); - } - - auto ambientcolor_it = (*general_it).find ("ambientcolor"); - auto bloom_it = (*general_it).find ("bloom"); - auto bloomstrength_it = (*general_it).find ("bloomstrength"); - auto bloomthreshold_it = (*general_it).find ("bloomthreshold"); - auto camerafade_it = (*general_it).find ("camerafade"); - auto cameraparallax_it = (*general_it).find ("cameraparallax"); - auto cameraparallaxamount_it = (*general_it).find ("cameraparallaxamount"); - auto cameraparallaxdelay_it = (*general_it).find ("cameraparallaxdelay"); - auto cameraparallaxmouseinfluence_it = (*general_it).find ("cameraparallaxmouseinfluence"); - auto camerapreview_it = (*general_it).find ("camerapreview"); - auto camerashake_it = (*general_it).find ("camerashake"); - auto camerashakeamplitude_it = (*general_it).find ("camerashakeamplitude"); - auto camerashakeroughness_it = (*general_it).find ("camerashakeroughness"); - auto camerashakespeed_it = (*general_it).find ("camerashakespeed"); - auto clearcolor_it = (*general_it).find ("clearcolor"); - auto orthogonalprojection_it = (*general_it).find ("orthogonalprojection"); - auto 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"); - } + auto ambientcolor_it = jsonFindRequired (*general_it, "ambientcolor", "General section must have ambient color"); + auto bloom_it = jsonFindRequired (*general_it, "bloom", "General section must have bloom flag"); + auto bloomstrength_it = jsonFindRequired (*general_it, "bloomstrength", "General section must have bloom strength"); + auto bloomthreshold_it = jsonFindRequired (*general_it, "bloomthreshold", "General section must have bloom threshold"); + auto camerafade_it = jsonFindRequired (*general_it, "camerafade", "General section must have camera fade"); + auto cameraparallax_it = jsonFindRequired (*general_it, "cameraparallax", "General section must have camera parallax"); + auto cameraparallaxamount_it = jsonFindRequired (*general_it, "cameraparallaxamount", "General section must have camera parallax amount"); + auto cameraparallaxdelay_it = jsonFindRequired (*general_it, "cameraparallaxdelay", "General section must have camera parallax delay"); + auto cameraparallaxmouseinfluence_it = jsonFindRequired (*general_it, "cameraparallaxmouseinfluence", "General section must have camera parallax mouse influence"); + auto camerapreview_it = jsonFindRequired (*general_it, "camerapreview", "General section must have camera preview"); + auto camerashake_it = jsonFindRequired (*general_it, "camerashake", "General section must have camera shake"); + auto camerashakeamplitude_it = jsonFindRequired (*general_it, "camerashakeamplitude", "General section must have camera shake amplitude"); + auto camerashakeroughness_it = jsonFindRequired (*general_it, "camerashakeroughness", "General section must have camera shake roughness"); + auto camerashakespeed_it = jsonFindRequired (*general_it, "camerashakespeed", "General section must have camera shake speed"); + auto clearcolor_it = jsonFindRequired (*general_it, "clearcolor", "General section must have clear color"); + auto orthogonalprojection_it = jsonFindRequired (*general_it, "orthogonalprojection", "General section must have orthogonal projection info"); + auto skylightcolor_it = jsonFindRequired (*general_it, "skylightcolor", "General section must have skylight color"); CScene* scene = new CScene ( Scenes::CCamera::fromJSON (*camera_it), diff --git a/src/WallpaperEngine/Core/CScene.h b/src/WallpaperEngine/Core/CScene.h index 842c499..c9a828c 100644 --- a/src/WallpaperEngine/Core/CScene.h +++ b/src/WallpaperEngine/Core/CScene.h @@ -1,11 +1,12 @@ #pragma once #include -#include #include "CProject.h" #include "CObject.h" +#include "Core.h" + #include "WallpaperEngine/Core/Scenes/CCamera.h" #include "WallpaperEngine/Core/Scenes/CProjection.h" diff --git a/src/WallpaperEngine/Core/Core.cpp b/src/WallpaperEngine/Core/Core.cpp index 90d00ea..2867315 100644 --- a/src/WallpaperEngine/Core/Core.cpp +++ b/src/WallpaperEngine/Core/Core.cpp @@ -58,4 +58,14 @@ irr::video::SColor Core::atoSColor (const char *str) irr::video::SColor Core::atoSColor (const std::string& str) { return Core::atoSColor (str.c_str ()); -} \ No newline at end of file +} + +nlohmann::detail::iter_impl Core::jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg) +{ + auto value = data.find (key); + if (value == data.end ()) + { + throw std::runtime_error (notFoundMsg); + } + return value; +} diff --git a/src/WallpaperEngine/Core/Core.h b/src/WallpaperEngine/Core/Core.h index 1918580..7cd9612 100644 --- a/src/WallpaperEngine/Core/Core.h +++ b/src/WallpaperEngine/Core/Core.h @@ -2,6 +2,7 @@ #include #include +#include namespace WallpaperEngine::Core { @@ -16,4 +17,6 @@ namespace WallpaperEngine::Core irr::video::SColor atoSColor (const char *str); irr::video::SColor atoSColor (const std::string& str); + + nlohmann::json::iterator jsonFindRequired (nlohmann::json& data, const char *key, const char *notFoundMsg); }; diff --git a/src/WallpaperEngine/Core/Objects/CEffect.cpp b/src/WallpaperEngine/Core/Objects/CEffect.cpp index 8a63905..f28a5d1 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.cpp +++ b/src/WallpaperEngine/Core/Objects/CEffect.cpp @@ -2,7 +2,6 @@ #include -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/CImage.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstantFloat.h" @@ -30,54 +29,19 @@ CEffect::CEffect ( CEffect* CEffect::fromJSON (json data, Core::CObject* object) { - auto file_it = data.find ("file"); + auto file_it = jsonFindRequired (data, "file", "Object effect must have a file"); auto effectpasses_it = data.find ("passes"); - if (file_it == data.end ()) - { - throw std::runtime_error ("Object effect must have a file"); - } - json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get ().c_str ())); - auto name_it = content.find ("name"); - auto description_it = content.find ("description"); - auto group_it = content.find ("group"); - auto preview_it = content.find ("preview"); - auto passes_it = content.find ("passes"); - auto dependencies_it = content.find ("dependencies"); + auto name_it = jsonFindRequired (content, "name", "Effect must have a name"); + auto description_it = jsonFindRequired (content, "description", "Effect must have a description"); + auto group_it = jsonFindRequired (content, "group", "Effect must have a group"); + auto preview_it = jsonFindRequired (content, "preview", "Effect must have a preview"); + auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list"); + auto dependencies_it = jsonFindRequired (content, "dependencies", ""); auto fbos_it = content.find ("fbos"); - 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"); - } - CEffect* effect = new CEffect ( *name_it, *description_it, diff --git a/src/WallpaperEngine/Core/Objects/CEffect.h b/src/WallpaperEngine/Core/Objects/CEffect.h index c05db72..61ce37e 100644 --- a/src/WallpaperEngine/Core/Objects/CEffect.h +++ b/src/WallpaperEngine/Core/Objects/CEffect.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Effects/CFBO.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" #include "WallpaperEngine/Core/CObject.h" diff --git a/src/WallpaperEngine/Core/Objects/CImage.cpp b/src/WallpaperEngine/Core/Objects/CImage.cpp index 4ca86b0..0fcbd5a 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.cpp +++ b/src/WallpaperEngine/Core/Objects/CImage.cpp @@ -1,7 +1,6 @@ #include "CImage.h" #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" -#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h" using namespace WallpaperEngine::Core::Objects; @@ -31,21 +30,11 @@ WallpaperEngine::Core::CObject* CImage::fromJSON ( const irr::core::vector3df& angles) { auto image_it = data.find ("image"); - auto size_it = data.find ("size"); - - if (size_it == data.end ()) - { - throw std::runtime_error ("Images must have size"); - } + auto size_it = jsonFindRequired (data, "size", "Images must have size"); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*image_it).get ().c_str ())); - auto material_it = content.find ("material"); - - if (material_it == content.end ()) - { - throw std::runtime_error ("Image must have a material"); - } + auto material_it = jsonFindRequired (content, "material", "Image must have a material"); return new CImage ( Images::CMaterial::fromFile ((*material_it).get ().c_str ()), diff --git a/src/WallpaperEngine/Core/Objects/CImage.h b/src/WallpaperEngine/Core/Objects/CImage.h index 6f5c88d..477f7cf 100644 --- a/src/WallpaperEngine/Core/Objects/CImage.h +++ b/src/WallpaperEngine/Core/Objects/CImage.h @@ -1,10 +1,10 @@ #pragma once -#include #include #include "WallpaperEngine/Core/Objects/Images/CMaterial.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CParticle.cpp b/src/WallpaperEngine/Core/Objects/CParticle.cpp index df0b5ed..66ab725 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.cpp +++ b/src/WallpaperEngine/Core/Objects/CParticle.cpp @@ -14,30 +14,10 @@ CParticle* CParticle::fromFile ( { json data = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename)); auto controlpoint_it = data.find ("controlpoint"); - auto starttime_it = data.find ("starttime"); - auto maxcount_it = data.find ("maxcount"); - auto emitter_it = data.find ("emitter"); - auto initializer_it = data.find ("initializer"); - - if (starttime_it == data.end ()) - { - throw std::runtime_error ("Particles must have start time"); - } - - if (maxcount_it == data.end ()) - { - throw std::runtime_error ("Particles must have maximum count"); - } - - if (emitter_it == data.end ()) - { - throw std::runtime_error ("Particles must have emitters"); - } - - if (initializer_it == data.end ()) - { - throw std::runtime_error ("Particles must have initializers"); - } + auto starttime_it = jsonFindRequired (data, "starttime", "Particles must have start time"); + auto maxcount_it = jsonFindRequired (data, "maxcount", "Particles must have maximum count"); + auto emitter_it = jsonFindRequired (data, "emitter", "Particles must have emitters"); + auto initializer_it = jsonFindRequired (data, "initializer", "Particles must have initializers"); CParticle* particle = new CParticle ( *starttime_it, diff --git a/src/WallpaperEngine/Core/Objects/CParticle.h b/src/WallpaperEngine/Core/Objects/CParticle.h index 34bf6ac..78605d3 100644 --- a/src/WallpaperEngine/Core/Objects/CParticle.h +++ b/src/WallpaperEngine/Core/Objects/CParticle.h @@ -1,12 +1,12 @@ #pragma once #include -#include #include "WallpaperEngine/Core/Objects/Particles/CControlPoint.h" #include "WallpaperEngine/Core/Objects/Particles/CEmitter.h" #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/CSound.cpp b/src/WallpaperEngine/Core/Objects/CSound.cpp index 6f6f6f4..e0b0f7b 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.cpp +++ b/src/WallpaperEngine/Core/Objects/CSound.cpp @@ -25,12 +25,7 @@ WallpaperEngine::Core::CObject* CSound::fromJSON ( const irr::core::vector3df& scale, const irr::core::vector3df& angles) { - auto sound_it = data.find ("sound"); - - if (sound_it == data.end ()) - { - throw std::runtime_error ("Sound information not present"); - } + auto sound_it = jsonFindRequired (data, "sound", "Sound information not present"); if ((*sound_it).is_array () == false) { diff --git a/src/WallpaperEngine/Core/Objects/CSound.h b/src/WallpaperEngine/Core/Objects/CSound.h index a9c4173..1d220dd 100644 --- a/src/WallpaperEngine/Core/Objects/CSound.h +++ b/src/WallpaperEngine/Core/Objects/CSound.h @@ -1,8 +1,8 @@ #pragma once #include -#include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/CObject.h" namespace WallpaperEngine::Core::Objects diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp index c890115..090cf8a 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.cpp @@ -12,18 +12,8 @@ CBind::CBind (std::string name, irr::u32 index) : CBind* CBind::fromJSON (json data) { - auto name_it = data.find ("name"); - auto index_it = data.find ("index"); - - if (name_it == data.end ()) - { - throw std::runtime_error ("bind must have texture name"); - } - - if (index_it == data.end ()) - { - throw std::runtime_error ("bind must have index"); - } + auto name_it = jsonFindRequired (data, "name", "bind must have texture name"); + auto index_it = jsonFindRequired (data, "index", "bind must have index"); return new CBind (*name_it, *index_it); } diff --git a/src/WallpaperEngine/Core/Objects/Effects/CBind.h b/src/WallpaperEngine/Core/Objects/Effects/CBind.h index a4cbeb1..1b946d1 100644 --- a/src/WallpaperEngine/Core/Objects/Effects/CBind.h +++ b/src/WallpaperEngine/Core/Objects/Effects/CBind.h @@ -3,7 +3,8 @@ #include #include -#include + +#include "WallpaperEngine/Core/Core.h" namespace WallpaperEngine::Core::Objects::Effects { diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp index af269b2..069b5d5 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.cpp @@ -37,12 +37,7 @@ CMaterial* CMaterial::fromJSON (json data, const std::string& target) CMaterial* CMaterial::fromJSON (json data) { - auto passes_it = data.find ("passes"); - - if (passes_it == data.end ()) - { - throw std::runtime_error ("Material must have at least one pass"); - } + auto passes_it = jsonFindRequired (data, "passes", "Material must have at least one pass"); CMaterial* material = new CMaterial (); diff --git a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h index 0fe2e54..6bde2cf 100644 --- a/src/WallpaperEngine/Core/Objects/Images/CMaterial.h +++ b/src/WallpaperEngine/Core/Objects/Images/CMaterial.h @@ -1,11 +1,12 @@ #pragma once #include -#include #include "WallpaperEngine/Core/Objects/Images/Materials/CPass.h" #include "WallpaperEngine/Core/Objects/Effects/CBind.h" +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Images { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp index 8db6d1a..1e6fa6b 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp @@ -14,39 +14,14 @@ CPass::CPass (std::string blending, std::string cullmode, std::string depthtest, CPass* CPass::fromJSON (json data) { - auto blending_it = data.find ("blending"); - auto cullmode_it = data.find ("cullmode"); - auto depthtest_it = data.find ("depthtest"); - auto depthwrite_it = data.find ("depthwrite"); - auto shader_it = data.find ("shader"); + auto blending_it = jsonFindRequired (data, "blending", "Material pass must have blending specified"); + auto cullmode_it = jsonFindRequired (data, "cullmode", "Material pass must have cullmode specified"); + auto depthtest_it = jsonFindRequired (data, "depthtest", "Material pass must have depthtest specified"); + auto depthwrite_it = jsonFindRequired (data, "depthwrite", "Material pass must have depthwrite specified"); + auto shader_it = jsonFindRequired (data, "shader", "Material pass must have shader specified"); auto textures_it = data.find ("textures"); auto combos_it = data.find ("combos"); - if (blending_it == data.end ()) - { - throw std::runtime_error ("Material pass must have blending specified"); - } - - if (cullmode_it == data.end ()) - { - throw std::runtime_error ("Material pass must have cullmode specified"); - } - - if (depthtest_it == data.end ()) - { - throw std::runtime_error ("Material pass must have depthtest specified"); - } - - if (depthwrite_it == data.end ()) - { - throw std::runtime_error ("Material pass must have depthwrite specified"); - } - - if (shader_it == data.end ()) - { - throw std::runtime_error ("Material pass must have shader specified"); - } - if (textures_it != data.end ()) { // TODO: FETCH THIS FROM CImage TO MAKE IT COMPATIBLE WITH OLDER WALLPAPERS diff --git a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h index 517c2cd..9779211 100644 --- a/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h +++ b/src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h" diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp index b89d975..63775db 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.cpp @@ -1,20 +1,13 @@ #include "CControlPoint.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles; CControlPoint* CControlPoint::fromJSON (json data) { auto flags_it = data.find ("flags"); - auto id_it = data.find ("id"); + auto id_it = jsonFindRequired (data, "id", "Particle's control point must have id"); auto offset_it = data.find ("offset"); - if (id_it == data.end ()) - { - throw std::runtime_error ("Particle's control point must have id"); - } - CControlPoint* controlpoint = new CControlPoint (*id_it, 0); if (offset_it != data.end ()) diff --git a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h index 2a00dd5..a34dcfa 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CControlPoint.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp index 21cccbe..a0e23fc 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.cpp @@ -1,48 +1,16 @@ #include "CEmitter.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles; CEmitter* CEmitter::fromJSON (json data) { - auto directions_it = data.find ("directions"); - auto distancemax_it = data.find ("distancemax"); - auto distancemin_it = data.find ("distancemin"); + auto directions_it = jsonFindRequired (data, "directions", "Particle emitter must have direction specified"); + auto distancemax_it = jsonFindRequired (data, "distancemax", "Particle emitter must have maximum distance"); + auto distancemin_it = jsonFindRequired (data, "distancemin", "Particle emitter must have minimum distance"); auto id_it = data.find ("id"); - auto name_it = data.find ("name"); - auto origin_it = data.find ("origin"); - auto rate_it = data.find ("rate"); - - if (directions_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have direction specified"); - } - - if (distancemax_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have maximum distance"); - } - - if (distancemin_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have minimum distance"); - } - - if (name_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have a name"); - } - - if (origin_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have an origin"); - } - - if (rate_it == data.end ()) - { - throw std::runtime_error ("Particle emitter must have a rate"); - } + auto name_it = jsonFindRequired (data, "name", "Particle emitter must have a name"); + auto origin_it = jsonFindRequired (data, "origin", "Particle emitter must have an origin"); + auto rate_it = jsonFindRequired (data, "rate", "Particle emitter must have a rate"); return new CEmitter ( WallpaperEngine::Core::ato3vf (*directions_it), diff --git a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h index f574b13..1959812 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CEmitter.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp index 39bf0f0..8cab735 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.cpp @@ -13,14 +13,9 @@ using namespace WallpaperEngine::Core::Objects::Particles; CInitializer* CInitializer::fromJSON (json data) { auto id_it = data.find ("id"); - auto name_it = data.find ("name"); + auto name_it = jsonFindRequired (data, "name", "Particle's initializer must have a name"); irr::u32 id = ((id_it == data.end ()) ? 0 : (irr::u32) (*id_it)); - if (name_it == data.end ()) - { - throw std::runtime_error ("Particle's initializer must have a name"); - } - if (*name_it == "lifetimerandom") { return Initializers::CLifeTimeRandom::fromJSON (data, id); diff --git a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h index 0aa6ee1..3f5c1f3 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h +++ b/src/WallpaperEngine/Core/Objects/Particles/CInitializer.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Objects::Particles { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp index 57be620..d21882d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.cpp @@ -4,18 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAlphaRandom* CAlphaRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Alpharandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Alpharandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Alpharandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Alpharandom initializer must have a maximum value"); return new CAlphaRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h index 02a2d17..7531e1f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAlphaRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp index de3b5a6..401eaad 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.cpp @@ -1,23 +1,11 @@ #include "CAngularVelocityRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CAngularVelocityRandom* CAngularVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Angularvelocityrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Angularvelocityrandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Angularvelocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Angularvelocityrandom initializer must have a maximum value"); return new CAngularVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h index 353dc3d..f1f6344 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CAngularVelocityRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp index 927d7d6..51bd81f 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.cpp @@ -1,23 +1,11 @@ #include "CColorRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CColorRandom* CColorRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Colorrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Colorrandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Colorrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Colorrandom initializer must have a maximum value"); return new CColorRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h index 306469d..54bcb1a 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CColorRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp index c60ef6b..be91c9c 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.cpp @@ -4,18 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CLifeTimeRandom* CLifeTimeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Lifetimerandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Lifetimerandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Lifetimerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Lifetimerandom initializer must have a maximum value"); return new CLifeTimeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h index e6c7435..f1bc8ed 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CLifeTimeRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp index ad67131..66ce76d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.cpp @@ -4,18 +4,8 @@ using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CSizeRandom* CSizeRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Sizerandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Sizerandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Sizerandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Sizerandom initializer must have a maximum value"); return new CSizeRandom (id, *min_it, *max_it); } diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h index afecd47..0c46add 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CSizeRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp index 6c652fe..4db31fa 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.cpp @@ -1,23 +1,11 @@ #include "CVelocityRandom.h" -#include "WallpaperEngine/Core/Core.h" - using namespace WallpaperEngine::Core::Objects::Particles::Initializers; CVelocityRandom* CVelocityRandom::fromJSON (json data, irr::u32 id) { - auto min_it = data.find ("min"); - auto max_it = data.find ("max"); - - if (min_it == data.end ()) - { - throw std::runtime_error ("Velocityrandom initializer must have a minimum value"); - } - - if (max_it == data.end ()) - { - throw std::runtime_error ("Velocityrandom initializer must have a maximum value"); - } + auto min_it = jsonFindRequired (data, "min", "Velocityrandom initializer must have a minimum value"); + auto max_it = jsonFindRequired (data, "max", "Velocityrandom initializer must have a maximum value"); return new CVelocityRandom ( id, diff --git a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h index 131b061..ef06b1d 100644 --- a/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h +++ b/src/WallpaperEngine/Core/Objects/Particles/Initializers/CVelocityRandom.h @@ -2,7 +2,8 @@ #include "WallpaperEngine/Core/Objects/Particles/CInitializer.h" -#include +#include "WallpaperEngine/Core/Core.h" + #include namespace WallpaperEngine::Core::Objects::Particles::Initializers diff --git a/src/WallpaperEngine/Core/Projects/CProperty.cpp b/src/WallpaperEngine/Core/Projects/CProperty.cpp index 9054638..26f5c32 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.cpp +++ b/src/WallpaperEngine/Core/Projects/CProperty.cpp @@ -5,20 +5,10 @@ using namespace WallpaperEngine::Core::Projects; CProperty* CProperty::fromJSON (json data, const std::string& name) { - auto type = data.find ("type"); - auto value = data.find ("value"); + auto type = jsonFindRequired (data, "type", "Project properties must have the type field"); + auto value = jsonFindRequired (data, "value", "Project properties must have the value field"); auto text = data.find ("text"); - if (value == data.end ()) - { - throw std::runtime_error ("Project properties must have the value field"); - } - - if (type == data.end ()) - { - throw std::runtime_error ("Project properties must have the type field"); - } - if (*type == CPropertyColor::Type) { return CPropertyColor::fromJSON (data, name); diff --git a/src/WallpaperEngine/Core/Projects/CProperty.h b/src/WallpaperEngine/Core/Projects/CProperty.h index 29c4405..651b7c0 100644 --- a/src/WallpaperEngine/Core/Projects/CProperty.h +++ b/src/WallpaperEngine/Core/Projects/CProperty.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "WallpaperEngine/Core/Core.h" namespace WallpaperEngine::Core::Projects { diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp index 31e70e6..ea10468 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.cpp @@ -1,5 +1,4 @@ #include "CPropertyColor.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Projects; diff --git a/src/WallpaperEngine/Core/Projects/CPropertyColor.h b/src/WallpaperEngine/Core/Projects/CPropertyColor.h index af4bd76..a3669bd 100644 --- a/src/WallpaperEngine/Core/Projects/CPropertyColor.h +++ b/src/WallpaperEngine/Core/Projects/CPropertyColor.h @@ -4,6 +4,8 @@ #include "CProperty.h" +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Projects { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.cpp b/src/WallpaperEngine/Core/Scenes/CCamera.cpp index eadf5e0..3055805 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.cpp +++ b/src/WallpaperEngine/Core/Scenes/CCamera.cpp @@ -1,5 +1,4 @@ #include "CCamera.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Scenes; @@ -27,24 +26,9 @@ const irr::core::vector3df& CCamera::getUp () const CCamera* CCamera::fromJSON (json data) { - auto center_it = data.find ("center"); - auto eye_it = data.find ("eye"); - auto up_it = data.find ("up"); - - if (center_it == data.end ()) - { - throw std::runtime_error ("Camera must have a center position"); - } - - if (eye_it == data.end ()) - { - throw std::runtime_error ("Camera must have an eye position"); - } - - if (up_it == data.end ()) - { - throw std::runtime_error ("Camera must have a up position"); - } + auto center_it = jsonFindRequired (data, "center", "Camera must have a center position"); + auto eye_it = jsonFindRequired (data, "eye", "Camera must have an eye position"); + auto up_it = jsonFindRequired (data, "up", "Camera must have a up position"); return new CCamera ( WallpaperEngine::Core::ato3vf (*center_it), diff --git a/src/WallpaperEngine/Core/Scenes/CCamera.h b/src/WallpaperEngine/Core/Scenes/CCamera.h index 1e9efce..7465551 100644 --- a/src/WallpaperEngine/Core/Scenes/CCamera.h +++ b/src/WallpaperEngine/Core/Scenes/CCamera.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Scenes { using json = nlohmann::json; diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.cpp b/src/WallpaperEngine/Core/Scenes/CProjection.cpp index 45bd412..92495f3 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.cpp +++ b/src/WallpaperEngine/Core/Scenes/CProjection.cpp @@ -1,5 +1,4 @@ #include "CProjection.h" -#include "WallpaperEngine/Core/Core.h" using namespace WallpaperEngine::Core::Scenes; @@ -21,18 +20,8 @@ const irr::u32& CProjection::getHeight () const CProjection* CProjection::fromJSON (json data) { - auto width_it = data.find ("width"); - auto 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"); - } + auto width_it = jsonFindRequired (data, "width", "Projection must have width"); + auto height_it = jsonFindRequired (data, "height", "Projection must have height"); return new CProjection ( *width_it, diff --git a/src/WallpaperEngine/Core/Scenes/CProjection.h b/src/WallpaperEngine/Core/Scenes/CProjection.h index 537735f..16f92fc 100644 --- a/src/WallpaperEngine/Core/Scenes/CProjection.h +++ b/src/WallpaperEngine/Core/Scenes/CProjection.h @@ -1,8 +1,9 @@ #pragma once -#include #include +#include "WallpaperEngine/Core/Core.h" + namespace WallpaperEngine::Core::Scenes { using json = nlohmann::json; diff --git a/src/WallpaperEngine/FileSystem/FileSystem.cpp b/src/WallpaperEngine/FileSystem/FileSystem.cpp index 0ee94a6..5011cbc 100644 --- a/src/WallpaperEngine/FileSystem/FileSystem.cpp +++ b/src/WallpaperEngine/FileSystem/FileSystem.cpp @@ -1,6 +1,8 @@ // filesystem includes #include "FileSystem.h" +#include + // engine includes #include "WallpaperEngine/Irrlicht/CContext.h" @@ -10,6 +12,7 @@ using namespace WallpaperEngine; std::string FileSystem::loadFullFile (const irr::io::path& file) { + std::cout << file.c_str() << std::endl; irr::io::IReadFile* reader = IrrlichtContext->getDevice ()->getFileSystem ()->createAndOpenFile (file); if (reader == nullptr) diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index a287611..b7bad42 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -8,7 +8,6 @@ // shader compiler #include -#include #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableFloat.h" @@ -17,6 +16,8 @@ #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector3.h" #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariableVector4.h" +using namespace WallpaperEngine::Core; + namespace WallpaperEngine::Render::Shaders { Compiler::Compiler (Irrlicht::CContext* context, irr::io::path& file, Type type, const std::map& combos, bool recursive) : @@ -483,17 +484,12 @@ namespace WallpaperEngine::Render::Shaders void Compiler::parseComboConfiguration (const std::string& content) { json data = json::parse (content); - auto combo = data.find ("combo"); - auto defvalue = data.find ("default"); + auto combo = jsonFindRequired (data, "combo", "cannot parse combo information"); + auto defvalue = jsonFindRequired (data, "default", "cannot parse combo information"); // add line feed just in case this->m_compiledContent += "\n"; - if (combo == data.end () || defvalue == data.end ()) - { - throw std::runtime_error ("cannot parse combo information"); - } - // check the combos std::map::const_iterator entry = this->m_combos.find ((*combo).get ()); diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.h b/src/WallpaperEngine/Render/Shaders/Compiler.h index 467e553..26a818a 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.h +++ b/src/WallpaperEngine/Render/Shaders/Compiler.h @@ -4,7 +4,8 @@ #include #include #include -#include + +#include "WallpaperEngine/Core/Core.h" #include "WallpaperEngine/FileSystem/FileSystem.h"