ToolSystem.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Core/Context.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/Resource/ResourceCache.h>
  10. #include "Platform/PlatformWeb.h"
  11. #include "Platform/PlatformMac.h"
  12. #include "Platform/PlatformWindows.h"
  13. #include "Platform/PlatformAndroid.h"
  14. #include "Platform/PlatformIOS.h"
  15. #include "Assets/AssetDatabase.h"
  16. #include "Net/CurlManager.h"
  17. #include "License/LicenseSystem.h"
  18. #include "Build/BuildSystem.h"
  19. #include "Subprocess/SubprocessSystem.h"
  20. #include "ToolSystem.h"
  21. #include "ToolEnvironment.h"
  22. #include "ToolEvents.h"
  23. #include "Project/Project.h"
  24. #include "Project/ProjectEvents.h"
  25. #include "Project/ProjectUserPrefs.h"
  26. #ifdef ATOMIC_DOTNET
  27. #include "NETTools/NETToolSystem.h"
  28. #endif
  29. namespace ToolCore
  30. {
  31. ToolSystem::ToolSystem(Context* context) : Object(context),
  32. cli_(false)
  33. {
  34. context_->RegisterSubsystem(new AssetDatabase(context_));
  35. context_->RegisterSubsystem(new CurlManager(context_));
  36. context_->RegisterSubsystem(new LicenseSystem(context_));
  37. context_->RegisterSubsystem(new BuildSystem(context_));
  38. context_->RegisterSubsystem(new SubprocessSystem(context_));
  39. #ifdef ATOMIC_DOTNET
  40. context_->RegisterSubsystem(new NETToolSystem(context_));
  41. #endif
  42. // platform registration
  43. RegisterPlatform(new PlatformMac(context));
  44. RegisterPlatform(new PlatformWeb(context));
  45. RegisterPlatform(new PlatformWindows(context));
  46. RegisterPlatform(new PlatformIOS(context));
  47. RegisterPlatform(new PlatformAndroid(context));
  48. }
  49. ToolSystem::~ToolSystem()
  50. {
  51. }
  52. bool ToolSystem::LoadProject(const String& fullpath)
  53. {
  54. String pathName, fileName, ext;
  55. SplitPath(fullpath, pathName, fileName, ext);
  56. String path;
  57. if (ext == ".atomic")
  58. {
  59. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(pathName)));
  60. }
  61. else
  62. {
  63. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  64. }
  65. ResourceCache* cache = GetSubsystem<ResourceCache>();
  66. // Do NOT add the root project path as a resource path, otherwise
  67. // it will introduce a situation where there are nested resource paths
  68. // which will confuse the ResourceCache and can cause resources referenced
  69. // by various paths to be seen as unique resources
  70. //cache->AddResourceDir(path, 0);
  71. String resourcePath = path;
  72. resourcePath += "/Resources";
  73. cache->AddResourceDir(resourcePath, 0);
  74. project_ = new Project(context_);
  75. project_->SetResourcePath(resourcePath);
  76. bool result = project_->Load(fullpath);
  77. if (result)
  78. {
  79. // TODO: persistent platform setting
  80. SetCurrentPlatform(project_->GetUserPrefs()->GetDefaultPlatform());
  81. }
  82. return result;
  83. }
  84. void ToolSystem::CloseProject()
  85. {
  86. if (project_.Null())
  87. return;
  88. SendEvent(E_PROJECTUNLOADED);
  89. ResourceCache* cache = GetSubsystem<ResourceCache>();
  90. String projectPath = project_->GetProjectPath();
  91. String resourcePath = project_->GetResourcePath();
  92. project_ = 0;
  93. cache->RemoveResourceDir(resourcePath);
  94. cache->RemoveResourceDir(projectPath);
  95. cache->ReleaseAllResources(true);
  96. }
  97. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  98. {
  99. VariantMap eventData;
  100. if (platform == PLATFORMID_UNDEFINED)
  101. {
  102. currentPlatform_ = NULL;
  103. eventData[PlatformChanged::P_PLATFORM] = (Platform*) 0;
  104. SendEvent(E_PLATFORMCHANGED, eventData);
  105. return;
  106. }
  107. if (!platforms_.Contains((unsigned) platform))
  108. return;
  109. currentPlatform_ = platforms_[(unsigned)platform];
  110. eventData[PlatformChanged::P_PLATFORM] = currentPlatform_;
  111. SendEvent(E_PLATFORMCHANGED, eventData);
  112. }
  113. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  114. {
  115. if (!platforms_.Contains((unsigned) platform))
  116. return NULL;
  117. return platforms_[(unsigned)platform];
  118. }
  119. Platform* ToolSystem::GetPlatformByName(const String& name)
  120. {
  121. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  122. while (itr != platforms_.End())
  123. {
  124. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  125. return (*itr).second_;
  126. itr++;
  127. }
  128. return NULL;
  129. }
  130. Platform *ToolSystem::GetCurrentPlatform()
  131. {
  132. return currentPlatform_;
  133. }
  134. void ToolSystem::RegisterPlatform(Platform* platform)
  135. {
  136. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  137. }
  138. }