-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Screenshot extension (for games running on Windows/macOS/Linux) (#…
…806) * Add functionality to take screenshots, when running on Electron.
- Loading branch information
Showing
8 changed files
with
334 additions
and
3 deletions.
There are no files selected for viewing
224 changes: 224 additions & 0 deletions
224
Binaries/Output/Release_Windows/JsPlatform/Extensions/take_screenshot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+483 Bytes
Binaries/Output/Release_Windows/JsPlatform/Extensions/take_screenshot16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+697 Bytes
Binaries/Output/Release_Windows/JsPlatform/Extensions/take_screenshot24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+885 Bytes
Binaries/Output/Release_Windows/JsPlatform/Extensions/take_screenshot32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* This is a declaration of an extension for GDevelop 5. | ||
* | ||
* ℹ️ Run `node import-GDJS-Runtime.js` (in newIDE/app/scripts) if you make any change | ||
* to this extension file or to any other *.js file that you reference inside. | ||
* | ||
* The file must be named "JsExtension.js", otherwise GDevelop won't load it. | ||
* ⚠️ If you make a change and the extension is not loaded, open the developer console | ||
* and search for any errors. | ||
* | ||
* More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md | ||
*/ | ||
module.exports = { | ||
createExtension: function (t, gd) { | ||
const extension = new gd.PlatformExtension(); | ||
extension.setExtensionInformation( | ||
"Screenshot", | ||
t("Screenshot"), | ||
t( | ||
"Save screenshots of a running game." | ||
), | ||
"Matthias Meike", | ||
"Open source (MIT License)" | ||
).setExtensionHelpPath("/all-features/screenshot"); | ||
|
||
extension | ||
.addAction( | ||
"TakeScreenshot", | ||
t("Take screenshot"), | ||
t("Take a screenshot of the game, and save it to a png file (supported only when running on Windows/Linux/macOS)."), | ||
t("Take a screenshot and save at _PARAM1_"), | ||
t("Screenshot"), | ||
"JsPlatform/Extensions/take_screenshot24.png", | ||
"JsPlatform/Extensions/take_screenshot32.png" | ||
) | ||
.addCodeOnlyParameter('currentScene', '') | ||
.addParameter("string", t("Save path"), "", false) | ||
.getCodeExtraInformation() | ||
.setIncludeFile( | ||
"Extensions/Screenshot/screenshottools.js" | ||
) | ||
.setFunctionName("gdjs.screenshot.takeScreenshot"); | ||
|
||
return extension; | ||
}, | ||
runExtensionSanityTests: function (gd, extension) { return []; }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @memberof gdjs | ||
* @class screenshot | ||
* @static | ||
* @private | ||
*/ | ||
|
||
gdjs.screenshot = {} | ||
|
||
/** | ||
* Save a screenshot of the game. | ||
* @param {string} savepath The path where to save the screenshot | ||
*/ | ||
gdjs.screenshot.takeScreenshot = function (runtimeScene, savePath) { | ||
const electron = runtimeScene.getGame().getRenderer().getElectron(); | ||
|
||
if (electron) { | ||
const fileSystem = electron.remote.require("fs"); | ||
const canvas = runtimeScene.getGame().getRenderer().getCanvas(); | ||
|
||
if (canvas) { | ||
const content = canvas.toDataURL('image/png').replace('data:image/png;base64,', ''); | ||
if (savePath.toLowerCase().indexOf('.png') == -1) savePath += '.png'; | ||
|
||
fileSystem.writeFile(savePath, content, 'base64', (err) => { | ||
if (err) { | ||
console.error("Unable to save the screenshot at path: " + savePath); | ||
} | ||
}); | ||
} else { | ||
console.error("Screenshot are not supported on rendering engines without canvas.") | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters