project.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <irrlicht/irrlicht.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <stdexcept>
  5. #include "fs/fileResolver.h"
  6. #include "project.h"
  7. #include "irrlicht.h"
  8. namespace wp
  9. {
  10. project::project ()
  11. {
  12. irr::io::path projectFile = wp::fs::resolver.resolveOnWorkingDirectory ("project.json");
  13. std::ifstream _in (projectFile.c_str ());
  14. this->m_content = "";
  15. this->m_content.append (std::istreambuf_iterator<char> (_in), std::istreambuf_iterator<char> ());
  16. this->m_projectFile = json::parse (this->m_content);
  17. json::const_iterator file_it = this->m_projectFile.find ("file");
  18. json::const_iterator name_it = this->m_projectFile.find ("title");
  19. json::const_iterator type_it = this->m_projectFile.find ("type");
  20. if (file_it != this->m_projectFile.end ())
  21. {
  22. // load scene file
  23. this->m_file = wp::fs::resolver.resolveOnWorkingDirectory (*file_it);
  24. this->m_scene = new scene (this->m_file.c_str ());
  25. }
  26. if (type_it != this->m_projectFile.end ())
  27. {
  28. this->m_type = type_it.value ();
  29. }
  30. if (name_it != this->m_projectFile.end ())
  31. {
  32. this->m_title = name_it.value ();
  33. }
  34. if (this->m_type != "scene")
  35. {
  36. throw std::runtime_error ("Only scene wallpapers are supported");
  37. }
  38. }
  39. scene* project::getScene ()
  40. {
  41. return this->m_scene;
  42. }
  43. }