Repository navigation
Expand file tree
/
Copy pathJsExtension.js
More file actions
548 lines (522 loc) · 20 KB
/
Copy pathJsExtension.js
File metadata and controls
548 lines (522 loc) · 20 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
//@ts-check
/// <reference path="../JsExtensionTypes.d.ts" />
/**
* This is a declaration of an extension for GDevelop 5.
*
* ℹ️ Changes in this file are watched and automatically imported if the editor
* is running. You can also manually run `node import-GDJS-Runtime.js` (in newIDE/app/scripts).
*
* 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
*/
/** @type {ExtensionModule} */
module.exports = {
createExtension: function (_, gd) {
const extension = new gd.PlatformExtension();
extension
.setExtensionInformation(
'FileSystem',
_('File system'),
_('Access the filesystem of the operating system.'),
'Matthias Meike',
'Open source (MIT License)'
)
.setExtensionHelpPath('/all-features/filesystem')
.setCategory('Advanced');
extension
.addInstructionOrExpressionGroupMetadata(_('File system'))
.setIcon('JsPlatform/Extensions/filesystem_create_folder32.png');
extension
.addCondition(
'PathExists',
_('File or directory exists'),
_('Check if the file or directory exists.'),
_('The path _PARAM0_ exists'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_path_exists32.png',
'JsPlatform/Extensions/filesystem_path_exists32.png'
)
.addParameter('string', _('Path to file or directory'), '', false)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.pathExists');
extension
.addAction(
'MakeDirectory',
_('Create a directory'),
_('Create a new directory at the specified path.'),
_('Create directory _PARAM0_'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_create_folder32.png',
'JsPlatform/Extensions/filesystem_create_folder32.png'
)
.addParameter('string', _('Directory'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.makeDirectory')
.setAsyncFunctionName('gdjs.fileSystem.makeDirectoryAsync');
extension
.addAction(
'SaveStringToFileSync',
_('Save a text into a file'),
_(
'Save a text into a file. Only use this on small files to avoid any lag or freeze during the game execution.'
),
_('Save _PARAM0_ into file _PARAM1_'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('string', _('String (text)'), '', false)
.addParameter('string', _('Save path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.saveStringToFile');
extension
.addAction(
'SaveStringToFileAsync',
_('Save a text into a file (Async)'),
_(
"Save a text into a file asynchronously. Use this for large files to avoid any lag or freeze during game execution. The 'result' variable gets updated when the operation has finished."
),
_('Save _PARAM0_ into file _PARAM1_'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('string', _('String (text)'), '', false)
.addParameter('string', _('Save path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.saveStringToFileAsync')
.setAsyncFunctionName('gdjs.fileSystem.saveStringToFileAsyncTask');
extension
.addAction(
'SaveVariableToJSONFileSync',
_('Save a scene variable into a JSON file'),
_(
'Save a scene variable (including, for structure, all the children) into a file in JSON format. Only use this on small files to avoid any lag or freeze during the game execution.'
),
_('Save scene variable _PARAM0_ into file _PARAM1_ as JSON'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Save path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.saveVariableToJSONFile');
extension
.addAction(
'SaveVariableToJSONFileAsync',
_('Save a scene variable into a JSON file (Async)'),
_(
"Save the scene variable (including, for structures, all the children) into a file in JSON format, asynchronously. Use this for large files to avoid any lag or freeze during game execution. The 'result' variable gets updated when the operation has finished."
),
_('Save scene variable _PARAM0_ into file _PARAM1_ as JSON'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Save path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.saveVariableToJSONFileAsync')
.setAsyncFunctionName('gdjs.fileSystem.saveVariableToJSONFileAsyncTask');
extension
.addAction(
'LoadStringFromFileAsync',
_('Load a text from a file (Async)'),
_(
"Load a text from a file, asynchronously. Use this for large files to avoid any lag or freeze during game execution. The content of the file will be available in the scene variable after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished."
),
_('Load text from _PARAM1_ into scene variable _PARAM0_ (Async)'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_load_file32.png',
'JsPlatform/Extensions/filesystem_load_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Load path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.addParameter(
'yesorno',
_('Normalize the file content (recommended)'),
'',
true
)
.setParameterLongDescription(
_(
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
)
)
.setDefaultValue('yes')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.loadStringFromFileAsync')
.setAsyncFunctionName('gdjs.fileSystem.loadStringFromFileAsyncTask');
extension
.addAction(
'LoadStringFromFileSync',
_('Load a text from a file'),
_(
'Load a text from a file. Only use this on small files to avoid any lag or freeze during the game execution.'
),
_('Load text from _PARAM1_ into scene variable _PARAM0_'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_load_file32.png',
'JsPlatform/Extensions/filesystem_load_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Load path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.addParameter(
'yesorno',
_('Normalize the file content (recommended)'),
'',
true
)
.setParameterLongDescription(
_(
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
)
)
.setDefaultValue('yes')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.loadStringFromFile');
extension
.addAction(
'LoadVariableFromJSONFileSync',
_('Load a scene variable from a JSON file'),
_(
'Load a JSON formatted text from a file and convert it to a scene variable (potentially a structure variable with children). Only use this on small files to avoid any lag or freeze during the game execution.'
),
_('Load JSON from _PARAM1_ into scene variable _PARAM0_'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Load path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.addParameter(
'yesorno',
_('Normalize the file content (recommended)'),
'',
true
)
.setParameterLongDescription(
_(
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
)
)
.setDefaultValue('yes')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.loadVariableFromJSONFile');
extension
.addAction(
'LoadVariableFromJSONFileAsync',
_('Load a scene variable from a JSON file (Async)'),
_(
"Load a JSON formatted text from a file and convert it to a scene variable (potentially a structure variable with children), asynchronously. Use this for large files to avoid any lag or freeze during game execution. The content of the file will be available as a scene variable after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished."
),
_('Load JSON from _PARAM1_ into scene variable _PARAM0_'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_save_file32.png',
'JsPlatform/Extensions/filesystem_save_file32.png'
)
.addParameter('scenevar', _('Scene variable'), '', false)
.addParameter('string', _('Load path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.addParameter(
'yesorno',
_('Normalize the file content (recommended)'),
'',
true
)
.setParameterLongDescription(
_(
'This replaces Windows new lines characters ("CRLF") by a single new line character.'
)
)
.setDefaultValue('yes')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.loadVariableFromJSONFileAsync')
.setAsyncFunctionName(
'gdjs.fileSystem.loadVariableFromJSONFileAsyncTask'
);
extension
.addAction(
'DeleteFile',
_('Delete a file'),
_('Delete a file from the filesystem.'),
_('Delete the file _PARAM0_'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_delete_file32.png',
'JsPlatform/Extensions/filesystem_delete_file32.png'
)
.addParameter('string', _('File path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.deleteFile');
extension
.addAction(
'DeleteFileAsync',
_('Delete a file (Async)'),
_(
'Delete a file from the filesystem asynchronously. The option result variable will be updated once the file is deleted.'
),
_('Delete the file _PARAM0_'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_delete_file32.png',
'JsPlatform/Extensions/filesystem_delete_file32.png'
)
.addParameter('string', _('File path'), '', false)
.addParameter(
'scenevar',
_(
"(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occurred."
),
'',
true
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.deleteFileAsync')
.setAsyncFunctionName('gdjs.fileSystem.deleteFileAsyncTask');
extension
.addStrExpression(
'DesktopPath',
_('Desktop folder'),
_('Get the path to the desktop folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getDesktopPath');
extension
.addStrExpression(
'DocumentsPath',
_('Documents folder'),
_('Get the path to the documents folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getDocumentsPath');
extension
.addStrExpression(
'PicturesPath',
_('Pictures folder'),
_('Get the path to the pictures folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getPicturesPath');
extension
.addStrExpression(
'ExecutablePath',
_('Game executable file'),
_('Get the path to this game executable file.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getExecutablePath');
extension
.addStrExpression(
'ExecutableFolderPath',
_('Game executable folder'),
_('Get the path to this game executable folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getExecutableFolderPath');
extension
.addStrExpression(
'UserdataPath',
_('Userdata folder (for application settings)'),
_('Get the path to userdata folder (for application settings).'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getUserdataPath');
extension
.addStrExpression(
'UserHomePath',
_("User's Home folder"),
_('Get the path to the user home folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getUserHomePath');
extension
.addStrExpression(
'TempPath',
_('Temp folder'),
_('Get the path to temp folder.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addCodeOnlyParameter('currentScene', '')
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getTempPath');
extension
.addStrExpression(
'PathDelimiter',
_('Path delimiter'),
_('Get the operating system path delimiter.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getPathDelimiter');
extension
.addStrExpression(
'DirectoryName',
_('Get directory name from a path'),
_(
'Returns the portion of the path that represents the directories, without the ending file name.'
),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addParameter('string', _('File or folder path'), '', false)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getDirectoryName');
extension
.addStrExpression(
'FileName',
_('Get file name from a path'),
_('Returns the name of the file with its extension, if any.'),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addParameter('string', _('File path'), '', false)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getFileName');
extension
.addStrExpression(
'ExtensionName',
_('Get the extension from a file path'),
_(
'Returns the extension of the file designated by the given path, including the extension period. For example: ".txt".'
),
_('Windows, Linux, MacOS'),
'JsPlatform/Extensions/filesystem_folder32.png'
)
.addParameter('string', _('File path'), '', false)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.getExtensionName');
return extension;
},
runExtensionSanityTests: function (gd, extension) {
return [];
},
};