CSound.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <irrlicht/irrlicht.h>
  2. #include "WallpaperEngine/Core/CObject.h"
  3. #include "CSound.h"
  4. #include "WallpaperEngine/Core/Core.h"
  5. using namespace WallpaperEngine::Core::Objects;
  6. CSound::CSound (
  7. bool visible,
  8. irr::u32 id,
  9. std::string name,
  10. const irr::core::vector3df& origin,
  11. const irr::core::vector3df& scale,
  12. const irr::core::vector3df& angles) :
  13. CObject (visible, id, std::move(name), Type, origin, scale, angles)
  14. {
  15. }
  16. WallpaperEngine::Core::CObject* CSound::fromJSON (
  17. json data,
  18. bool visible,
  19. irr::u32 id,
  20. std::string name,
  21. const irr::core::vector3df& origin,
  22. const irr::core::vector3df& scale,
  23. const irr::core::vector3df& angles)
  24. {
  25. auto sound_it = jsonFindValueRequired(&data, "sound", "Sound information not present");
  26. if ((*sound_it).is_array () == false)
  27. {
  28. throw std::runtime_error ("Expected sound list");
  29. }
  30. CSound* sound = new CSound (
  31. visible,
  32. id,
  33. name,
  34. origin,
  35. scale,
  36. angles
  37. );
  38. auto cur = (*sound_it).begin ();
  39. auto end = (*sound_it).end ();
  40. for (; cur != end; cur ++)
  41. {
  42. sound->insertSound (*cur);
  43. }
  44. return sound;
  45. }
  46. void CSound::insertSound (std::string filename)
  47. {
  48. this->m_sounds.push_back (filename);
  49. }
  50. const std::vector<std::string>& CSound::getSounds () const
  51. {
  52. return this->m_sounds;
  53. }
  54. const std::string CSound::Type = "sound";