project.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <wallpaperengine/fs/utils.h>
  2. #include "project.h"
  3. #include "../fs/utils.h"
  4. using namespace wp::core;
  5. project::project (std::string title, std::string type, scene *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. project* project::fromFile (const irr::io::path& filename)
  13. {
  14. json content = json::parse (wp::fs::utils::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 project (
  31. *title,
  32. *type,
  33. scene::fromFile ((*file).get <std::string> ().c_str ())
  34. );
  35. }
  36. scene* project::getScene ()
  37. {
  38. return this->m_scene;
  39. }
  40. std::string project::getTitle ()
  41. {
  42. return this->m_title;
  43. }
  44. std::string project::getType ()
  45. {
  46. return this->m_type;
  47. }