ToolSystem.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "ToolEvents.h"
  14. #include "Project/Project.h"
  15. namespace ToolCore
  16. {
  17. ToolSystem::ToolSystem(Context* context) : Object(context),
  18. cli_(false)
  19. {
  20. context_->RegisterSubsystem(new AssetDatabase(context_));
  21. context_->RegisterSubsystem(new CurlManager(context_));
  22. context_->RegisterSubsystem(new LicenseSystem(context_));
  23. context_->RegisterSubsystem(new BuildSystem(context_));
  24. // platform registration
  25. RegisterPlatform(new PlatformMac(context));
  26. RegisterPlatform(new PlatformWeb(context));
  27. RegisterPlatform(new PlatformWindows(context));
  28. }
  29. ToolSystem::~ToolSystem()
  30. {
  31. }
  32. bool ToolSystem::LoadProject(const String& fullpath)
  33. {
  34. String pathName, fileName, ext;
  35. SplitPath(fullpath, pathName, fileName, ext);
  36. String path;
  37. if (ext == ".atomic")
  38. {
  39. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(pathName)));
  40. }
  41. else
  42. {
  43. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  44. }
  45. ResourceCache* cache = GetSubsystem<ResourceCache>();
  46. cache->AddResourceDir(path, 0);
  47. String resourcePath = path;
  48. resourcePath += "/Resources";
  49. cache->AddResourceDir(resourcePath, 0);
  50. project_ = new Project(context_);
  51. project_->SetResourcePath(resourcePath);
  52. return project_->Load(fullpath);
  53. }
  54. void ToolSystem::CloseProject()
  55. {
  56. if (project_.Null())
  57. return;
  58. SendEvent(E_PROJECTUNLOADED);
  59. ResourceCache* cache = GetSubsystem<ResourceCache>();
  60. String projectPath = project_->GetProjectPath();
  61. String resourcePath = project_->GetResourcePath();
  62. project_ = 0;
  63. cache->RemoveResourceDir(resourcePath);
  64. cache->RemoveResourceDir(projectPath);
  65. cache->ReleaseAllResources(true);
  66. }
  67. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  68. {
  69. if (platform == PLATFORMID_UNDEFINED)
  70. {
  71. currentPlatform_ = NULL;
  72. return;
  73. }
  74. if (!platforms_.Contains((unsigned) platform))
  75. return;
  76. currentPlatform_ = platforms_[(unsigned)platform];
  77. }
  78. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  79. {
  80. if (!platforms_.Contains((unsigned) platform))
  81. return NULL;
  82. return platforms_[(unsigned)platform];
  83. }
  84. Platform* ToolSystem::GetPlatformByName(const String& name)
  85. {
  86. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  87. while (itr != platforms_.End())
  88. {
  89. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  90. return (*itr).second_;
  91. itr++;
  92. }
  93. return NULL;
  94. }
  95. Platform *ToolSystem::GetCurrentPlatform()
  96. {
  97. return currentPlatform_;
  98. }
  99. void ToolSystem::RegisterPlatform(Platform* platform)
  100. {
  101. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  102. }
  103. }