Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a condition (and expression) to check if an external layout is being previewed (and which one) #5672

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions Extensions/SystemInfo/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ void DeclareSystemInfoExtension(gd::PlatformExtension& extension) {

.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
.AddCondition(
"HasTouchScreen",
Expand Down
6 changes: 6 additions & 0 deletions Extensions/SystemInfo/JsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class SystemInfoJsExtension : public gd::PlatformExtension {
GetAllConditions()["SystemInfo::IsPreview"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.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"]
.SetIncludeFile("Extensions/SystemInfo/systeminfotools.js")
.SetFunctionName("gdjs.evtTools.systemInfo.hasTouchScreen");
Expand Down
28 changes: 28 additions & 0 deletions Extensions/SystemInfo/systeminfotools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ namespace gdjs {
): boolean => {
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();
};
}
}
}
11 changes: 10 additions & 1 deletion GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace gdjs {
/**
* Allow to specify an external layout to insert in the first scene.
*/
_injectExternalLayout: any;
_injectExternalLayout: string;
_options: RuntimeGameOptions;

/**
Expand Down Expand Up @@ -1078,6 +1078,15 @@ namespace gdjs {
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.
*
Expand Down