-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathScreenCapToVariable.json
More file actions
216 lines (216 loc) · 9.33 KB
/
ScreenCapToVariable.json
File metadata and controls
216 lines (216 loc) · 9.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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": []
}