ToolSystem.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. cache->AddResourceDir(path, 0);
  66. String resourcePath = path;
  67. resourcePath += "/Resources";
  68. cache->AddResourceDir(resourcePath, 0);
  69. project_ = new Project(context_);
  70. project_->SetResourcePath(resourcePath);
  71. bool result = project_->Load(fullpath);
  72. if (result)
  73. {
  74. // TODO: persistent platform setting
  75. SetCurrentPlatform(project_->GetUserPrefs()->GetDefaultPlatform());
  76. }
  77. return result;
  78. }
  79. void ToolSystem::CloseProject()
  80. {
  81. if (project_.Null())
  82. return;
  83. SendEvent(E_PROJECTUNLOADED);
  84. ResourceCache* cache = GetSubsystem<ResourceCache>();
  85. String projectPath = project_->GetProjectPath();
  86. String resourcePath = project_->GetResourcePath();
  87. project_ = 0;
  88. cache->RemoveResourceDir(resourcePath);
  89. cache->RemoveResourceDir(projectPath);
  90. cache->ReleaseAllResources(true);
  91. }
  92. void ToolSystem::SetCurrentPlatform(PlatformID platform)
  93. {
  94. VariantMap eventData;
  95. if (platform == PLATFORMID_UNDEFINED)
  96. {
  97. currentPlatform_ = NULL;
  98. eventData[PlatformChanged::P_PLATFORM] = (Platform*) 0;
  99. SendEvent(E_PLATFORMCHANGED, eventData);
  100. return;
  101. }
  102. if (!platforms_.Contains((unsigned) platform))
  103. return;
  104. currentPlatform_ = platforms_[(unsigned)platform];
  105. eventData[PlatformChanged::P_PLATFORM] = currentPlatform_;
  106. SendEvent(E_PLATFORMCHANGED, eventData);
  107. }
  108. Platform* ToolSystem::GetPlatformByID(PlatformID platform)
  109. {
  110. if (!platforms_.Contains((unsigned) platform))
  111. return NULL;
  112. return platforms_[(unsigned)platform];
  113. }
  114. Platform* ToolSystem::GetPlatformByName(const String& name)
  115. {
  116. HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
  117. while (itr != platforms_.End())
  118. {
  119. if ((*itr).second_->GetName().ToLower()== name.ToLower())
  120. return (*itr).second_;
  121. itr++;
  122. }
  123. return NULL;
  124. }
  125. Platform *ToolSystem::GetCurrentPlatform()
  126. {
  127. return currentPlatform_;
  128. }
  129. void ToolSystem::RegisterPlatform(Platform* platform)
  130. {
  131. platforms_.Insert(MakePair((unsigned)platform->GetPlatformID(), SharedPtr<Platform>(platform)));
  132. }
  133. }