sound.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <irrlicht/irrlicht.h>
  2. #include "../object.h"
  3. #include "sound.h"
  4. using namespace wp::core::objects;
  5. sound::sound (
  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. object (visible, id, std::move(name), origin, scale, angles)
  13. {
  14. }
  15. wp::core::object* sound::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. json::const_iterator sound_it = data.find ("sound");
  25. if (sound_it == data.end ())
  26. {
  27. throw std::runtime_error ("Sound information not present");
  28. }
  29. if ((*sound_it).is_array () == false)
  30. {
  31. throw std::runtime_error ("Expected sound list");
  32. }
  33. sound* sound = new class sound (
  34. visible,
  35. id,
  36. name,
  37. origin,
  38. scale,
  39. angles
  40. );
  41. json::const_iterator cur = (*sound_it).begin ();
  42. json::const_iterator end = (*sound_it).end ();
  43. for (; cur != end; cur ++)
  44. {
  45. sound->insertSound (*cur);
  46. }
  47. return sound;
  48. }
  49. void sound::insertSound (std::string filename)
  50. {
  51. this->m_sounds.push_back (filename);
  52. }
  53. std::vector<std::string>* sound::getSounds ()
  54. {
  55. return &this->m_sounds;
  56. }