mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-16 06:12:23 +08:00
+ Added parsing of sounds
Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
2ba3498517
commit
5e5dd47154
@ -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
|
||||
|
@ -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;
|
||||
}
|
67
wallpaperengine/core/objects/sound.cpp
Normal file
67
wallpaperengine/core/objects/sound.cpp
Normal 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;
|
||||
}
|
40
wallpaperengine/core/objects/sound.h
Normal file
40
wallpaperengine/core/objects/sound.h
Normal 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;
|
||||
};
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user