ToolSystem.cpp 3.7 KB

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