ToolSystem.cpp 4.1 KB

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