CSound.cpp 1.4 KB

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