ImportCmd.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <Atomic/Core/StringUtils.h>
  2. #include <Atomic/IO/Log.h>
  3. #include <Atomic/IO/File.h>
  4. #include "../ToolSystem.h"
  5. #include "../Project/Project.h"
  6. #include "../Import/JSONSceneImporter.h"
  7. #include "../Import/JSONSceneProcess.h"
  8. #include "ImportCmd.h"
  9. #include <Poco/File.h>
  10. namespace ToolCore
  11. {
  12. ImportCmd::ImportCmd(Context* context) : Command(context)
  13. {
  14. }
  15. ImportCmd::~ImportCmd()
  16. {
  17. }
  18. bool ImportCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  19. {
  20. String argument = arguments[startIndex].ToLower();
  21. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  22. if (argument != "import")
  23. {
  24. errorMsg = "Unable to parse import command";
  25. return false;
  26. }
  27. if (!value.Length())
  28. {
  29. errorMsg = "Unable to parse source JSON filename";
  30. return false;
  31. }
  32. sourceJSONFilename_ = value;
  33. return true;
  34. }
  35. void ImportCmd::Run()
  36. {
  37. Poco::File file(sourceJSONFilename_.CString());
  38. if (!file.exists())
  39. {
  40. Error(ToString("JSON source scene does not exist: %s", sourceJSONFilename_.CString()));
  41. return;
  42. }
  43. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  44. Project* project = tsystem->GetProject();
  45. String resourcePath = project->GetResourcePath();
  46. LOGRAWF("Importing: %s", sourceJSONFilename_.CString());
  47. SharedPtr<JSONSceneImporter> jimporter;
  48. jimporter = new JSONSceneImporter(context_);
  49. jimporter->Import(sourceJSONFilename_);
  50. SharedPtr<JSONSceneProcess> sceneProcess;
  51. sceneProcess = new JSONSceneProcess(context_, jimporter);
  52. sceneProcess->Process(resourcePath);
  53. sceneProcess->Write();
  54. Finished();
  55. }
  56. }