ソースを参照

+ Added parsing of sounds

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 7 年 前
親
コミット
5e5dd47154

+ 2 - 0
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

+ 19 - 1
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,25 @@ 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,
+            *name_it,
+            wp::core::ato3vf (*origin_it),
+            wp::core::ato3vf (*scale_it),
+            wp::core::ato3vf (*angles_it)
+        );
+    }
+    else if (sound_it != data.end ())
+    {
+        object = objects::sound::fromJSON (
             data,
             visible,
             *id_it,
@@ -79,4 +95,6 @@ object* object::fromJSON (json data)
             wp::core::ato3vf (*angles_it)
         );
     }
+
+    return object;
 }

+ 67 - 0
wallpaperengine/core/objects/sound.cpp

@@ -0,0 +1,67 @@
+#include <irrlicht/irrlicht.h>
+
+#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<std::string>* sound::getSounds ()
+{
+    return &this->m_sounds;
+}

+ 40 - 0
wallpaperengine/core/objects/sound.h

@@ -0,0 +1,40 @@
+#pragma once
+
+#include <irrlicht/irrlicht.h>
+#include <nlohmann/json.hpp>
+
+#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<std::string>* 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<std::string> m_sounds;
+    };
+}

+ 5 - 0
wallpaperengine/core/scene.cpp

@@ -207,6 +207,11 @@ scene* scene::fromFile (const irr::io::path& filename)
 }
 
 
+std::vector<object*>* scene::getObjects ()
+{
+    return &this->m_objects;
+}
+
 void scene::insertObject (object* object)
 {
     this->m_objects.push_back (object);

+ 1 - 0
wallpaperengine/core/scene.h

@@ -22,6 +22,7 @@ namespace wp::core
         static scene* fromFile (const irr::io::path& filename);
 
         project* getProject ();
+        std::vector<object*>* getObjects ();
 
 
         const irr::video::SColorf &getAmbientColor() const;