GDevelop JS Platform
Platform for developing HTML5/Javascript based games with GDevelop
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
gdjs::ExporterHelper Class Reference

Export a project or a layout to a playable HTML5/Javascript based game. More...

#include <ExporterHelper.h>

Public Member Functions

 ExporterHelper (gd::AbstractFileSystem &fileSystem, gd::String gdjsRoot_, gd::String codeOutputDir)
 
const gd::String & GetLastError () const
 Return the error that occurred during the last export.
 
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.
 
void RemoveIncludes (bool pixiRenderers, std::vector< gd::String > &includesFiles)
 Remove include files that are Pixi renderers.
 
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>/Runtime" directory. More...
 
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. More...
 
bool ExportEffectIncludes (gd::Project &project, std::vector< gd::String > &includesFiles)
 Add the project effects include files.
 
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. More...
 
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. More...
 
const gd::String GenerateWebManifest (const gd::Project &project)
 Generates a WebManifest, a metadata file that allow to make the exported game a working PWA. More...
 
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. More...
 
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. More...
 
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 the export directory. More...
 
bool ExportFacebookInstantGamesFiles (const gd::Project &project, gd::String exportDir)
 Generate the Facebook Instant Games files for packaging and save it to the export directory. More...
 
bool ExportHtml5Files (const gd::Project &project, gd::String exportDir)
 Generate any HTML5 specific file. More...
 
bool ExportProjectForPixiPreview (const PreviewExportOptions &options)
 Create a preview for the specified options. More...
 
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.
 
void SetCodeOutputDirectory (gd::String codeOutputDir_)
 Change the directory where code files are generated. More...
 

Static Public Member Functions

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. More...
 
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. More...
 
static void AddDeprecatedFontFilesToFontResources (gd::AbstractFileSystem &fs, gd::ResourcesManager &resourcesManager, const gd::String &exportDir, gd::String urlPrefix="")
 

Public Attributes

gd::AbstractFileSystem & fs
 The abstract file system to be used for exportation.
 
gd::String lastError
 The last error that occurred.
 
gd::String gdjsRoot
 The root directory of GDJS, used to copy runtime files.
 
gd::String codeOutputDir
 

Detailed Description

Export a project or a layout to a playable HTML5/Javascript based game.

Member Function Documentation

◆ CompleteIndexFile()

bool gdjs::ExporterHelper::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.

Parameters
indexFileContentThe source of the index.html file.
exportDirThe directory where the project must be generated.
includesFiles"<!--GDJS_CODE_FILES -->" will be replaced by HTML tags to include the filenames contained inside the vector.
nonRuntimeScriptsCacheBurstIf non zero, add an additional cache bursting parameter to scripts, that are not part of the runtime/extensions, to force the browser to reload them.
additionalSpecThe string "GDJS_ADDITIONAL_SPEC" surrounded by comments marks will be replaced by the content of this string.

◆ ExportBuildResourcesElectronFiles()

bool gdjs::ExporterHelper::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 the export directory.

Parameters
projectThe original (non modified) project to be used.
exportDirThe directory where the files must be created.

◆ ExportCordovaFiles()

bool gdjs::ExporterHelper::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.

Parameters
projectThe project to be used to generate the configuration file.
exportDirThe directory where the config.xml must be created.

◆ ExportElectronFiles()

bool gdjs::ExporterHelper::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.

Parameters
projectThe project to be used to generate the files.
exportDirThe directory where the files must be created.

◆ ExportEventsCode()

bool gdjs::ExporterHelper::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.

Files are named "codeX.js", X being the number of the layout in the project.

Parameters
projectThe project with resources to be exported.
outputDirThe directory where the events code must be generated.
includesFilesA reference to a vector that will be filled with JS files to be exported along with the project. ( including "codeX.js" files ).

◆ ExportFacebookInstantGamesFiles()

bool gdjs::ExporterHelper::ExportFacebookInstantGamesFiles ( const gd::Project &  project,
gd::String  exportDir 
)

Generate the Facebook Instant Games files for packaging and save it to the export directory.

Parameters
projectThe project to be used to generate the files.
exportDirThe directory where the files must be created.

◆ ExportHtml5Files()

bool gdjs::ExporterHelper::ExportHtml5Files ( const gd::Project &  project,
gd::String  exportDir 
)

Generate any HTML5 specific file.

Parameters
projectThe project to be used to generate the files.
exportDirThe directory where the files must be created.

◆ ExportIncludesAndLibs()

bool gdjs::ExporterHelper::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>/Runtime" directory.

Parameters
includesFilesA vector with filenames to be copied.
exportDirThe directory where the files must be copied.
exportSourceMapsShould the source maps be copied? Should be true on previews only.

◆ ExportIndexFile()

bool gdjs::ExporterHelper::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.

The includes files must be relative to the export directory.

Parameters
projectThe project with layouts to be exported.
sourceThe file to be used as a template for the final file.
exportDirThe directory where the preview must be created.
includesFilesThe JS files to be included in the HTML file. Order is important.
nonRuntimeScriptsCacheBurstIf non zero, add an additional cache bursting parameter to scripts, that are not part of the runtime/extensions, to force the browser to reload them.
additionalSpecJSON string that will be passed to the gdjs.RuntimeGame object.

◆ ExportProjectData()

gd::String gdjs::ExporterHelper::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 
)
static

Export a project to JSON.

Parameters
fsThe abstract file system to use to write the file
projectThe project to be exported.
filenameThe filename where export the project
runtimeGameOptionsThe content of the extra configuration to store in gdjs.runtimeGameOptions
Returns
Empty string if everything is ok, description of the error otherwise.

◆ ExportProjectForPixiPreview()

bool gdjs::ExporterHelper::ExportProjectForPixiPreview ( const PreviewExportOptions options)

Create a preview for the specified options.

Note
The preview is not launched, it is the caller responsibility to open a browser pointing to the preview.
Parameters
optionsThe options to generate the preview.

◆ ExportResources()

void gdjs::ExporterHelper::ExportResources ( gd::AbstractFileSystem &  fs,
gd::Project &  project,
gd::String  exportDir 
)
static

Copy all the resources of the project to to the export directory, updating the resources filenames.

Parameters
fsThe abstract file system to use
projectThe project with resources to be exported.
exportDirThe directory where the preview must be created.
progressDlgOptional wxProgressDialog which will be updated with the progress.

◆ GenerateWebManifest()

const gd::String gdjs::ExporterHelper::GenerateWebManifest ( const gd::Project &  project)

Generates a WebManifest, a metadata file that allow to make the exported game a working PWA.

Parameters
projectThe project containing the game properties to generate the manifest from.

◆ SetCodeOutputDirectory()

void gdjs::ExporterHelper::SetCodeOutputDirectory ( gd::String  codeOutputDir_)
inline

Change the directory where code files are generated.

By default, this is set to a temporary directory.

Member Data Documentation

◆ codeOutputDir

gd::String gdjs::ExporterHelper::codeOutputDir

The directory where JS code is outputted. Will be then copied to the final output directory.


The documentation for this class was generated from the following files: