Project.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include <rapidjson/document.h>
  5. #include <rapidjson/filestream.h>
  6. #include <rapidjson/prettywriter.h>
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/File.h>
  9. #include <Atomic/Resource/JSONFile.h>
  10. #include "../Platform/Platform.h"
  11. #include "ProjectFile.h"
  12. #include "ProjectBuildSettings.h"
  13. #include "ProjectUserPrefs.h"
  14. #include "Project.h"
  15. using namespace rapidjson;
  16. namespace ToolCore
  17. {
  18. Project::Project(Context* context) :
  19. Object(context),
  20. dirty_(false)
  21. {
  22. userPrefs_ = new ProjectUserPrefs(context_);
  23. buildSettings_ = new ProjectBuildSettings(context_);
  24. }
  25. Project::~Project()
  26. {
  27. }
  28. void Project::LoadUserPrefs(const String& fullpath)
  29. {
  30. rapidjson::Document document;
  31. File jsonFile(context_, fullpath);
  32. if (!jsonFile.IsOpen())
  33. return;
  34. String json;
  35. jsonFile.ReadText(json);
  36. if (!json.Length())
  37. return;
  38. if (document.Parse<0>(json.CString()).HasParseError())
  39. {
  40. LOGERRORF("Could not parse Project JSON data from %s", fullpath.CString());
  41. return;
  42. }
  43. const Value::Member* current_platform = document.FindMember("current_platform");
  44. /*
  45. AEEditorPlatform platform = AE_PLATFORM_UNDEFINED;
  46. if (current_platform && current_platform->value.IsString())
  47. {
  48. String splatform = current_platform->value.GetString();
  49. if (splatform == "Windows")
  50. platform = AE_PLATFORM_WINDOWS;
  51. else if (splatform == "Mac")
  52. platform = AE_PLATFORM_MAC;
  53. else if (splatform == "HTML5")
  54. platform = AE_PLATFORM_HTML5;
  55. else if (splatform == "iOS")
  56. platform = AE_PLATFORM_IOS;
  57. else if (splatform == "Android")
  58. platform = AE_PLATFORM_ANDROID;
  59. }
  60. if (platform == AE_PLATFORM_UNDEFINED)
  61. {
  62. #ifdef ATOMIC_PLATFORM_OSX
  63. platform = AE_PLATFORM_MAC;
  64. #else
  65. platform = AE_PLATFORM_WINDOWS;
  66. #endif
  67. }
  68. */
  69. /*
  70. const Value::Member* last_build_path = document.FindMember("last_build_path");
  71. if (last_build_path && last_build_path->value.IsString())
  72. {
  73. lastBuildPath_ = last_build_path->value.GetString();
  74. }
  75. */
  76. // probably will want to move this, it will trigger a save (which is guarded with load_)
  77. /*
  78. Editor* editor = GetSubsystem<Editor>();
  79. editor->RequestPlatformChange(platform);
  80. */
  81. }
  82. void Project::SaveUserPrefs(const String& fullpath)
  83. {
  84. }
  85. void Project::SaveBuildSettings(const String& path)
  86. {
  87. }
  88. bool Project::LoadBuildSettings(const String& path)
  89. {
  90. return false;
  91. }
  92. void Project::AddPlatform(PlatformID platformID)
  93. {
  94. if (ContainsPlatform(platformID))
  95. return;
  96. dirty_ = true;
  97. platforms_.Push(platformID);
  98. }
  99. void Project::RemovePlatform(PlatformID platformID)
  100. {
  101. if (!ContainsPlatform(platformID))
  102. return;
  103. }
  104. bool Project::ContainsPlatform(PlatformID platformID)
  105. {
  106. for (List<PlatformID>::ConstIterator i = platforms_.Begin(); i != platforms_.End(); ++i)
  107. {
  108. if ((*i) == platformID)
  109. return true;
  110. }
  111. return false;
  112. }
  113. bool Project::Load(const String& fullpath)
  114. {
  115. projectFilePath_ = fullpath;
  116. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  117. return pfile->Load(this);
  118. }
  119. String Project::GetBuildSettingsFullPath()
  120. {
  121. String path = GetPath(projectFilePath_);
  122. String filename = GetFileName(projectFilePath_);
  123. String buildSettingsPath = path + filename + ".buildsettings";
  124. return buildSettingsPath;
  125. }
  126. String Project::GetUserPrefsFullPath()
  127. {
  128. String path = GetPath(projectFilePath_);
  129. String filename = GetFileName(projectFilePath_);
  130. String prefsPath = path + filename + ".userprefs";
  131. return prefsPath;
  132. }
  133. void Project::Save(const String& fullpath)
  134. {
  135. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  136. pfile->Save(this);
  137. dirty_ = false;
  138. }
  139. bool Project::IsComponentsDirOrFile(const String& fullPath)
  140. {
  141. String pathName;
  142. String fileName;
  143. String extension;
  144. SplitPath(fullPath, pathName, fileName, extension);
  145. if (extension.Length() && extension != ".js")
  146. return false;
  147. if (IsAbsoluteParentPath(componentsPath_, pathName))
  148. return true;
  149. return false;
  150. }
  151. bool Project::IsScriptsDirOrFile(const String& fullPath)
  152. {
  153. String pathName;
  154. String fileName;
  155. String extension;
  156. SplitPath(fullPath, pathName, fileName, extension);
  157. if (extension.Length() && extension != ".js")
  158. return false;
  159. if (IsAbsoluteParentPath(scriptsPath_, pathName))
  160. return true;
  161. return false;
  162. }
  163. bool Project::IsModulesDirOrFile(const String& fullPath)
  164. {
  165. String pathName;
  166. String fileName;
  167. String extension;
  168. SplitPath(fullPath, pathName, fileName, extension);
  169. if (extension.Length() && extension != ".js")
  170. return false;
  171. if (IsAbsoluteParentPath(modulesPath_, pathName))
  172. return true;
  173. return false;
  174. }
  175. }