CImage.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "CImage.h"
  2. #include "Images/CMaterial.h"
  3. #include "WallpaperEngine/Core/Core.h"
  4. #include "../../FileSystem/utils.h"
  5. using namespace WallpaperEngine::Core::Objects;
  6. CImage::CImage (
  7. Images::CMaterial* 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. CObject (visible, id, std::move(name), origin, scale, angles),
  16. m_size (size)
  17. {
  18. }
  19. WallpaperEngine::Core::CObject* CImage::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 (WallpaperEngine::FileSystem::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 CImage (
  41. Images::CMaterial::fromFile ((*material_it).get <std::string> ().c_str ()),
  42. visible,
  43. id,
  44. name,
  45. origin,
  46. scale,
  47. angles,
  48. WallpaperEngine::Core::ato2vf (*size_it)
  49. );
  50. }