ToolSystem.cpp 3.8 KB

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