ToolSystem.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  34. ResourceCache* cache = GetSubsystem<ResourceCache>();
  35. cache->AddResourceDir(path, 0);
  36. String resourcePath = path;
  37. resourcePath += "/Resources";
  38. cache->AddResourceDir(resourcePath, 0);
  39. project_ = new Project(context_);
  40. project_->SetResourcePath(resourcePath);
  41. return project_->Load(fullpath);
  42. }
  43. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  44. {
  45. if (platform == PLATFORMID_UNDEFINED)
  46. {
  47. currentPlatform_ = NULL;
  48. return;
  49. }
  50. if (!platforms_.Contains((unsigned) platform))
  51. return;
  52. currentPlatform_ = platforms_[(unsigned)platform];
  53. }
  54. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  55. {
  56. if (!platforms_.Contains((unsigned) platform))
  57. return NULL;
  58. return platforms_[(unsigned)platform];
  59. }
  60. Platform* ToolSystem::GetPlatformByName(const String& name)
  61. {
  62. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  63. while (itr != platforms_.End())
  64. {
  65. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  66. return (*itr).second_;
  67. itr++;
  68. }
  69. return NULL;
  70. }
  71. Platform *ToolSystem::GetCurrentPlatform()
  72. {
  73. return currentPlatform_;
  74. }
  75. void ToolSystem::RegisterPlatform(Platform* platform)
  76. {
  77. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  78. }
  79. }