BuildWeb.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/StringUtils.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/IO/File.h>
  10. #include "../ToolSystem.h"
  11. #include "../ToolEnvironment.h"
  12. #include "../Project/Project.h"
  13. #include "BuildEvents.h"
  14. #include "BuildSystem.h"
  15. #include "BuildWeb.h"
  16. namespace ToolCore
  17. {
  18. BuildWeb::BuildWeb(Context* context, Project* project) : BuildBase(context, project, PLATFORMID_WEB)
  19. {
  20. }
  21. BuildWeb::~BuildWeb()
  22. {
  23. }
  24. void BuildWeb::Initialize()
  25. {
  26. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  27. Project* project = tsystem->GetProject();
  28. Vector<String> defaultResourcePaths;
  29. GetDefaultResourcePaths(defaultResourcePaths);
  30. String projectResources = project->GetResourcePath();
  31. for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
  32. {
  33. AddResourceDir(defaultResourcePaths[i]);
  34. }
  35. // TODO: smart filtering of cache
  36. AddResourceDir(project->GetProjectPath() + "Cache/");
  37. AddResourceDir(projectResources);
  38. BuildResourceEntries();
  39. }
  40. void BuildWeb::Build(const String& buildPath)
  41. {
  42. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  43. buildPath_ = AddTrailingSlash(buildPath) + GetBuildSubfolder();
  44. VariantMap buildOutput;
  45. buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Starting Web Deployment</color>\n\n";
  46. SendEvent(E_BUILDOUTPUT, buildOutput);
  47. Initialize();
  48. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  49. if (fileSystem->DirExists(buildPath_))
  50. fileSystem->RemoveDir(buildPath_, true);
  51. String dataPath = tenv->GetToolDataDir();
  52. String buildSourceDir = dataPath + "Deployment/Web";
  53. fileSystem->CreateDir(buildPath_);
  54. String resourcePackagePath = buildPath_ + "/AtomicResources.data";
  55. GenerateResourcePackage(resourcePackagePath);
  56. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.html", buildPath_ + "/AtomicPlayer.html");
  57. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.html.mem", buildPath_ + "/AtomicPlayer.html.mem");
  58. fileSystem->Copy(buildSourceDir + "/AtomicPlayer.js", buildPath_ + "/AtomicPlayer.js");
  59. fileSystem->Copy(buildSourceDir + "/AtomicLoader.js", buildPath_ + "/AtomicLoader.js");
  60. fileSystem->Copy(buildSourceDir + "/index.html", buildPath_ + "/index.html");
  61. fileSystem->Copy(buildSourceDir + "/Atomic_Logo_Header.png", buildPath_ + "/Atomic_Logo_Header.png");
  62. File file(context_, buildSourceDir + "/AtomicResources_js.template", FILE_READ);
  63. unsigned size = file.GetSize();
  64. SharedArrayPtr<char> buffer(new char[size + 1]);
  65. file.Read(buffer.Get(), size);
  66. buffer[size] = '\0';
  67. String resourcejs = (const char*) buffer.Get();
  68. file.Close();
  69. file.Open(buildPath_ + "/AtomicResources.data", FILE_READ);
  70. int rsize = (int) file.GetSize();
  71. file.Close();
  72. String request;
  73. request.AppendWithFormat("new DataRequest(0, %i, 0, 0).open('GET', '/AtomicResources.pak');", rsize);
  74. resourcejs.Replace("$$REMOTE_PACKAGE_SIZE$$", ToString("%i", rsize));
  75. resourcejs.Replace("$$ATOMIC_RESOURCES_DATA_REQUEST$$", request);
  76. file.Open(buildPath_ + "/AtomicResources.js", FILE_WRITE);
  77. file.Write(resourcejs.CString(), resourcejs.Length());
  78. file.Close();
  79. buildOutput[BuildOutput::P_TEXT] = "\n\n<color #D4FB79>Web Deployment Complete</color>\n\n";
  80. SendEvent(E_BUILDOUTPUT, buildOutput);
  81. BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
  82. buildSystem->BuildComplete(PLATFORMID_WEB, buildPath_);
  83. //fileSystem->SystemCommandAsync("/Applications/Firefox.app/Contents/MacOS/firefox");
  84. }
  85. }