ToolSystem.cpp 4.2 KB

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