ToolSystem.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <Atomic/Core/Context.h>
  2. #include <Atomic/IO/FileSystem.h>
  3. #include <Atomic/Resource/ResourceCache.h>
  4. #include "Platform/PlatformWeb.h"
  5. #include "Platform/PlatformMac.h"
  6. #include "Platform/PlatformWindows.h"
  7. #include "Assets/AssetDatabase.h"
  8. #include "Net/CurlManager.h"
  9. #include "License/LicenseSystem.h"
  10. #include "Build/BuildSystem.h"
  11. #include "ToolSystem.h"
  12. #include "ToolEnvironment.h"
  13. #include "Project/Project.h"
  14. namespace ToolCore
  15. {
  16. ToolSystem::ToolSystem(Context* context) : Object(context),
  17. cli_(false)
  18. {
  19. context_->RegisterSubsystem(new AssetDatabase(context_));
  20. context_->RegisterSubsystem(new CurlManager(context_));
  21. context_->RegisterSubsystem(new LicenseSystem(context_));
  22. context_->RegisterSubsystem(new BuildSystem(context_));
  23. // platform registration
  24. RegisterPlatform(new PlatformMac(context));
  25. RegisterPlatform(new PlatformWeb(context));
  26. RegisterPlatform(new PlatformWindows(context));
  27. }
  28. ToolSystem::~ToolSystem()
  29. {
  30. }
  31. bool ToolSystem::LoadProject(const String& fullpath)
  32. {
  33. String pathName, fileName, ext;
  34. SplitPath(fullpath, pathName, fileName, ext);
  35. String path;
  36. if (ext == ".atomic")
  37. {
  38. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(pathName)));
  39. }
  40. else
  41. {
  42. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  43. }
  44. ResourceCache* cache = GetSubsystem<ResourceCache>();
  45. cache->AddResourceDir(path, 0);
  46. String resourcePath = path;
  47. resourcePath += "/Resources";
  48. cache->AddResourceDir(resourcePath, 0);
  49. project_ = new Project(context_);
  50. project_->SetResourcePath(resourcePath);
  51. return project_->Load(fullpath);
  52. }
  53. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  54. {
  55. if (platform == PLATFORMID_UNDEFINED)
  56. {
  57. currentPlatform_ = NULL;
  58. return;
  59. }
  60. if (!platforms_.Contains((unsigned) platform))
  61. return;
  62. currentPlatform_ = platforms_[(unsigned)platform];
  63. }
  64. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  65. {
  66. if (!platforms_.Contains((unsigned) platform))
  67. return NULL;
  68. return platforms_[(unsigned)platform];
  69. }
  70. Platform* ToolSystem::GetPlatformByName(const String& name)
  71. {
  72. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  73. while (itr != platforms_.End())
  74. {
  75. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  76. return (*itr).second_;
  77. itr++;
  78. }
  79. return NULL;
  80. }
  81. Platform *ToolSystem::GetCurrentPlatform()
  82. {
  83. return currentPlatform_;
  84. }
  85. void ToolSystem::RegisterPlatform(Platform* platform)
  86. {
  87. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  88. }
  89. }