CProject.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <WallpaperEngine/fs/utils.h>
  2. #include "CProject.h"
  3. #include "../fs/utils.h"
  4. using namespace WallpaperEngine::Core;
  5. CProject::CProject (std::string title, std::string type, CScene *scene) :
  6. m_title (std::move (title)),
  7. m_type (std::move (type)),
  8. m_scene (scene)
  9. {
  10. this->m_scene->setProject (this);
  11. }
  12. CProject* CProject::fromFile (const irr::io::path& filename)
  13. {
  14. json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename));
  15. json::const_iterator title = content.find ("title");
  16. json::const_iterator type = content.find ("type");
  17. json::const_iterator file = content.find ("file");
  18. if (title == content.end ())
  19. {
  20. throw std::runtime_error ("Project title missing");
  21. }
  22. if (type == content.end ())
  23. {
  24. throw std::runtime_error ("Project type missing");
  25. }
  26. if (file == content.end ())
  27. {
  28. throw std::runtime_error ("Project's main file missing");
  29. }
  30. return new CProject (
  31. *title,
  32. *type,
  33. CScene::fromFile ((*file).get <std::string> ().c_str ())
  34. );
  35. }
  36. CScene* CProject::getScene ()
  37. {
  38. return this->m_scene;
  39. }
  40. std::string CProject::getTitle ()
  41. {
  42. return this->m_title;
  43. }
  44. std::string CProject::getType ()
  45. {
  46. return this->m_type;
  47. }