image.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "image.h"
  2. #include "images/material.h"
  3. #include "../../core.h"
  4. #include "../../fs/utils.h"
  5. using namespace wp::core::objects;
  6. image::image (
  7. images::material* material,
  8. bool visible,
  9. irr::u32 id,
  10. std::string name,
  11. const irr::core::vector3df& origin,
  12. const irr::core::vector3df& scale,
  13. const irr::core::vector3df& angles,
  14. const irr::core::vector2df& size) :
  15. object (visible, id, std::move(name), origin, scale, angles),
  16. m_size (size)
  17. {
  18. }
  19. wp::core::object* image::fromJSON (
  20. json data,
  21. bool visible,
  22. irr::u32 id,
  23. std::string name,
  24. const irr::core::vector3df& origin,
  25. const irr::core::vector3df& scale,
  26. const irr::core::vector3df& angles)
  27. {
  28. json::const_iterator image_it = data.find ("image");
  29. json::const_iterator size_it = data.find ("size");
  30. if (size_it == data.end ())
  31. {
  32. throw std::runtime_error ("Images must have size");
  33. }
  34. json content = json::parse (wp::fs::utils::loadFullFile ((*image_it).get <std::string> ().c_str ()));
  35. json::const_iterator material_it = content.find ("material");
  36. if (material_it == content.end ())
  37. {
  38. throw std::runtime_error ("Image must have a material");
  39. }
  40. return new image (
  41. images::material::fromFile ((*material_it).get <std::string> ().c_str ()),
  42. visible,
  43. id,
  44. name,
  45. origin,
  46. scale,
  47. angles,
  48. wp::core::ato2vf (*size_it)
  49. );
  50. }