+ Added parsing of sounds

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2019-08-14 01:23:44 +02:00
parent 2ba3498517
commit 5e5dd47154
6 changed files with 134 additions and 1 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
};
}

View File

@ -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);

View File

@ -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;