ToolSystem.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "Net/CurlManager.h"
  7. #include "License/LicenseSystem.h"
  8. #include "Build/BuildSystem.h"
  9. #include "ToolSystem.h"
  10. #include "Project/Project.h"
  11. namespace ToolCore
  12. {
  13. ToolSystem::ToolSystem(Context* context) : Object(context)
  14. {
  15. context_->RegisterSubsystem(new CurlManager(context_));
  16. context_->RegisterSubsystem(new LicenseSystem(context_));
  17. context_->RegisterSubsystem(new BuildSystem(context_));
  18. // platform registration
  19. RegisterPlatform(new PlatformMac(context));
  20. RegisterPlatform(new PlatformWeb(context));
  21. }
  22. ToolSystem::~ToolSystem()
  23. {
  24. }
  25. bool ToolSystem::LoadProject(const String& fullpath)
  26. {
  27. String path = GetPath(fullpath);
  28. ResourceCache* cache = GetSubsystem<ResourceCache>();
  29. cache->AddResourceDir(path, 0);
  30. String resourcePath = path;
  31. resourcePath += "Resources";
  32. cache->AddResourceDir(resourcePath, 0);
  33. project_ = new Project(context_);
  34. project_->SetResourcePath(resourcePath);
  35. project_->Load(fullpath);
  36. return true;
  37. }
  38. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  39. {
  40. if (platform == PLATFORMID_UNDEFINED)
  41. {
  42. currentPlatform_ = NULL;
  43. return;
  44. }
  45. if (!platforms_.Contains((unsigned) platform))
  46. return;
  47. currentPlatform_ = platforms_[(unsigned)platform];
  48. }
  49. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  50. {
  51. if (!platforms_.Contains((unsigned) platform))
  52. return NULL;
  53. return platforms_[(unsigned)platform];
  54. }
  55. Platform* ToolSystem::GetPlatformByName(const String& name)
  56. {
  57. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  58. while (itr != platforms_.End())
  59. {
  60. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  61. return (*itr).second_;
  62. itr++;
  63. }
  64. return NULL;
  65. }
  66. Platform *ToolSystem::GetCurrentPlatform()
  67. {
  68. return currentPlatform_;
  69. }
  70. void ToolSystem::RegisterPlatform(Platform* platform)
  71. {
  72. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  73. }
  74. }