Compare commits

...

1 Commits

4 changed files with 66 additions and 1 deletions

View File

@@ -78,6 +78,28 @@ void DeclareSystemInfoExtension(gd::PlatformExtension& extension) {
.AddCodeOnlyParameter("currentScene", ""); .AddCodeOnlyParameter("currentScene", "");
extension
.AddCondition(
"IsPreviewingAnExternalLayout",
_("Is the game running an external layout as a preview"),
_("Check if the game is currently being previewed in the editor, "
"and this preview was launched for an external layout."),
_("An external layout of the game is being previewed in the editor"),
"",
"CppPlatform/Extensions/systeminfoicon.png",
"CppPlatform/Extensions/systeminfoicon.png")
.AddCodeOnlyParameter("currentScene", "");
extension
.AddExpression("PreviewedExternalLayoutName",
_("Name of the previewed external layout"),
_("Returns the name of the external layout being "
"previewed from the editor"),
"",
"CppPlatform/Extensions/systeminfoicon.png")
.AddCodeOnlyParameter("currentScene", "");
extension extension
.AddCondition( .AddCondition(
"HasTouchScreen", "HasTouchScreen",

View File

@@ -39,6 +39,12 @@ class SystemInfoJsExtension : public gd::PlatformExtension {
GetAllConditions()["SystemInfo::IsPreview"] GetAllConditions()["SystemInfo::IsPreview"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js") .SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.SetFunctionName("gdjs.evtTools.systemInfo.isPreview"); .SetFunctionName("gdjs.evtTools.systemInfo.isPreview");
GetAllConditions()["SystemInfo::IsPreviewingAnExternalLayout"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.SetFunctionName("gdjs.evtTools.systemInfo.isPreviewingAnExternalLayout");
GetAllExpressions()["SystemInfo::PreviewedExternalLayoutName"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.SetFunctionName("gdjs.evtTools.systemInfo.getPreviewedExternalLayoutName");
GetAllConditions()["SystemInfo::HasTouchScreen"] GetAllConditions()["SystemInfo::HasTouchScreen"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js") .SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.SetFunctionName("gdjs.evtTools.systemInfo.hasTouchScreen"); .SetFunctionName("gdjs.evtTools.systemInfo.hasTouchScreen");

View File

@@ -81,6 +81,34 @@ namespace gdjs {
): boolean => { ): boolean => {
return instanceContainer.getGame().isPreview(); return instanceContainer.getGame().isPreview();
}; };
/**
* Check if the game is running as a preview, launched from an editor,
* for an external layout.
* @param instanceContainer The current container.
* @returns true if the game is running as a preview for an external layout.
*/
export const isPreviewingAnExternalLayout = (
instanceContainer: gdjs.RuntimeInstanceContainer
): boolean => {
const game = instanceContainer.getGame();
return game.isPreview() && !!game.getPreviewedExternalLayoutName();
};
/**
* If the game is running as a preview, launched from an editor,
* this returns the name of the external layout being previewed - if any.
* Otherwise, returns an empty string.
*
* @param instanceContainer The current container.
* @returns the name of the previewed external layout.
*/
export const getPreviewedExternalLayoutName = (
instanceContainer: gdjs.RuntimeInstanceContainer
): string => {
const game = instanceContainer.getGame();
return game.getPreviewedExternalLayoutName();
};
} }
} }
} }

View File

@@ -186,7 +186,7 @@ namespace gdjs {
/** /**
* Allow to specify an external layout to insert in the first scene. * Allow to specify an external layout to insert in the first scene.
*/ */
_injectExternalLayout: any; _injectExternalLayout: string;
_options: RuntimeGameOptions; _options: RuntimeGameOptions;
/** /**
@@ -1078,6 +1078,15 @@ namespace gdjs {
return this._isPreview; return this._isPreview;
} }
/**
* Return the name of the external layout that was automatically created at position 0;0
* for this preview, if any.
* @returns the name of the external layout, or an empty string if none was injected.
*/
getPreviewedExternalLayoutName(): string {
return this._injectExternalLayout;
}
/** /**
* Check if the game should call GDevelop development APIs or not. * Check if the game should call GDevelop development APIs or not.
* *