GDevelop JS Platform
Platform for developing HTML5/Javascript based games with GDevelop
ExporterHelper.h
1 /*
2  * GDevelop JS Platform
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <unordered_map>
12 #include <vector>
13 
14 #include "GDCore/IDE/CaptureOptions.h"
15 #include "GDCore/String.h"
16 namespace gd {
17 class Project;
18 class Layout;
19 class ExternalLayout;
20 class SerializerElement;
21 class AbstractFileSystem;
22 class ResourcesManager;
23 class SourceFileMetadata;
24 class WholeProjectDiagnosticReport;
25 class CaptureOptions;
26 class Screenshot;
27 } // namespace gd
28 
29 namespace gdjs {
30 
39  PreviewExportOptions(gd::Project &project_, const gd::String &exportPath_)
40  : project(project_),
41  exportPath(exportPath_),
42  useWindowMessageDebuggerClient(false),
43  useMinimalDebuggerClient(false),
44  nativeMobileApp(false),
45  projectDataOnlyExport(false),
46  fullLoadingScreen(false),
47  isDevelopmentEnvironment(false),
48  nonRuntimeScriptsCacheBurst(0),
49  inAppTutorialMessageInPreview(""),
50  inAppTutorialMessagePositionInPreview(""),
51  fallbackAuthorId(""),
52  fallbackAuthorUsername(""),
53  playerId(""),
54  playerUsername(""),
55  playerToken(""),
56  allowAuthenticationUsingIframeForPreview(false) {};
57 
63  const gd::String &address, const gd::String &port) {
64  websocketDebuggerServerAddress = address;
65  websocketDebuggerServerPort = port;
66  return *this;
67  }
68 
74  const gd::String &message, const gd::String &position) {
75  inAppTutorialMessageInPreview = message;
76  inAppTutorialMessagePositionInPreview = position;
77  return *this;
78  }
79 
84  PreviewExportOptions &SetFallbackAuthor(const gd::String &id,
85  const gd::String &username) {
86  fallbackAuthorId = id;
87  fallbackAuthorUsername = username;
88  return *this;
89  }
90 
96  const gd::String &username,
97  const gd::String &token) {
98  playerId = id;
99  playerUsername = username;
100  playerToken = token;
101  return *this;
102  }
103 
109  useWindowMessageDebuggerClient = true;
110  return *this;
111  }
112 
117  useMinimalDebuggerClient = true;
118  return *this;
119  }
120 
126  nativeMobileApp = enable;
127  return *this;
128  }
129 
133  PreviewExportOptions &SetLayoutName(const gd::String &layoutName_) {
134  layoutName = layoutName_;
135  return *this;
136  }
137 
143  const gd::String &externalLayoutName_) {
144  externalLayoutName = externalLayoutName_;
145  return *this;
146  }
147 
152  PreviewExportOptions &SetIncludeFileHash(const gd::String &includeFile,
153  int hash) {
154  includeFileHashes[includeFile] = hash;
155  return *this;
156  }
157 
163  projectDataOnlyExport = enable;
164  return *this;
165  }
166 
172  fullLoadingScreen = enable;
173  return *this;
174  }
175 
181  isDevelopmentEnvironment = enable;
182  return *this;
183  }
184 
191  nonRuntimeScriptsCacheBurst = value;
192  return *this;
193  }
194 
202  const gd::String &electronRemoteRequirePath_) {
203  electronRemoteRequirePath = electronRemoteRequirePath_;
204  return *this;
205  }
206 
212  const gd::String &gdevelopResourceToken_) {
213  gdevelopResourceToken = gdevelopResourceToken_;
214  return *this;
215  }
216 
225  bool allowAuthenticationUsingIframeForPreview_) {
226  allowAuthenticationUsingIframeForPreview =
227  allowAuthenticationUsingIframeForPreview_;
228  return *this;
229  }
230 
235  const gd::String &crashReportUploadLevel_) {
236  crashReportUploadLevel = crashReportUploadLevel_;
237  return *this;
238  }
239 
243  PreviewExportOptions &SetPreviewContext(const gd::String &previewContext_) {
244  previewContext = previewContext_;
245  return *this;
246  }
247 
252  const gd::String &gdevelopVersionWithHash_) {
253  gdevelopVersionWithHash = gdevelopVersionWithHash_;
254  return *this;
255  }
256 
261  const gd::String &projectTemplateSlug_) {
262  projectTemplateSlug = projectTemplateSlug_;
263  return *this;
264  }
265 
269  PreviewExportOptions &SetSourceGameId(const gd::String &sourceGameId_) {
270  sourceGameId = sourceGameId_;
271  return *this;
272  }
273 
279  const gd::String &signedUrl,
280  const gd::String &publicUrl) {
281  gd::Screenshot screenshot;
282  screenshot.SetDelayTimeInSeconds(delayTimeInSeconds);
283  screenshot.SetSignedUrl(signedUrl);
284  screenshot.SetPublicUrl(publicUrl);
285  captureOptions.AddScreenshot(screenshot);
286  return *this;
287  }
288 
289  gd::Project &project;
290  gd::String exportPath;
291  gd::String websocketDebuggerServerAddress;
292  gd::String websocketDebuggerServerPort;
293  bool useWindowMessageDebuggerClient;
294  bool useMinimalDebuggerClient;
295  gd::String layoutName;
296  gd::String externalLayoutName;
297  gd::String fallbackAuthorUsername;
298  gd::String fallbackAuthorId;
299  gd::String playerId;
300  gd::String playerUsername;
301  gd::String playerToken;
302  gd::String inAppTutorialMessageInPreview;
303  gd::String inAppTutorialMessagePositionInPreview;
304  bool nativeMobileApp;
305  std::map<gd::String, int> includeFileHashes;
306  bool projectDataOnlyExport;
307  bool fullLoadingScreen;
308  bool isDevelopmentEnvironment;
309  unsigned int nonRuntimeScriptsCacheBurst;
310  gd::String electronRemoteRequirePath;
311  gd::String gdevelopResourceToken;
312  bool allowAuthenticationUsingIframeForPreview;
313  gd::String crashReportUploadLevel;
314  gd::String previewContext;
315  gd::String gdevelopVersionWithHash;
316  gd::String projectTemplateSlug;
317  gd::String sourceGameId;
318  gd::CaptureOptions captureOptions;
319 };
320 
329  ExportOptions(gd::Project &project_, const gd::String &exportPath_)
330  : project(project_),
331  exportPath(exportPath_),
332  target(""),
333  fallbackAuthorId(""),
334  fallbackAuthorUsername("") {};
335 
340  ExportOptions &SetFallbackAuthor(const gd::String &id,
341  const gd::String &username) {
342  fallbackAuthorId = id;
343  fallbackAuthorUsername = username;
344  return *this;
345  }
346 
353  ExportOptions &SetTarget(const gd::String &target_) {
354  target = target_;
355  return *this;
356  }
357 
358  gd::Project &project;
359  gd::String exportPath;
360  gd::String target;
361  gd::String fallbackAuthorUsername;
362  gd::String fallbackAuthorId;
363 };
364 
370  public:
371  ExporterHelper(gd::AbstractFileSystem &fileSystem,
372  gd::String gdjsRoot_,
373  gd::String codeOutputDir);
374  virtual ~ExporterHelper() {};
375 
379  const gd::String &GetLastError() const { return lastError; };
380 
391  static gd::String ExportProjectData(
392  gd::AbstractFileSystem &fs,
393  gd::Project &project,
394  gd::String filename,
395  const gd::SerializerElement &runtimeGameOptions,
396  std::set<gd::String> &projectUsedResources,
397  std::unordered_map<gd::String, std::set<gd::String>>
398  &layersUsedResources);
399 
410  static void ExportResources(gd::AbstractFileSystem &fs,
411  gd::Project &project,
412  gd::String exportDir);
413 
417  void AddLibsInclude(bool pixiRenderers,
418  bool pixiInThreeRenderers,
419  bool includeWebsocketDebuggerClient,
420  bool includeWindowMessageDebuggerClient,
421  bool includeMinimalDebuggerClient,
422  bool includeCaptureManager,
423  bool includeInAppTutorialMessage,
424  gd::String gdevelopLogoStyle,
425  std::vector<gd::String> &includesFiles);
426 
430  void RemoveIncludes(bool pixiRenderers,
431  std::vector<gd::String> &includesFiles);
432 
443  bool ExportIncludesAndLibs(const std::vector<gd::String> &includesFiles,
444  gd::String exportDir,
445  bool exportSourceMaps);
446 
456  bool ExportEventsCode(
457  const gd::Project &project,
458  gd::String outputDir,
459  std::vector<gd::String> &includesFiles,
460  gd::WholeProjectDiagnosticReport &wholeProjectDiagnosticReport,
461  bool exportForPreview);
462 
466  bool ExportEffectIncludes(gd::Project &project,
467  std::vector<gd::String> &includesFiles);
468 
486  bool ExportIndexFile(const gd::Project &project,
487  gd::String source,
488  gd::String exportDir,
489  const std::vector<gd::String> &includesFiles,
490  const std::vector<gd::SourceFileMetadata> &sourceFiles,
491  unsigned int nonRuntimeScriptsCacheBurst,
492  gd::String additionalSpec = "");
493 
510  bool CompleteIndexFile(gd::String &indexFileContent,
511  gd::String exportDir,
512  const std::vector<gd::String> &includesFiles,
513  unsigned int nonRuntimeScriptsCacheBurst,
514  gd::String additionalSpec);
515 
523  const gd::String GenerateWebManifest(const gd::Project &project);
524 
532  bool ExportCordovaFiles(const gd::Project &project,
533  gd::String exportDir,
534  std::set<gd::String> usedExtensions);
535 
543  bool ExportElectronFiles(const gd::Project &project,
544  gd::String exportDir,
545  std::set<gd::String> usedExtensions);
546 
554  bool ExportBuildResourcesElectronFiles(const gd::Project &project,
555  gd::String exportDir);
556 
564  bool ExportFacebookInstantGamesFiles(const gd::Project &project,
565  gd::String exportDir);
566 
573  bool ExportHtml5Files(const gd::Project &project, gd::String exportDir);
574 
583 
588  gd::String GetExportedIncludeFilename(
589  const gd::String &include, unsigned int nonRuntimeScriptsCacheBurst = 0);
590 
596  void SetCodeOutputDirectory(gd::String codeOutputDir_) {
597  codeOutputDir = codeOutputDir_;
598  }
599 
600  static void AddDeprecatedFontFilesToFontResources(
601  gd::AbstractFileSystem &fs,
602  gd::ResourcesManager &resourcesManager,
603  const gd::String &exportDir,
604  gd::String urlPrefix = "");
605 
606  gd::AbstractFileSystem
607  &fs;
608  gd::String lastError;
609  gd::String
611  gd::String codeOutputDir;
613 
614  private:
615  static void SerializeUsedResources(
616  gd::SerializerElement &rootElement,
617  std::set<gd::String> &projectUsedResources,
618  std::unordered_map<gd::String, std::set<gd::String>>
619  &layersUsedResources);
620 };
621 
622 } // namespace gdjs
Export a project or a layout to a playable HTML5/Javascript based game.
Definition: ExporterHelper.h:369
bool CompleteIndexFile(gd::String &indexFileContent, gd::String exportDir, const std::vector< gd::String > &includesFiles, unsigned int nonRuntimeScriptsCacheBurst, gd::String additionalSpec)
Replace the annotations in a index.html file by the specified content.
Definition: ExporterHelper.cpp:767
gd::String lastError
The last error that occurred.
Definition: ExporterHelper.h:608
bool ExportEffectIncludes(gd::Project &project, std::vector< gd::String > &includesFiles)
Add the project effects include files.
Definition: ExporterHelper.cpp:949
gd::String GetExportedIncludeFilename(const gd::String &include, unsigned int nonRuntimeScriptsCacheBurst=0)
Given an include file, returns the name of the file to reference in the exported game.
Definition: ExporterHelper.cpp:996
bool ExportProjectForPixiPreview(const PreviewExportOptions &options)
Create a preview for the specified options.
Definition: ExporterHelper.cpp:106
bool ExportHtml5Files(const gd::Project &project, gd::String exportDir)
Generate any HTML5 specific file.
Definition: ExporterHelper.cpp:636
bool ExportBuildResourcesElectronFiles(const gd::Project &project, gd::String exportDir)
Generate the Build Resources files for Electron (mainly for the icons) for packaging and save it to t...
Definition: ExporterHelper.cpp:748
bool ExportIncludesAndLibs(const std::vector< gd::String > &includesFiles, gd::String exportDir, bool exportSourceMaps)
Copy all the specified files to the export directory. Relative files are copied from "<GDJS root>/Run...
Definition: ExporterHelper.cpp:1035
void AddLibsInclude(bool pixiRenderers, bool pixiInThreeRenderers, bool includeWebsocketDebuggerClient, bool includeWindowMessageDebuggerClient, bool includeMinimalDebuggerClient, bool includeCaptureManager, bool includeInAppTutorialMessage, gd::String gdevelopLogoStyle, std::vector< gd::String > &includesFiles)
Add libraries files to the list of includes.
Definition: ExporterHelper.cpp:802
gd::String gdjsRoot
The root directory of GDJS, used to copy runtime files.
Definition: ExporterHelper.h:610
bool ExportCordovaFiles(const gd::Project &project, gd::String exportDir, std::set< gd::String > usedExtensions)
Generate the Cordova configuration file and save it to the export directory.
Definition: ExporterHelper.cpp:437
bool ExportFacebookInstantGamesFiles(const gd::Project &project, gd::String exportDir)
Generate the Facebook Instant Games files for packaging and save it to the export directory.
Definition: ExporterHelper.cpp:615
static void ExportResources(gd::AbstractFileSystem &fs, gd::Project &project, gd::String exportDir)
Copy all the resources of the project to to the export directory, updating the resources filenames.
Definition: ExporterHelper.cpp:1074
bool ExportEventsCode(const gd::Project &project, gd::String outputDir, std::vector< gd::String > &includesFiles, gd::WholeProjectDiagnosticReport &wholeProjectDiagnosticReport, bool exportForPreview)
Generate the events JS code, and save them to the export directory.
Definition: ExporterHelper.cpp:961
gd::String codeOutputDir
Definition: ExporterHelper.h:611
bool ExportIndexFile(const gd::Project &project, gd::String source, gd::String exportDir, const std::vector< gd::String > &includesFiles, const std::vector< gd::SourceFileMetadata > &sourceFiles, unsigned int nonRuntimeScriptsCacheBurst, gd::String additionalSpec="")
Generate the standard index file and save it to the export directory.
Definition: ExporterHelper.cpp:390
void RemoveIncludes(bool pixiRenderers, std::vector< gd::String > &includesFiles)
Remove include files that are Pixi renderers.
Definition: ExporterHelper.cpp:935
const gd::String & GetLastError() const
Return the error that occurred during the last export.
Definition: ExporterHelper.h:379
static gd::String ExportProjectData(gd::AbstractFileSystem &fs, gd::Project &project, gd::String filename, const gd::SerializerElement &runtimeGameOptions, std::set< gd::String > &projectUsedResources, std::unordered_map< gd::String, std::set< gd::String >> &layersUsedResources)
Export a project to JSON.
Definition: ExporterHelper.cpp:337
const gd::String GenerateWebManifest(const gd::Project &project)
Generates a WebManifest, a metadata file that allow to make the exported game a working PWA.
Definition: ExporterHelper.cpp:1118
gd::AbstractFileSystem & fs
The abstract file system to be used for exportation.
Definition: ExporterHelper.h:607
bool ExportElectronFiles(const gd::Project &project, gd::String exportDir, std::set< gd::String > usedExtensions)
Generate the Electron files for packaging and save it to the export directory.
Definition: ExporterHelper.cpp:657
void SetCodeOutputDirectory(gd::String codeOutputDir_)
Change the directory where code files are generated.
Definition: ExporterHelper.h:596
The options used to export a project.
Definition: ExporterHelper.h:324
ExportOptions & SetTarget(const gd::String &target_)
Set the (optional) target platform.
Definition: ExporterHelper.h:353
ExportOptions(gd::Project &project_, const gd::String &exportPath_)
Definition: ExporterHelper.h:329
ExportOptions & SetFallbackAuthor(const gd::String &id, const gd::String &username)
Set the fallback author info (if info not present in project properties).
Definition: ExporterHelper.h:340
The options used to export a project for a preview.
Definition: ExporterHelper.h:34
PreviewExportOptions & SetCrashReportUploadLevel(const gd::String &crashReportUploadLevel_)
Set the level of crash reports to be sent to GDevelop APIs.
Definition: ExporterHelper.h:234
PreviewExportOptions & UseWindowMessageDebuggerClient()
Set that the game should connect to the debugger server using the "Window Message " debugger client.
Definition: ExporterHelper.h:108
PreviewExportOptions & SetProjectTemplateSlug(const gd::String &projectTemplateSlug_)
Set the template slug that was used to create the project.
Definition: ExporterHelper.h:260
PreviewExportOptions & SetSourceGameId(const gd::String &sourceGameId_)
Set the source game id that was used to create the project.
Definition: ExporterHelper.h:269
PreviewExportOptions & SetExternalLayoutName(const gd::String &externalLayoutName_)
Set the (optional) external layout to be instantiated in the scene at the beginning of the previewed ...
Definition: ExporterHelper.h:142
PreviewExportOptions & SetElectronRemoteRequirePath(const gd::String &electronRemoteRequirePath_)
Definition: ExporterHelper.h:201
PreviewExportOptions & SetGDevelopResourceToken(const gd::String &gdevelopResourceToken_)
Definition: ExporterHelper.h:211
PreviewExportOptions & SetIncludeFileHash(const gd::String &includeFile, int hash)
Set the hash associated to an include file. Useful for the preview hot-reload, to know if a file chan...
Definition: ExporterHelper.h:152
PreviewExportOptions & SetGDevelopVersionWithHash(const gd::String &gdevelopVersionWithHash_)
Set the GDevelop version so the game is aware of it.
Definition: ExporterHelper.h:251
PreviewExportOptions & SetIsDevelopmentEnvironment(bool enable)
Set if the export should consider to be in a development environment of GDevelop (the game should use...
Definition: ExporterHelper.h:180
PreviewExportOptions & SetPreviewContext(const gd::String &previewContext_)
Set the context of the preview.
Definition: ExporterHelper.h:243
PreviewExportOptions & UseMinimalDebuggerClient()
Set that the game should have a minimal debugger client.
Definition: ExporterHelper.h:116
PreviewExportOptions & SetFullLoadingScreen(bool enable)
Set if the export should show the full loading screen (false by default, skipping the minimum duratio...
Definition: ExporterHelper.h:171
PreviewExportOptions & UseWebsocketDebuggerClientWithServerAddress(const gd::String &address, const gd::String &port)
Set the address of the debugger server that the game should reach out to, using the "WebSockets" debu...
Definition: ExporterHelper.h:62
PreviewExportOptions & SetFallbackAuthor(const gd::String &id, const gd::String &username)
Set the fallback author info (if info not present in project properties).
Definition: ExporterHelper.h:84
PreviewExportOptions & SetLayoutName(const gd::String &layoutName_)
Set the layout to be run first in the previewed game.
Definition: ExporterHelper.h:133
PreviewExportOptions & SetAuthenticatedPlayer(const gd::String &id, const gd::String &username, const gd::String &token)
Set the fallback author info (if info not present in project properties).
Definition: ExporterHelper.h:95
PreviewExportOptions & SetInAppTutorialMessageInPreview(const gd::String &message, const gd::String &position)
Set the message to display to the user in a preview (as part of an in-app tutorial).
Definition: ExporterHelper.h:73
PreviewExportOptions(gd::Project &project_, const gd::String &exportPath_)
Definition: ExporterHelper.h:39
PreviewExportOptions & SetNonRuntimeScriptsCacheBurst(unsigned int value)
If set to a non zero value, the exported script URLs will have an extra search parameter added (with ...
Definition: ExporterHelper.h:190
PreviewExportOptions & SetNativeMobileApp(bool enable)
Set that the preview is launched from a GDevelop native mobile app (iOS or Android).
Definition: ExporterHelper.h:125
PreviewExportOptions & AddScreenshotCapture(int delayTimeInSeconds, const gd::String &signedUrl, const gd::String &publicUrl)
Set the capture options to be used for taking screenshots or videos of the preview.
Definition: ExporterHelper.h:278
PreviewExportOptions & SetProjectDataOnlyExport(bool enable)
Set if the export should only export the project data, not exporting events code.
Definition: ExporterHelper.h:162
PreviewExportOptions & SetAllowAuthenticationUsingIframeForPreview(bool allowAuthenticationUsingIframeForPreview_)
Definition: ExporterHelper.h:224