Skip to content
Open
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
216 changes: 216 additions & 0 deletions extensions/community/ScreenCapToVariable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"author": "",
"category": "Advanced",
"extensionNamespace": "",
"fullName": "Screen Cap to Variable",
"gdevelopVersion": "",
"helpPath": "",
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLWNhbWVyYS1pcmlzIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTEzLjczLDE1TDkuODMsMjEuNzZDMTAuNTMsMjEuOTEgMTEuMjUsMjIgMTIsMjJDMTQuNCwyMiAxNi42LDIxLjE1IDE4LjMyLDE5Ljc1TDE0LjY2LDEzLjRNMi40NiwxNUMzLjM4LDE3LjkyIDUuNjEsMjAuMjYgOC40NSwyMS4zNEwxMi4xMiwxNU04LjU0LDEyTDQuNjQsNS4yNUMzLDcgMiw5LjM5IDIsMTJDMiwxMi42OCAyLjA3LDEzLjM1IDIuMiwxNEg5LjY5TTIxLjgsMTBIMTQuMzFMMTQuNiwxMC41TDE5LjM2LDE4Ljc1QzIxLDE2Ljk3IDIyLDE0LjYgMjIsMTJDMjIsMTEuMzEgMjEuOTMsMTAuNjQgMjEuOCwxME0yMS41NCw5QzIwLjYyLDYuMDcgMTguMzksMy43NCAxNS41NSwyLjY2TDExLjg4LDlNOS40LDEwLjVMMTQuMTcsMi4yNEMxMy40NywyLjA5IDEyLjc1LDIgMTIsMkM5LjYsMiA3LjQsMi44NCA1LjY4LDQuMjVMOS4zNCwxMC42TDkuNCwxMC41WiIgLz48L3N2Zz4=",
"name": "ScreenCapToVariable",
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/ef66e1e2ef00223425b06ff34aaa9e7f41ea19971b1e5a1709307fadf3d19ca4_camera-iris.svg",
"shortDescription": "Captures part of the screen and saves it to text variable, and loads text encoded photos to sprite.",
"version": "0.0.1",
"description": [
"\"CaptureScreenArea\" lets you select an origin and size of a part of the screen to save into a text scene variable in Base64 jpeg format.",
"\"LoadBase64ToSprite\" replaces a sprite graphic with an image saved in a variable as base64 text."
],
"tags": [
"Capture",
"Base64",
"Text to sprite",
"Screen Capture",
"Image to Variable"
],
"authorIds": [
"J4ErxW9i1KSmpS8NJ55WqWwe8TT2"
],
"dependencies": [],
"globalVariables": [],
"sceneVariables": [],
"eventsFunctions": [
{
"description": "Capture a rectangular area of the screen to a variable.",
"fullName": "capture screen area",
"functionType": "Action",
"group": "Screen Capture",
"name": "CaptureScreenArea",
"sentence": "Capture screen area from _PARAM1_, _PARAM2_ with size _PARAM3_x_PARAM4_ into variable _PARAM5_",
"events": [
{
"type": "BuiltinCommonInstructions::Standard",
"conditions": [],
"actions": []
},
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"const startX = eventsFunctionContext.getArgument(\"StartX\");",
"const startY = eventsFunctionContext.getArgument(\"StartY\");",
"const width = eventsFunctionContext.getArgument(\"Width\");",
"const height = eventsFunctionContext.getArgument(\"Height\");",
"const variable = eventsFunctionContext.getArgument(\"VariableName\");",
"",
"try {",
" const canvas = document.querySelector('canvas');",
" ",
" if (!canvas) {",
" throw new Error(\"No canvas found\");",
" }",
" ",
" const tempCanvas = document.createElement('canvas');",
" const tempCtx = tempCanvas.getContext('2d');",
" ",
" tempCanvas.width = width;",
" tempCanvas.height = height;",
" ",
" tempCtx.drawImage(canvas, startX, startY, width, height, 0, 0, width, height);",
" ",
" const base64Data = tempCanvas.toDataURL('image/jpeg', 0.8);",
"",
" // Set the variable directly (not by name)",
" variable.setString(base64Data);",
" ",
" console.log(\"Screen capture successful! Data size:\", base64Data.length, \"characters\");",
" ",
"} catch (error) {",
" console.error('Screen capture failed:', error);",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": false
}
],
"parameters": [
{
"description": "StartX",
"name": "StartX",
"type": "expression"
},
{
"description": "StartY",
"name": "StartY",
"type": "expression"
},
{
"description": "Width",
"name": "Width",
"type": "expression"
},
{
"description": "Height",
"name": "Height",
"type": "expression"
},
{
"description": "Variable to store image data",
"name": "VariableName",
"type": "variable"
}
],
"objectGroups": []
},
{
"description": "Load base64 image data into a sprite.",
"fullName": "Load base64 to sprite",
"functionType": "Action",
"group": "Screen Capture",
"name": "LoadBase64ToSprite",
"sentence": "Load base64 data from variable _PARAM1_ into sprite _PARAM2_",
"events": [
{
"type": "BuiltinCommonInstructions::Standard",
"conditions": [],
"actions": []
},
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"console.log(\"LoadBase64ToSprite function started\");",
"",
"try {",
" const variable = eventsFunctionContext.getArgument(\"Variable\");",
" const objects = eventsFunctionContext.getObjects(\"Object\");",
" ",
" const base64Data = variable.getAsString();",
" console.log(\"Base64 data length:\", base64Data.length);",
" ",
" if (objects.length > 0 && base64Data && base64Data.startsWith(\"data:image/\")) {",
" console.log(\"Creating Image object...\");",
" const img = new Image();",
" ",
" img.onload = function () {",
" console.log(\"Image loaded successfully!\");",
" console.log(\"Image dimensions:\", img.width, \"x\", img.height);",
" ",
" // Test PIXI texture creation",
" try {",
" console.log(\"Creating PIXI texture...\");",
" const texture = PIXI.Texture.from(img);",
" console.log(\"PIXI texture created successfully:\", texture);",
" ",
" // Test applying to objects",
" console.log(\"Applying texture to objects...\");",
" for (let i = 0; i < objects.length; i++) {",
" const obj = objects[i];",
" console.log(\"Processing object\", i);",
" ",
" const rendererObject = obj.getRendererObject();",
" console.log(\"Renderer object:\", rendererObject);",
" ",
" if (rendererObject && rendererObject.texture) {",
" rendererObject.texture = texture;",
" console.log(\"Texture applied to object\", i);",
" } else {",
" console.warn(\"Object\", i, \"renderer not found or invalid\");",
" }",
" }",
" ",
" console.log(\"SUCCESS: Process completed\");",
" ",
" } catch (pixiError) {",
" console.error(\"PIXI texture error:\", pixiError);",
" }",
" };",
" ",
" img.onerror = function () {",
" console.error(\"ERROR: Could not load image from base64 data\");",
" };",
" ",
" console.log(\"Setting image src...\");",
" img.src = base64Data;",
" ",
" } else {",
" console.error(\"ERROR: Requirements not met\");",
" console.log(\"Objects found:\", objects.length);",
" console.log(\"Base64 valid:\", base64Data ? base64Data.startsWith(\"data:image/\") : false);",
" }",
" ",
"} catch (error) {",
" console.error(\"Error in main function:\", error);",
"}"
],
"parameterObjects": "Object",
"useStrict": true,
"eventsSheetExpanded": false
}
],
"parameters": [
{
"description": "Variable containing base64 image data",
"name": "Variable",
"type": "variable"
},
{
"description": "Sprite object to load image into",
"name": "Object",
"supplementaryInformation": "Sprite",
"type": "objectList"
}
],
"objectGroups": []
}
],
"eventsBasedBehaviors": [],
"eventsBasedObjects": []
}