CProject.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <WallpaperEngine/FileSystem/utils.h>
  2. #include "CProject.h"
  3. using namespace WallpaperEngine::Core;
  4. CProject::CProject (std::string title, std::string type, CScene *scene) :
  5. m_title (std::move (title)),
  6. m_type (std::move (type)),
  7. m_scene (scene)
  8. {
  9. this->m_scene->setProject (this);
  10. }
  11. CProject* CProject::fromFile (const irr::io::path& filename)
  12. {
  13. json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename));
  14. json::const_iterator title = content.find ("title");
  15. json::const_iterator type = content.find ("type");
  16. json::const_iterator file = content.find ("file");
  17. json::const_iterator general = content.find ("general");
  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. CProject* project = new CProject (
  31. *title,
  32. *type,
  33. CScene::fromFile ((*file).get <std::string> ().c_str ())
  34. );
  35. if (general != content.end ())
  36. {
  37. json::const_iterator properties = (*general).find ("properties");
  38. if (properties != (*general).end ())
  39. {
  40. json::const_iterator cur = (*properties).begin ();
  41. json::const_iterator end = (*properties).end ();
  42. for (; cur != end; cur ++)
  43. {
  44. project->insertProperty (
  45. Projects::CProperty::fromJSON (*cur, cur.key ())
  46. );
  47. }
  48. }
  49. }
  50. return project;
  51. }
  52. CScene* CProject::getScene ()
  53. {
  54. return this->m_scene;
  55. }
  56. std::string CProject::getTitle ()
  57. {
  58. return this->m_title;
  59. }
  60. std::string CProject::getType ()
  61. {
  62. return this->m_type;
  63. }
  64. std::vector<Projects::CProperty*>* CProject::getProperties ()
  65. {
  66. return &this->m_properties;
  67. }
  68. void CProject::insertProperty (Projects::CProperty* property)
  69. {
  70. this->m_properties.push_back (property);
  71. }