From 5e5dd47154f7ac550ffd11095fa8cfa037295a6c Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Wed, 14 Aug 2019 01:23:44 +0200 Subject: [PATCH] + Added parsing of sounds Signed-off-by: Alexis Maiquez --- CMakeLists.txt | 2 + wallpaperengine/core/object.cpp | 20 +++++++- wallpaperengine/core/objects/sound.cpp | 67 ++++++++++++++++++++++++++ wallpaperengine/core/objects/sound.h | 40 +++++++++++++++ wallpaperengine/core/scene.cpp | 5 ++ wallpaperengine/core/scene.h | 1 + 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 wallpaperengine/core/objects/sound.cpp create mode 100644 wallpaperengine/core/objects/sound.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b09641..0cc4e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,8 @@ add_executable( wallpaperengine/core/objects/image.cpp wallpaperengine/core/objects/image.h + wallpaperengine/core/objects/sound.cpp + wallpaperengine/core/objects/sound.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 7ab2a95..694553a 100644 --- a/wallpaperengine/core/object.cpp +++ b/wallpaperengine/core/object.cpp @@ -1,5 +1,6 @@ #include "object.h" #include "objects/image.h" +#include "objects/sound.h" #include "../core.h" @@ -66,10 +67,13 @@ object* object::fromJSON (json data) } json::const_iterator image_it = data.find ("image"); + json::const_iterator sound_it = data.find ("sound"); + + object* object = nullptr; if (image_it != data.end () && (*image_it).is_null () == false) { - return objects::image::fromJSON ( + object = objects::image::fromJSON ( data, visible, *id_it, @@ -79,4 +83,18 @@ object* object::fromJSON (json data) wp::core::ato3vf (*angles_it) ); } + else if (sound_it != data.end ()) + { + object = objects::sound::fromJSON ( + data, + visible, + *id_it, + *name_it, + wp::core::ato3vf (*origin_it), + wp::core::ato3vf (*scale_it), + wp::core::ato3vf (*angles_it) + ); + } + + return object; } \ No newline at end of file diff --git a/wallpaperengine/core/objects/sound.cpp b/wallpaperengine/core/objects/sound.cpp new file mode 100644 index 0000000..281e37b --- /dev/null +++ b/wallpaperengine/core/objects/sound.cpp @@ -0,0 +1,67 @@ +#include + +#include "../object.h" +#include "sound.h" + +using namespace wp::core::objects; +sound::sound ( + bool visible, + irr::u32 id, + std::string name, + const irr::core::vector3df& origin, + const irr::core::vector3df& scale, + const irr::core::vector3df& angles) : + object (visible, id, std::move(name), origin, scale, angles) +{ +} + +wp::core::object* sound::fromJSON ( + json data, + bool visible, + irr::u32 id, + std::string name, + const irr::core::vector3df& origin, + const irr::core::vector3df& scale, + const irr::core::vector3df& angles) +{ + json::const_iterator sound_it = data.find ("sound"); + + if (sound_it == data.end ()) + { + throw std::runtime_error ("Sound information not present"); + } + + if ((*sound_it).is_array () == false) + { + throw std::runtime_error ("Expected sound list"); + } + + sound* sound = new class sound ( + visible, + id, + name, + origin, + scale, + angles + ); + + json::const_iterator cur = (*sound_it).begin (); + json::const_iterator end = (*sound_it).end (); + + for (; cur != end; cur ++) + { + sound->insertSound (*cur); + } + + return sound; +} + +void sound::insertSound (std::string filename) +{ + this->m_sounds.push_back (filename); +} + +std::vector* sound::getSounds () +{ + return &this->m_sounds; +} \ No newline at end of file diff --git a/wallpaperengine/core/objects/sound.h b/wallpaperengine/core/objects/sound.h new file mode 100644 index 0000000..0db1b34 --- /dev/null +++ b/wallpaperengine/core/objects/sound.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +#include "../object.h" + +namespace wp::core::objects +{ + using json = nlohmann::json; + + class sound : object + { + public: + static object* fromJSON ( + json data, + bool visible, + irr::u32 id, + std::string name, + const irr::core::vector3df& origin, + const irr::core::vector3df& scale, + const irr::core::vector3df& angles + ); + + void insertSound (std::string filename); + std::vector* getSounds (); + protected: + + sound ( + bool visible, + irr::u32 id, + std::string name, + const irr::core::vector3df& origin, + const irr::core::vector3df& scale, + const irr::core::vector3df& angles + ); + private: + std::vector m_sounds; + }; +} diff --git a/wallpaperengine/core/scene.cpp b/wallpaperengine/core/scene.cpp index 8705dc0..457ba02 100644 --- a/wallpaperengine/core/scene.cpp +++ b/wallpaperengine/core/scene.cpp @@ -207,6 +207,11 @@ scene* scene::fromFile (const irr::io::path& filename) } +std::vector* scene::getObjects () +{ + return &this->m_objects; +} + void scene::insertObject (object* object) { this->m_objects.push_back (object); diff --git a/wallpaperengine/core/scene.h b/wallpaperengine/core/scene.h index 7b249e4..668053d 100644 --- a/wallpaperengine/core/scene.h +++ b/wallpaperengine/core/scene.h @@ -22,6 +22,7 @@ namespace wp::core static scene* fromFile (const irr::io::path& filename); project* getProject (); + std::vector* getObjects (); const irr::video::SColorf &getAmbientColor() const;