ToolSystem.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/ProjectUserPrefs.h"
  25. #ifdef ATOMIC_DOTNET
  26. #include "NETTools/NETToolSystem.h"
  27. #endif
  28. namespace ToolCore
  29. {
  30. ToolSystem::ToolSystem(Context* context) : Object(context),
  31. cli_(false)
  32. {
  33. context_->RegisterSubsystem(new AssetDatabase(context_));
  34. context_->RegisterSubsystem(new CurlManager(context_));
  35. context_->RegisterSubsystem(new LicenseSystem(context_));
  36. context_->RegisterSubsystem(new BuildSystem(context_));
  37. context_->RegisterSubsystem(new SubprocessSystem(context_));
  38. #ifdef ATOMIC_DOTNET
  39. context_->RegisterSubsystem(new NETToolSystem(context_));
  40. #endif
  41. // platform registration
  42. RegisterPlatform(new PlatformMac(context));
  43. RegisterPlatform(new PlatformWeb(context));
  44. RegisterPlatform(new PlatformWindows(context));
  45. RegisterPlatform(new PlatformIOS(context));
  46. RegisterPlatform(new PlatformAndroid(context));
  47. }
  48. ToolSystem::~ToolSystem()
  49. {
  50. }
  51. bool ToolSystem::LoadProject(const String& fullpath)
  52. {
  53. String pathName, fileName, ext;
  54. SplitPath(fullpath, pathName, fileName, ext);
  55. String path;
  56. if (ext == ".atomic")
  57. {
  58. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(pathName)));
  59. }
  60. else
  61. {
  62. path = RemoveTrailingSlash(GetPath(AddTrailingSlash(fullpath)));
  63. }
  64. ResourceCache* cache = GetSubsystem<ResourceCache>();
  65. // Do NOT add the root project path as a resource path, otherwise
  66. // it will introduce a situation where there are nested resource paths
  67. // which will confuse the ResourceCache and can cause resources referenced
  68. // by various paths to be seen as unique resources
  69. //cache->AddResourceDir(path, 0);
  70. String resourcePath = path;
  71. resourcePath += "/Resources";
  72. cache->AddResourceDir(resourcePath, 0);
  73. project_ = new Project(context_);
  74. project_->SetResourcePath(resourcePath);
  75. bool result = project_->Load(fullpath);
  76. if (result)
  77. {
  78. // TODO: persistent platform setting
  79. SetCurrentPlatform(project_->GetUserPrefs()->GetDefaultPlatform());
  80. }
  81. return result;
  82. }
  83. void ToolSystem::CloseProject()
  84. {
  85. if (project_.Null())
  86. return;
  87. SendEvent(E_PROJECTUNLOADED);
  88. ResourceCache* cache = GetSubsystem<ResourceCache>();
  89. String projectPath = project_->GetProjectPath();
  90. String resourcePath = project_->GetResourcePath();
  91. project_ = 0;
  92. cache->RemoveResourceDir(resourcePath);
  93. cache->RemoveResourceDir(projectPath);
  94. cache->ReleaseAllResources(true);
  95. }
  96. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  97. {
  98. VariantMap eventData;
  99. if (platform == PLATFORMID_UNDEFINED)
  100. {
  101. currentPlatform_ = NULL;
  102. eventData[PlatformChanged::P_PLATFORM] = (Platform*) 0;
  103. SendEvent(E_PLATFORMCHANGED, eventData);
  104. return;
  105. }
  106. if (!platforms_.Contains((unsigned) platform))
  107. return;
  108. currentPlatform_ = platforms_[(unsigned)platform];
  109. eventData[PlatformChanged::P_PLATFORM] = currentPlatform_;
  110. SendEvent(E_PLATFORMCHANGED, eventData);
  111. }
  112. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  113. {
  114. if (!platforms_.Contains((unsigned) platform))
  115. return NULL;
  116. return platforms_[(unsigned)platform];
  117. }
  118. Platform* ToolSystem::GetPlatformByName(const String& name)
  119. {
  120. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  121. while (itr != platforms_.End())
  122. {
  123. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  124. return (*itr).second_;
  125. itr++;
  126. }
  127. return NULL;
  128. }
  129. Platform *ToolSystem::GetCurrentPlatform()
  130. {
  131. return currentPlatform_;
  132. }
  133. void ToolSystem::RegisterPlatform(Platform* platform)
  134. {
  135. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  136. }
  137. }