Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('gdjs.ShapePainterRuntimeObject (using a PixiJS RuntimeGame with assets
};

it('properly computes bounds of the object (basics)', async () => {
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
const runtimeGame = await gdjs.getPixiRuntimeGame();
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
loadScene(runtimeScene);

Expand Down Expand Up @@ -127,7 +127,7 @@ describe('gdjs.ShapePainterRuntimeObject (using a PixiJS RuntimeGame with assets
});

it('properly computes bounds of the object (custom center)', async () => {
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
const runtimeGame = await gdjs.getPixiRuntimeGame();
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
loadScene(runtimeScene);

Expand Down Expand Up @@ -202,7 +202,7 @@ describe('gdjs.ShapePainterRuntimeObject (using a PixiJS RuntimeGame with assets
});

it('can transform points', async () => {
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
const runtimeGame = await gdjs.getPixiRuntimeGame();
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
loadScene(runtimeScene);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('gdjs.TextInputRuntimeObject (using a PixiJS RuntimeGame with DOM eleme
};

const setupObjectAndGetDomElementContainer = async () => {
const runtimeGame = await gdjs.getPixiRuntimeGameWithAssets();
const runtimeGame = await gdjs.getPixiRuntimeGame();
const runtimeScene = new gdjs.RuntimeScene(runtimeGame);
loadScene(runtimeScene);

Expand Down
11 changes: 6 additions & 5 deletions GDJS/GDJS/IDE/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ bool Exporter::ExportWholePixiProject(const ExportOptions &options) {
/*includeCaptureManager*/ false,
/*includeInAppTutorialMessage*/ false,
exportedProject.GetLoadingScreen().GetGDevelopLogoStyle(),
includesFiles);
includesFiles,
resourcesFiles);

// Export files for free function, object and behaviors
for (const auto &includeFile : usedExtensionsResult.GetUsedIncludeFiles()) {
Expand Down Expand Up @@ -145,14 +146,14 @@ bool Exporter::ExportWholePixiProject(const ExportOptions &options) {
helper.ExportIncludesAndLibs(includesFiles, exportDir, false);
helper.ExportIncludesAndLibs(resourcesFiles, exportDir, false);

gd::String source = gdjsRoot + "/Runtime/index.html";
gd::String sourceDir = gdjsRoot + "/Runtime";
if (options.target == "cordova")
source = gdjsRoot + "/Runtime/Cordova/www/index.html";
sourceDir = gdjsRoot + "/Runtime/Cordova/www";
else if (options.target == "facebookInstantGames")
source = gdjsRoot + "/Runtime/FacebookInstantGames/index.html";
sourceDir = gdjsRoot + "/Runtime/FacebookInstantGames";

if (!helper.ExportIndexFile(exportedProject,
source,
sourceDir,
exportDir,
includesFiles,
usedExtensionsResult.GetUsedSourceFiles(),
Expand Down
65 changes: 47 additions & 18 deletions GDJS/GDJS/IDE/ExporterHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,22 @@ bool ExporterHelper::ExportProjectForPixiPreview(
// end of compatibility code
}

bool hasScanProjectForExtension = false;
bool has3DObjects = false;

std::vector<gd::SourceFileMetadata> noUsedSourceFiles;
std::vector<gd::SourceFileMetadata> &usedSourceFiles = noUsedSourceFiles;
if (options.shouldReloadLibraries || options.shouldClearExportFolder) {
auto usedExtensionsResult =
gd::UsedExtensionsFinder::ScanProject(exportedProject);
usedSourceFiles = usedExtensionsResult.GetUsedSourceFiles();
hasScanProjectForExtension = true;
has3DObjects = usedExtensionsResult.Has3DObjects();

// Export engine libraries
AddLibsInclude(/*pixiRenderers=*/true,
/*pixiInThreeRenderers=*/
usedExtensionsResult.Has3DObjects(),
has3DObjects,
/*isInGameEdition=*/
options.isInGameEdition,
/*includeWebsocketDebuggerClient=*/
Expand All @@ -191,7 +196,8 @@ bool ExporterHelper::ExportProjectForPixiPreview(
/*includeInAppTutorialMessage*/
!options.inAppTutorialMessageInPreview.empty(),
immutableProject.GetLoadingScreen().GetGDevelopLogoStyle(),
includesFiles);
includesFiles,
resourcesFiles);

// Export files for free function, object and behaviors
for (const auto &includeFile : usedExtensionsResult.GetUsedIncludeFiles()) {
Expand Down Expand Up @@ -321,18 +327,26 @@ bool ExporterHelper::ExportProjectForPixiPreview(

if (options.shouldReloadLibraries || options.shouldClearExportFolder) {
includesFiles.push_back(codeOutputDir + "/data.js");
includesFiles.push_back("gdjs-bootstrap.js");
// Copy all the dependencies and their source maps
ExportIncludesAndLibs(includesFiles, options.exportPath, true);
ExportIncludesAndLibs(resourcesFiles, options.exportPath, true);

// TODO Build a full includesFiles list without actually doing export or
// generation.
if (options.shouldGenerateScenesEventsCode || options.shouldClearExportFolder) {
if (!hasScanProjectForExtension) {
auto usedExtensionsResult =
gd::UsedExtensionsFinder::ScanProject(exportedProject);
usedSourceFiles = usedExtensionsResult.GetUsedSourceFiles();
hasScanProjectForExtension = true;
has3DObjects = usedExtensionsResult.Has3DObjects();
}
// Create the index file
if (!ExportIndexFile(exportedProject, gdjsRoot + "/Runtime/index.html",
if (!ExportIndexFile(exportedProject, gdjsRoot + "/Runtime",
options.exportPath, includesFiles, usedSourceFiles,
options.nonRuntimeScriptsCacheBurst,
"gdjs.runtimeGameOptions")) {
has3DObjects, "gdjs.runtimeGameOptions")) {
return false;
}
}
Expand Down Expand Up @@ -701,13 +715,14 @@ void ExporterHelper::SerializeUsedResources(

bool ExporterHelper::ExportIndexFile(
const gd::Project &project,
gd::String source,
gd::String sourceDir,
gd::String exportDir,
const std::vector<gd::String> &includesFiles,
const std::vector<gd::SourceFileMetadata> &sourceFiles,
unsigned int nonRuntimeScriptsCacheBurst,
bool has3DObjects,
gd::String additionalSpec) {
gd::String str = fs.ReadFile(source);
gd::String str = fs.ReadFile(sourceDir + "/index.html");

// Add a reference to all files to include, as weel as the source files
// required by the project.
Expand All @@ -734,7 +749,7 @@ bool ExporterHelper::ExportIndexFile(
exportDir,
finalIncludesFiles,
nonRuntimeScriptsCacheBurst,
additionalSpec))
has3DObjects))
return false;

// Write the index.html file
Expand All @@ -743,6 +758,14 @@ bool ExporterHelper::ExportIndexFile(
return false;
}

gd::String bootstrapScript = fs.ReadFile(sourceDir + "/gdjs-bootscrap.js");
bootstrapScript.FindAndReplace("{} /*GDJS_ADDITIONAL_SPEC*/",
additionalSpec.empty() ? "{}"
: additionalSpec);
if (!fs.WriteToFile(exportDir + "/gdjs-bootscrap.js", str)) {
lastError = "Unable to write index file.";
return false;
}
return true;
}

Expand Down Expand Up @@ -1081,9 +1104,7 @@ bool ExporterHelper::CompleteIndexFile(
gd::String exportDir,
const std::vector<gd::String> &includesFiles,
unsigned int nonRuntimeScriptsCacheBurst,
gd::String additionalSpec) {
if (additionalSpec.empty()) additionalSpec = "{}";

bool has3DObjects) {
gd::String codeFilesIncludes;
for (auto &include : includesFiles) {
gd::String scriptSrc =
Expand All @@ -1100,13 +1121,20 @@ bool ExporterHelper::CompleteIndexFile(
}

codeFilesIncludes += "\t<script src=\"" + scriptSrc +
"\" crossorigin=\"anonymous\"></script>\n";
"\" crossorigin=\"anonymous\" defer></script>\n";
}

str = str.FindAndReplace("/* GDJS_CUSTOM_STYLE */", "")
.FindAndReplace("<!-- GDJS_CUSTOM_HTML -->", "")
.FindAndReplace("<!-- GDJS_CODE_FILES -->", codeFilesIncludes)
.FindAndReplace("{}/*GDJS_ADDITIONAL_SPEC*/", additionalSpec);
str =
str.FindAndReplace("/* GDJS_CUSTOM_STYLE */", "")
.FindAndReplace(
"<!-- 3D_LIBRARY_SCRIPT -->",
has3DObjects
? "<script type=\"module\">\n"
" import * as THREE from './pixi-renderers/three.js';\n"
" globalThis.THREE = THREE;\n"
"</script>\n"
: "")
.FindAndReplace("<!-- GDJS_CUSTOM_HTML -->", "")
.FindAndReplace("<!-- GDJS_CODE_FILES -->", codeFilesIncludes);

return true;
}
Expand All @@ -1120,7 +1148,8 @@ void ExporterHelper::AddLibsInclude(bool pixiRenderers,
bool includeCaptureManager,
bool includeInAppTutorialMessage,
gd::String gdevelopLogoStyle,
std::vector<gd::String> &includesFiles) {
std::vector<gd::String> &includesFiles,
std::vector<gd::String> &requiredFiles) {
// First, do not forget common includes (they must be included before events
// generated code files).
InsertUnique(includesFiles, "libs/jshashtable.js");
Expand Down Expand Up @@ -1204,7 +1233,7 @@ void ExporterHelper::AddLibsInclude(bool pixiRenderers,
}

if (pixiInThreeRenderers || isInGameEdition) {
InsertUnique(includesFiles, "pixi-renderers/three.js");
InsertUnique(requiredFiles, "pixi-renderers/three.js");
InsertUnique(includesFiles, "pixi-renderers/ThreeAddons.js");
InsertUnique(includesFiles, "pixi-renderers/draco/gltf/draco_decoder.wasm");
InsertUnique(includesFiles,
Expand Down
53 changes: 28 additions & 25 deletions GDJS/GDJS/IDE/ExporterHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ class ExporterHelper {
bool includeCaptureManager,
bool includeInAppTutorialMessage,
gd::String gdevelopLogoStyle,
std::vector<gd::String> &includesFiles);
std::vector<gd::String> &includesFiles,
std::vector<gd::String> &requiredFiles);

/**
* \brief Remove include files that are Pixi renderers.
Expand Down Expand Up @@ -606,7 +607,8 @@ class ExporterHelper {
* The includes files must be relative to the export directory.
*
* \param project The project with layouts to be exported.
* \param source The file to be used as a template for the final file.
* \param sourceDir The directory containing the files to be used as a
* template for the final file.
* \param exportDir The directory where the preview must be created.
* \param includesFiles The JS files to be included in the HTML file. Order is
* important.
Expand All @@ -617,35 +619,14 @@ class ExporterHelper {
* gdjs.RuntimeGame object.
*/
bool ExportIndexFile(const gd::Project &project,
gd::String source,
gd::String sourceDir,
gd::String exportDir,
const std::vector<gd::String> &includesFiles,
const std::vector<gd::SourceFileMetadata> &sourceFiles,
unsigned int nonRuntimeScriptsCacheBurst,
bool has3DObjects,
gd::String additionalSpec = "");

/**
* \brief Replace the annotations in a index.html file by the specified
* content.
*
* \param indexFileContent The source of the index.html file.
* \param exportDir The directory where the project must be generated.
* \param includesFiles "<!--GDJS_CODE_FILES -->" will be
* replaced by HTML tags to include the filenames
* contained inside the vector.
* \param nonRuntimeScriptsCacheBurst If 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.
* \param additionalSpec The string "GDJS_ADDITIONAL_SPEC"
* surrounded by comments marks will be replaced by the
* content of this string.
*/
bool CompleteIndexFile(gd::String &indexFileContent,
gd::String exportDir,
const std::vector<gd::String> &includesFiles,
unsigned int nonRuntimeScriptsCacheBurst,
gd::String additionalSpec);

/**
* \brief Generates a WebManifest, a metadata file that allow to make the
* exported game a working PWA.
Expand Down Expand Up @@ -751,6 +732,28 @@ class ExporterHelper {
///< be then copied to the final output directory.

private:
/**
* \brief Replace the annotations in a index.html file by the specified
* content.
*
* \param indexFileContent The source of the index.html file.
* \param exportDir The directory where the project must be generated.
* \param includesFiles "<!--GDJS_CODE_FILES -->" will be
* replaced by HTML tags to include the filenames
* contained inside the vector.
* \param nonRuntimeScriptsCacheBurst If 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.
* \param additionalSpec The string "GDJS_ADDITIONAL_SPEC"
* surrounded by comments marks will be replaced by the
* content of this string.
*/
bool CompleteIndexFile(gd::String &indexFileContent,
gd::String exportDir,
const std::vector<gd::String> &includesFiles,
unsigned int nonRuntimeScriptsCacheBurst,
bool has3DObjects);

static void
SerializeUsedResources(gd::SerializerElement &rootElement,
std::set<gd::String> &projectUsedResources,
Expand Down
20 changes: 20 additions & 0 deletions GDJS/Runtime/gdjs-bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function () {
//Initialization
const game = new gdjs.RuntimeGame(
gdjs.projectData,
{} /*GDJS_ADDITIONAL_SPEC*/
);

//Create a renderer
game.getRenderer().createStandardCanvas(document.body);

//Bind keyboards/mouse/touch events
game
.getRenderer()
.bindStandardEvents(game.getInputManager(), window, document);

//Load all assets and start the game
game.loadAllAssets(function () {
game.startGameLoop();
});
})();
26 changes: 3 additions & 23 deletions GDJS/Runtime/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,11 @@

/* GDJS_CUSTOM_STYLE */
</style>
<!-- Libs and GDJS core files : -->
<!-- GDJS_CODE_FILES -->

</head>
<body>

<!-- 3D_LIBRARY_SCRIPT -->
<!-- Libs and GDJS core files : -->
<!-- GDJS_CODE_FILES -->
<!-- GDJS_CUSTOM_HTML -->
<script>

(function() {
//Initialization
var game = new gdjs.RuntimeGame(gdjs.projectData, {}/*GDJS_ADDITIONAL_SPEC*/);

//Create a renderer
game.getRenderer().createStandardCanvas(document.body);

//Bind keyboards/mouse/touch events
game.getRenderer().bindStandardEvents(game.getInputManager(), window, document);

//Load all assets and start the game
game.loadAllAssets(function() {
game.startGameLoop();
});
})();

</script>
</body>
</html>
3 changes: 1 addition & 2 deletions GDJS/Runtime/pixi-renderers/three.js

Large diffs are not rendered by default.

Loading