From e2125d9b152451c2797f2caa8e2dfc82abe42609 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Wed, 16 Jan 2019 19:11:48 +0100 Subject: [PATCH 01/10] Add 'save text to file' function to filesystem extension --- .../Extensions/filesystem_save_file.svg | 203 ++++++++++++++++++ .../Extensions/filesystem_save_file16.png | Bin 0 -> 545 bytes .../Extensions/filesystem_save_file24.png | Bin 0 -> 788 bytes .../Extensions/filesystem_save_file32.png | Bin 0 -> 1039 bytes Extensions/FileSystem/JsExtension.js | 54 +++-- Extensions/FileSystem/filesystemtools.js | 17 ++ 6 files changed, 256 insertions(+), 18 deletions(-) create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file.svg create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file16.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file24.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file32.png diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file.svg b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file.svg new file mode 100644 index 000000000000..8e0f3083cd30 --- /dev/null +++ b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file.svg @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file16.png b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_save_file16.png new file mode 100644 index 0000000000000000000000000000000000000000..08266fb69d9e92e8c4105c5431ba968e36847d32 GIT binary patch literal 545 zcmV++0^a?JP)a&DhZ&evDY=~1LxVSyTH`V{V%JjZnw{5r%=dCQ#bb?GutTl jo$Ux=X>)T67Z2wWP)(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H10+C5XK~zYIwUtdsR8bg)pZlwhqtVcae`#uNti+WDNw_M)zzT|@ zOmyKUOe<*P#@vXsQ(8t~5QSifDYOd`2`a>bFe(kD9A|8Bu0J!*+_jB?0r`K*#@Wn_!j+4Pk%yI<>zf}&4vB_j{@8I zWXDbkBuNrA)iroL2Xs~A4O>oQ*8l)b(`jjGMOKv3o9#^x_Z$G=^?JE-`6`k`b9;N^ z#XSSaGWY|2rluy5B#FGdd=yoCa;x)tLA*~*)L^UDA}gEf>gwYR4Gl6l_!Iyk1hy?y zYlYjuoqq=09k_-^!&Fop-Q?-%=?*Ui0<$Sikl{*WBP00d+upy^*zPac zNsbfD1-@ZfCWyF20kgi(D2hsvw=8Miae~R233^95i0H=OwTN!eJJP}A%!E_i8PHJE zNO|rtkgT|rMX9%fhMLCR0|0KEzK1KCgRlj{7PvNYXgkxrlW1~4IPAmcA7^1PKz4w0ErK)NdzMNa%aCH)T+Strw7M5enanJuZd zylBiDMo1ZbF`QB}!w4xtFrN_M@yv}bFBjh*AAen!3LqAXz4CbGMpN2ds`?Fha^^20 SpK$sB000004g z`d|eqZKM)v3~fXSQDI5Z2OmUS@JSycg;tP0_(dof5Pj*JN(&;zvTbS6s!-ab_(9U_ z+H7`rc4qGNAvDn@WOvpz`rv^J!g_0BCM*=Fp)bl+pnqeP;&-27K!Z z0MOeTHD20#6J8J};l-E|$dZs_Kf{{?NO=ImE|{@JIX!dBx-QlCF8@dc@ZI!9o;$vmaHyF#hfWeQ zt4q=?c>*D`nirpV4ZmSf8}VV7%dLhfscVz?4L>7~zgn`nCjfx^Te>)~YZxcJa&UIq z&w*Ws>4@}rk@S8B_Vqo@)}~&Z%<>l48Q2o;Vqf2&S2^zhO4*D&HilWK#kLeqK@qTO z7~T6aN_oEviXKA8$uc{4fmG@WT3KkV0XVq5mk-Z<3Bcg)9ZXM60w9DyN|XBVHkuk@ z7)Gdk09O^b`ont&VIZZ6lvUK$v||RFX!Qjc^0x!fy*Y;K7O?U&+@8M%T61eQ$?VLx zbauW}K7bSkh7rPX^JrB-_yWvlu9LTBk%l^Xb+(mM^pRt`Bj*|iO(sl?T00F{>-w0Aw9i^!uMpbCTn&w3T?nG6n zg|<*jDW#s{zjqZY#e$G9JvGIpOBX6)GJWF)07A%2QGmwAsmrN!^jtD|es?l?z9ImN z=Hi?B`s-I# { + if (err) { + console.error("Unable to save the text to path: '" + savePath + "' " + err); + } + }); + } +} + /** * Check if the file or directory exists. * @param {string} path The path to the file or directory From 2f595125ccc8813d24bc4ed933a55c438dc92d6b Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Sat, 19 Jan 2019 16:15:44 +0100 Subject: [PATCH 02/10] Add delete file functionality Rename "text" to "string" in javascript functions Make "err" a separate argument in console output --- .../Extensions/filesystem_delete_file.svg | 206 ++++++++++++++++++ .../Extensions/filesystem_delete_file16.png | Bin 0 -> 556 bytes .../Extensions/filesystem_delete_file24.png | Bin 0 -> 741 bytes .../Extensions/filesystem_delete_file32.png | Bin 0 -> 974 bytes Extensions/FileSystem/JsExtension.js | 23 +- Extensions/FileSystem/filesystemtools.js | 24 +- 6 files changed, 247 insertions(+), 6 deletions(-) create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file.svg create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file16.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file24.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file32.png diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file.svg b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file.svg new file mode 100644 index 000000000000..46a5773e07f3 --- /dev/null +++ b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file.svg @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file16.png b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_delete_file16.png new file mode 100644 index 0000000000000000000000000000000000000000..1dbeb988ce86fc8e23e53f89b19641d79e387544 GIT binary patch literal 556 zcmV+{0@MA8P)|L){sDzuA;pBUJ0dAR#w7{O%A7e;a~3;0uM6#m!|TVl-i!D7KF{ZU-skP* zP@!OOpn>NJfklQv9fU~Nkw_$G^-9U1$)Op^;|VyO)rK|cK~1~!`PU492CG-n)bw!d z>gtRdh379T9$%rMi2xlR_eZUDJd;={4(RUgLAA@(7Yz3G{vQB<2n2(J0nX`iFOH1( z>q>D}L7`B<=0+T<`UqcVJ7Vjr*b{aEfDk*D0dz3|rzhvw**SpQE#dxNg`(7AY%~M_ zxV^c-d~{Z0b`V`yg08>8;i$svTMmAIKNO{gd9^PyXlZRmDs>0Dokvq+J&ukN*xx_= zJHYF0fh@}qMHe(J3r)-7luzN=kM+r+ltR~Ypp-HTe(WHfRuS0000(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H10%A!-K~zYI#gj`&RACgye|P5IX>c*Y;A4D%;zCSaNDB>;&{~uj z)Fvt_MTItLnn4f-4YqL6&RK`$3}sCi2};W#7eU!*g(ybWSl~RG=HBs<-kEz_w9&l7 zOrz3&cQ}vVIp_Nh?6HK+hSOOuMx(_}NwUv9eCrVZ%szIa-)SRdCN zK4M7)cr*Eyn4+L-iKc-8_js~6akHW8rXrhdf1>H+sZ{k@3Iv&*oxvoUo^^J%7P(x5 zA)`1`%1TKj2m-Y=wb$wQwl3kk$mMsxtcg1(TCgl$4a>a1`SAe`R?&Msv&AbO%ok@OYl`{o4}N)dvX# z0{DFIIDX>19#*S$oA1NN_bH3RE*#o_2NP X%u3t6kiLOlM1|29OR>oG)6zLqcl+>gpR543x zXM#0%w+FH^Y-@5c&7SNH2gm0=pZEK9U%vMP{$q*dihjS}4o~+;lJS-mGeb~qlN>|6 zz28ja4WMc7DSsw6{DNsVTM1t@ltenSV6H!ZejuI~fZu=2CnQ2U-)-WZhV7QZFJ8Pr zCi4Q|L4|8`y{2hKwi)Hsf+XQIff}!u9XouM00sxY`v+iKA`$)y_$=FuWGNwwgaGe` zjZ{@tgW%+;Q=fcXQ~&^*qHz59r>LqOgc}uT&u<7k;M}N@)01g~HL`}_lFhy5)_pu|(^(=V`tY|76;rlB;(bd(7$K$57 zw3L~dX?nltS?o!rp1nK~BGBD^_{O<&!AJl0$ZG}W=AP2m7oex-OX5$G419YDfcEwS ztaYy=ok}epLI@lV2biW!2)XH1FH0++>pIu2-Q>rsKT}mzOqT#=(#Fb79~z zcDo(BU8V2qz_Pt9Eju}UW-jm}sK&lvzfQDjO=N>;o+ zKR-_<^V~APs=kW<2gpUQ-2=L=Gcz3{7MsN|vi{x`9$;kTE`k0aHk(2wlPNxcuIp4( zxNx~D2#3R@QmGYt7Zw%@53tU?7D*Ds<4=$z!RTn{wPsCCjfDl+x@`+*&Yrex`bGeT z!80MjbTrDnd!q#jnT|vN5JLJZD?nvsbS#ndj)X#YT0)^a1p#;&E`BX9fB5^7`f|;h w)}ba6_B|lV3lnc9U9RW1G;J`yow}O(8&U)iE;MLk!~g&Q07*qoM6N<$g68tG { if (err) { - console.error("Unable to save the text to path: '" + savePath + "' " + err); + console.error("Unable to save the text to path: '" + savePath + "': ", err); } }); } } +/** + * Delete a file from the filesystem. + * @param {string} filePath The absolute path on the filesystem + */ +gdjs.fileSystem.deleteFile = function (filePath) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + + if (fileSystem) { + if (fileSystem.existsSync(filePath)) { + fileSystem.unlink(filePath, (err) => { + if (err) { + console.error("Unable to delete the file: '" + filePath + "': ", err); + } + }); + } + } +} + /** * Check if the file or directory exists. * @param {string} path The path to the file or directory From 0ce7e74b78750fd4a31928e5c302c66ef9c14e08 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Sun, 20 Jan 2019 16:19:28 +0100 Subject: [PATCH 03/10] Add load string into scene variable functions - Sync and Async --- .../Extensions/filesystem_load_file.svg | 203 ++++++++++++++++++ .../Extensions/filesystem_load_file16.png | Bin 0 -> 544 bytes .../Extensions/filesystem_load_file24.png | Bin 0 -> 795 bytes .../Extensions/filesystem_load_file32.png | Bin 0 -> 1039 bytes Extensions/FileSystem/JsExtension.js | 36 ++++ Extensions/FileSystem/filesystemtools.js | 46 ++++ 6 files changed, 285 insertions(+) create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file.svg create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file16.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file24.png create mode 100644 Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file32.png diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file.svg b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file.svg new file mode 100644 index 000000000000..bd87da67dbab --- /dev/null +++ b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file.svg @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file16.png b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file16.png new file mode 100644 index 0000000000000000000000000000000000000000..fbba00ea9a613fe39ee8a67c6ecd5a227395c1cc GIT binary patch literal 544 zcmV+*0^j|KP)ZG*rgy9M4ZIIuT6sqDx&c_njrV%IEe9by=r{m4ClP>dHC_d zt6(7(>!?vxA+VwA@`Dg%d+~TYXRqa(2Znk^%1TS4UawELH=U%9OEm576sWP+^86U? zolhh-q;6b2I|~cH<-lN6_V;&B+yALA8m%bM($b30?{AOA+S}eQ0EA1>)fH8|{*qsP zecjdh_d-4ggCXYs&avWJ1`wi{8Q|NSf}cy90CYBeCLE3ckV+<*nw~g+Gr?-&h}rE! z3@Hf*Khjtqa_n=Q!DaT2vHzP~nu3gUF}}FPSteV!AeFwL+^rxD9ck!PdWtwWzb;(R zP#d5*@)Wr_5~86t;3%-oKyq;Sk6bRzO~y@y`ryCGY_YSuhR0I@gkKXV2;oH(x%pD3 z@%7U~*)R-*>P843hNiqGfI!uE$Ec5_l1XQQshjJwe`Xq;mdQ#sdn-)cTz|@J;iYx9 iq9{@u9i7~Nyx#-v7MCF2Bjk4g0000(^b8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H10+>leK~zYIwUtdsR8bVifA@Wij?YmTQv6D@Y$I+8(Vz$yxiYAQ zh0%x9qTHC)EQOE=TtqFD7A+#M4+=vQv{glrpwJf?ur6?;a+o?Nv$jhIp=@~wK`iP<_ea+3Mi@LgQ zhu5l8Je?9q2tjpKHNoH(pQbays@K>s06^D$oH=tAMOC+-Z)v=>=>UM7oE(ld97hOF zx3ru*vS|QCftm0OqoeN-LXe+dfU4>DFSMO1jIYxY8F;CxY7f1=J@oWE06q^au za1jWl1i1P1Edb{Z?54cDg7Wf;zs@^4E?cwV@R#^p(tvm4Q}m5~MM}x8(mbkm6eQJ` z)C}f-SX_EEgsB@u^Z-{L4-+<*HV5FklF;2}%qj*TKtNbE2;F;*e0CAP zi2cd=Wt7P|lj{Q`8wWJiR?;7;$8haGIm5N-57pCDTj>e#9CE<_``?TI2n1yL(>%>R z0hTqzVq^@q$63jz9FTHB2;uO zfJiXTwE;q*wDc&B8)apAiY4nCv8ajT`~*Nv%OnukhT$(HJtGfQNxYxdoq?+OFfxlV zGK<$MTUV<#8k45Es16SFr(|ZDi>j1NCIke76N3v2C0B=rUe=@nh{a+rg29Qwlx~-* ZegRz$>hzjXxP|}#002ovPDHLkV1iBVV8Q?Z literal 0 HcmV?d00001 diff --git a/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file32.png b/Binaries/Output/Release_Windows/JsPlatform/Extensions/filesystem_load_file32.png new file mode 100644 index 0000000000000000000000000000000000000000..dd6b5456587388fbfe7b90c42dd9c594d6b97498 GIT binary patch literal 1039 zcmV+q1n~QbP))@+NKCCjDUjoOKs2bh@?<1r;~E zQy3FR89Lm=36o&xZg!t51urVQXhEDGXve^UtX^zvP-Vj@Vo5DlY=zc-jLd1<)V6tJ zk~imgQCqjQHf@@Ae|X{Ld7kt9e>{hC-WMLQ#9F~{IP8Y`gHo!}%`{VjTBkHGcXWL4 zYu*5n$RT5PZud>JequA`D-ESc+G$AUI5|ni54M=KHhqOeUCo2Df0^#KEt*% z0K)w#H`?0T96JgC z(A?a@(@#AE&{$n-e!SxV07qUtN?lz&Xz^-$`-xZ9s#$dkwj!U;$E{mabiDWOO3bnn zOD{rv(%$}Z-??)a@7%qnpc6QJ_y`r1RU|EI# zQ2qc?7#M~ZJNq|Ur4bGn3yb4~o-O9BLjk080iaYGr7|omPM}d}l|iF03=dMQKjd|@ zLP+*La+;)do9WpfNhV`t>?F3m2xzp{|JDgWfN { + if (err) { + console.error("Unable to load the file at path: '" + loadPath + "': ", err); + } + if (data) { + scenevar.setString(data); + } + }); + } + } +} + /** * Delete a file from the filesystem. * @param {string} filePath The absolute path on the filesystem From fa143e2211b8ade477e38a283c10678fe299f319 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Mon, 21 Jan 2019 19:26:05 +0100 Subject: [PATCH 04/10] Add optional result variable More pleasant formulation of descriptions --- Extensions/FileSystem/JsExtension.js | 9 ++- Extensions/FileSystem/filesystemtools.js | 86 ++++++++++++++---------- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Extensions/FileSystem/JsExtension.js b/Extensions/FileSystem/JsExtension.js index 291281976844..5a6fc257d4d5 100644 --- a/Extensions/FileSystem/JsExtension.js +++ b/Extensions/FileSystem/JsExtension.js @@ -53,6 +53,7 @@ module.exports = { "JsPlatform/Extensions/filesystem_create_folder32.png" ) .addParameter("string", t("Directory"), "", false) + .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) .getCodeExtraInformation() .setIncludeFile( "Extensions/FileSystem/filesystemtools.js" @@ -71,6 +72,7 @@ module.exports = { ) .addParameter("string", t("String (text)"), "", false) .addParameter("string", t("Save path"), "", false) + .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) .getCodeExtraInformation() .setIncludeFile( "Extensions/FileSystem/filesystemtools.js" @@ -81,7 +83,7 @@ module.exports = { .addAction( "LoadStringFromFileAsync", t("Load a text from a file (Async)"), - t("Load a text from a file asynchronously. Use this for large files to not delay game execution. (The content of the file will not be available immediately)"), + t("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 finised."), t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), t("Filesystem/Windows, Linux, MacOS"), "JsPlatform/Extensions/filesystem_load_file24.png", @@ -89,6 +91,7 @@ module.exports = { ) .addParameter("scenevar", t("Scene variable"), "", false) .addParameter("string", t("Load path"), "", false) + .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) .getCodeExtraInformation() .setIncludeFile( "Extensions/FileSystem/filesystemtools.js" @@ -99,7 +102,7 @@ module.exports = { .addAction( "LoadStringFromFileSync", t("Load a text from a file"), - t("Load a text from a file. Only use this on small files to not delay the game execution."), + t("Load a text from a file. Only use this on small files to avoid any lag or freeze during the the game execution."), t("Load text from _PARAM1_ into scene variable _PARAM0_"), t("Filesystem/Windows, Linux, MacOS"), "JsPlatform/Extensions/filesystem_load_file24.png", @@ -107,6 +110,7 @@ module.exports = { ) .addParameter("scenevar", t("Scene variable"), "", false) .addParameter("string", t("Load path"), "", false) + .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) .getCodeExtraInformation() .setIncludeFile( "Extensions/FileSystem/filesystemtools.js" @@ -124,6 +128,7 @@ module.exports = { "JsPlatform/Extensions/filesystem_delete_file32.png" ) .addParameter("string", t("File path"), "", false) + .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) .getCodeExtraInformation() .setIncludeFile( "Extensions/FileSystem/filesystemtools.js" diff --git a/Extensions/FileSystem/filesystemtools.js b/Extensions/FileSystem/filesystemtools.js index 28fe1139c23a..510e3312b0c1 100644 --- a/Extensions/FileSystem/filesystemtools.js +++ b/Extensions/FileSystem/filesystemtools.js @@ -114,95 +114,113 @@ gdjs.fileSystem.getPathDelimiter = function () { /** * Create a new directory at the given path. * @param {string} directory The path to create a new directory + * @param {scenevar} resultVar (optional) The variable to store the result of the operation */ -gdjs.fileSystem.makeDirectory = function (directory) { +gdjs.fileSystem.makeDirectory = function (directory, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'ok'; if (fileSystem) { - if (!fileSystem.existsSync(directory)) + try { fileSystem.mkdirSync(directory); + } + catch (err) { + console.error("Unable to create directory at: '" + directory + "': ", err); + result = 'error'; + } } + resultVar.setString(result); } /** * Save a string into a file. * @param {string} text The string to be saved * @param {string} savePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation */ -gdjs.fileSystem.saveStringToFile = function (text, savePath) { +gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'ok'; if (fileSystem) { fileSystem.writeFile(savePath, text, (err) => { if (err) { console.error("Unable to save the text to path: '" + savePath + "': ", err); + result = 'error'; } }); } + resultVar.setString(result); } /** * Load a string from a file into a scene variable. - * @param {scenevar} scenevar The scene variable to store the string + * @param {scenevar} stringVar The scene variable to store the string * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation */ -gdjs.fileSystem.loadStringFromFileSync = function (scenevar, loadPath) { +gdjs.fileSystem.loadStringFromFileSync = function (stringVar, loadPath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'ok'; if (fileSystem) { - if (fileSystem.existsSync(loadPath)) { - try { - const data = fileSystem.readFileSync(loadPath, 'utf8'); + try { + const data = fileSystem.readFileSync(loadPath, 'utf8'); - if (data) { - scenevar.setString(data); - } - } - catch (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); + if (data) { + stringVar.setString(data); } } + catch (err) { + console.error("Unable to load the file at path: '" + loadPath + "': ", err); + result = 'error'; + } } + resultVar.setString(result); } /** * Load a string from a file into a scene variable asyncrounousely. - * @param {scenevar} scenevar The scene variable to store the string + * @param {scenevar} stringVar The scene variable to store the string * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation */ -gdjs.fileSystem.loadStringFromFileAsync = function (scenevar, loadPath) { +gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'ok'; if (fileSystem) { - if (fileSystem.existsSync(loadPath)) { - fileSystem.readFile(loadPath, 'utf8', (err, data) => { - if (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); - } - if (data) { - scenevar.setString(data); - } - }); - } + fileSystem.readFile(loadPath, 'utf8', (err, data) => { + if (data) { + stringVar.setString(data); + } + if (err) { + console.error("Unable to load the file at path: '" + loadPath + "': ", err); + result = 'error'; + } + }); } + resultVar.setString(result); } /** * Delete a file from the filesystem. * @param {string} filePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation */ -gdjs.fileSystem.deleteFile = function (filePath) { +gdjs.fileSystem.deleteFile = function (filePath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'ok'; if (fileSystem) { - if (fileSystem.existsSync(filePath)) { - fileSystem.unlink(filePath, (err) => { - if (err) { - console.error("Unable to delete the file: '" + filePath + "': ", err); - } - }); - } + fileSystem.unlink(filePath, (err) => { + if (err) { + console.error("Unable to delete the file: '" + filePath + "': ", err); + result = 'error'; + } + }); } + resultVar.setString(result); } /** From d14ea9cc1ddecf5a1fa29081479bb55fcec4b732 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Mon, 21 Jan 2019 19:51:23 +0100 Subject: [PATCH 05/10] Fix result for async functions --- Extensions/FileSystem/filesystemtools.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Extensions/FileSystem/filesystemtools.js b/Extensions/FileSystem/filesystemtools.js index 510e3312b0c1..123ac5551def 100644 --- a/Extensions/FileSystem/filesystemtools.js +++ b/Extensions/FileSystem/filesystemtools.js @@ -140,17 +140,16 @@ gdjs.fileSystem.makeDirectory = function (directory, resultVar) { */ gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - let result = 'ok'; if (fileSystem) { fileSystem.writeFile(savePath, text, (err) => { + resultVar.setString('ok'); if (err) { console.error("Unable to save the text to path: '" + savePath + "': ", err); - result = 'error'; + resultVar.setString('error'); } }); } - resultVar.setString(result); } /** @@ -187,20 +186,19 @@ gdjs.fileSystem.loadStringFromFileSync = function (stringVar, loadPath, resultVa */ gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - let result = 'ok'; if (fileSystem) { fileSystem.readFile(loadPath, 'utf8', (err, data) => { if (data) { stringVar.setString(data); + resultVar.setString('ok'); } if (err) { console.error("Unable to load the file at path: '" + loadPath + "': ", err); - result = 'error'; + resultVar.setString('error'); } }); } - resultVar.setString(result); } /** @@ -210,17 +208,16 @@ gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultV */ gdjs.fileSystem.deleteFile = function (filePath, resultVar) { const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - let result = 'ok'; if (fileSystem) { fileSystem.unlink(filePath, (err) => { + resultVar.setString('ok'); if (err) { console.error("Unable to delete the file: '" + filePath + "': ", err); - result = 'error'; + resultVar.setString('error'); } }); } - resultVar.setString(result); } /** From d7bd5ac2afe250b3fcdc66d9e932872524e5f591 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Tue, 22 Jan 2019 20:10:12 +0100 Subject: [PATCH 06/10] Add function to load a JSON string from a file and convert it into a structure Add function to save a structure as JSON string into a file Add sync and async variants of the existing functions Cleanup variable names and error result --- Extensions/FileSystem/JsExtension.js | 672 ++++++++++++++--------- Extensions/FileSystem/filesystemtools.js | 626 +++++++++++++-------- 2 files changed, 810 insertions(+), 488 deletions(-) diff --git a/Extensions/FileSystem/JsExtension.js b/Extensions/FileSystem/JsExtension.js index 5a6fc257d4d5..ac417e9be14f 100644 --- a/Extensions/FileSystem/JsExtension.js +++ b/Extensions/FileSystem/JsExtension.js @@ -1,252 +1,420 @@ -/** - * 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( - "FileSystem", - t("Filesystem"), - t( - "Access the filesystem of the operating system." - ), - "Matthias Meike", - "Open source (MIT License)" - ).setExtensionHelpPath("/all-features/filesystem"); - - extension - .addCondition( - "PathExists", - t("File or directory exists"), - t( - "Check if the file or directory exists." - ), - t("The path _PARAM0_ exists"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_path_exists24.png", - "JsPlatform/Extensions/filesystem_path_exists32.png" - ) - .addParameter("string", t("Path to file or directory"), "", false) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.pathExists"); - - extension - .addAction( - "MakeDirectory", - t("Create a directory"), - t("Create a new directory at the specified path."), - t("Create directory _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_create_folder24.png", - "JsPlatform/Extensions/filesystem_create_folder32.png" - ) - .addParameter("string", t("Directory"), "", false) - .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.makeDirectory"); - - extension - .addAction( - "SaveStringToFile", - t("Save a text into a file"), - t("Save a text into a file."), - t("Save _PARAM0_ into file _PARAM1_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" - ) - .addParameter("string", t("String (text)"), "", false) - .addParameter("string", t("Save path"), "", false) - .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.saveStringToFile"); - - extension - .addAction( - "LoadStringFromFileAsync", - t("Load a text from a file (Async)"), - t("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 finised."), - t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_load_file24.png", - "JsPlatform/Extensions/filesystem_load_file32.png" - ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Load path"), "", false) - .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.loadStringFromFileAsync"); - - extension - .addAction( - "LoadStringFromFileSync", - t("Load a text from a file"), - t("Load a text from a file. Only use this on small files to avoid any lag or freeze during the the game execution."), - t("Load text from _PARAM1_ into scene variable _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_load_file24.png", - "JsPlatform/Extensions/filesystem_load_file32.png" - ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Load path"), "", false) - .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.loadStringFromFileSync"); - - extension - .addAction( - "DeleteFile", - t("Delete a file"), - t("Delete a file from the filesystem."), - t("Delete the file _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_delete_file24.png", - "JsPlatform/Extensions/filesystem_delete_file32.png" - ) - .addParameter("string", t("File path"), "", false) - .addParameter("scenevar", t("(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured."), "", true) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.deleteFile"); - - extension - .addStrExpression( - "DesktopPath", - t("Desktop folder"), - t("Get the path to the desktop folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getDesktopPath"); - - extension - .addStrExpression( - "DocumentsPath", - t("Documents folder"), - t("Get the path to the documents folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getDocumentsPath"); - - extension - .addStrExpression( - "PicturesPath", - t("Pictures folder"), - t("Get the path to the pictures folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getPicturesPath"); - - extension - .addStrExpression( - "ExecutablePath", - t("This games executable folder"), - t("Get the path to this games executable folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getExecutablePath"); - - extension - .addStrExpression( - "UserdataPath", - t("Userdata folder (For application settings)"), - t("Get the path to userdata folder. (For application settings)"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getUserdataPath"); - - extension - .addStrExpression( - "TempPath", - t("Temp folder"), - t("Get the path to temp folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .addCodeOnlyParameter('currentScene', '') - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getTempPath"); - - extension - .addStrExpression( - "PathDelimiter", - t("Path delimiter"), - t("Get the operating system agnostic path delimiter."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" - ) - .getCodeExtraInformation() - .setIncludeFile( - "Extensions/FileSystem/filesystemtools.js" - ) - .setFunctionName("gdjs.fileSystem.getPathDelimiter"); - - return extension; - }, - runExtensionSanityTests: function (gd, extension) { return []; }, -}; +/** + * 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( + "FileSystem", + t("Filesystem"), + t("Access the filesystem of the operating system."), + "Matthias Meike", + "Open source (MIT License)" + ) + .setExtensionHelpPath("/all-features/filesystem"); + + extension + .addCondition( + "PathExists", + t("File or directory exists"), + t("Check if the file or directory exists."), + t("The path _PARAM0_ exists"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_path_exists24.png", + "JsPlatform/Extensions/filesystem_path_exists32.png" + ) + .addParameter("string", t("Path to file or directory"), "", false) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.pathExists"); + + extension + .addAction( + "MakeDirectory", + t("Create a directory"), + t("Create a new directory at the specified path."), + t("Create directory _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_create_folder24.png", + "JsPlatform/Extensions/filesystem_create_folder32.png" + ) + .addParameter("string", t("Directory"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.makeDirectory"); + + extension + .addAction( + "SaveStringToFile", + t("Save a text into a file"), + t( + "Save a text into a file. Only use this on small files to avoid any lag or freeze during the the game execution." + ), + t("Save _PARAM0_ into file _PARAM1_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("string", t("String (text)"), "", false) + .addParameter("string", t("Save path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.saveStringToFile"); + + extension + .addAction( + "SaveStringToFileAsync", + t("Save a text into a file (Async)."), + t( + "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 finised." + ), + t("Save _PARAM0_ into file _PARAM1_"), + t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("string", t("String (text)"), "", false) + .addParameter("string", t("Save path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.saveStringToFileAsync"); + + extension + .addAction( + "SaveStructureToJSONFileSync", + t("Save a structure into a file"), + t( + "Save a structure with all its child variables into a file in JSON format. Only use this on small files to avoid any lag or freeze during the the game execution." + ), + t("Save structure _PARAM0_ into file _PARAM1_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("string", t("Save path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.saveStructureToJSONFile"); + + extension + .addAction( + "SaveStructureToJSONFileAsync", + t("Save a structure into a file (Async)"), + t( + "Save a structure with all its child variables 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 finised." + ), + t("Save structure _PARAM0_ into file _PARAM1_"), + t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("string", t("Save path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.saveStructureToJSONFileAsync"); + + extension + .addAction( + "LoadStringFromFileAsync", + t("Load a text from a file (Async)"), + t( + "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 finised." + ), + t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), + t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + "JsPlatform/Extensions/filesystem_load_file24.png", + "JsPlatform/Extensions/filesystem_load_file32.png" + ) + .addParameter("scenevar", t("Scene variable"), "", false) + .addParameter("string", t("Load path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.loadStringFromFileAsync"); + + extension + .addAction( + "LoadStringFromFileSync", + t("Load a text from a file"), + t( + "Load a text from a file. Only use this on small files to avoid any lag or freeze during the the game execution." + ), + t("Load text from _PARAM1_ into scene variable _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_load_file24.png", + "JsPlatform/Extensions/filesystem_load_file32.png" + ) + .addParameter("scenevar", t("Scene variable"), "", false) + .addParameter("string", t("Load path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.loadStringFromFile"); + + extension + .addAction( + "LoadStructureFromJSONFileSync", + t("Load a structure from a file"), + t( + "Load a JSON formatted text from a file and convert it into a structure. Only use this on small files to avoid any lag or freeze during the the game execution." + ), + t("Load JSON from _PARAM1_ into structure variable _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("string", t("Load path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.loadStructureFromJSONFile"); + + extension + .addAction( + "LoadStructureFromJSONFileAsync", + t("Load a structure from a file (Async)"), + t( + "Load a JSON formatted text from a file and convert it into a structure. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finised." + ), + t("Load JSON from _PARAM1_ into structure variable _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + "JsPlatform/Extensions/filesystem_save_file24.png", + "JsPlatform/Extensions/filesystem_save_file32.png" + ) + .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("string", t("Load path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.loadStructureFromJSONFileAsync"); + + extension + .addAction( + "DeleteFile", + t("Delete a file"), + t("Delete a file from the filesystem."), + t("Delete the file _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_delete_file24.png", + "JsPlatform/Extensions/filesystem_delete_file32.png" + ) + .addParameter("string", t("File path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.deleteFile"); + + extension + .addAction( + "DeleteFileAsync", + t("Delete a file (Async)"), + t("Delete a file from the filesystem asyncrounouse."), + t("Delete the file _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + "JsPlatform/Extensions/filesystem_delete_file24.png", + "JsPlatform/Extensions/filesystem_delete_file32.png" + ) + .addParameter("string", t("File path"), "", false) + .addParameter( + "scenevar", + t( + "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." + ), + "", + true + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.deleteFileAsync"); + + extension + .addStrExpression( + "DesktopPath", + t("Desktop folder"), + t("Get the path to the desktop folder."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getDesktopPath"); + + extension + .addStrExpression( + "DocumentsPath", + t("Documents folder"), + t("Get the path to the documents folder."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getDocumentsPath"); + + extension + .addStrExpression( + "PicturesPath", + t("Pictures folder"), + t("Get the path to the pictures folder."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getPicturesPath"); + + extension + .addStrExpression( + "ExecutablePath", + t("This games executable folder"), + t("Get the path to this games executable folder."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getExecutablePath"); + + extension + .addStrExpression( + "UserdataPath", + t("Userdata folder (For application settings)"), + t("Get the path to userdata folder. (For application settings)"), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getUserdataPath"); + + extension + .addStrExpression( + "TempPath", + t("Temp folder"), + t("Get the path to temp folder."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .addCodeOnlyParameter("currentScene", "") + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getTempPath"); + + extension + .addStrExpression( + "PathDelimiter", + t("Path delimiter"), + t("Get the operating system agnostic path delimiter."), + t("Filesystem/Windows, Linux, MacOS"), + "JsPlatform/Extensions/filesystem_folder24.png", + "JsPlatform/Extensions/filesystem_folder32.png" + ) + .getCodeExtraInformation() + .setIncludeFile("Extensions/FileSystem/filesystemtools.js") + .setFunctionName("gdjs.fileSystem.getPathDelimiter"); + + return extension; + }, + runExtensionSanityTests: function (gd, extension) { + return []; + } +}; diff --git a/Extensions/FileSystem/filesystemtools.js b/Extensions/FileSystem/filesystemtools.js index 123ac5551def..418fc4c2f28e 100644 --- a/Extensions/FileSystem/filesystemtools.js +++ b/Extensions/FileSystem/filesystemtools.js @@ -1,236 +1,390 @@ -/** - * @memberof gdjs - * @class fileSystem - * @static - * @private - */ - -gdjs.fileSystem = {} - -/** - * Get the path to 'Desktop' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to the desktop folder - */ -gdjs.fileSystem.getDesktopPath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('desktop') || ''; - } else { - return ''; - } -} - -/** - * Get the path to 'Documents' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to the documents folder - */ -gdjs.fileSystem.getDocumentsPath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('documents') || ''; - } else { - return ''; - } -} - -/** - * Get the path to 'Pictures' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to the pictures folder - */ -gdjs.fileSystem.getPicturesPath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('pictures') || ''; - } else { - return ''; - } -} - -/** - * Get the path to this applications 'executable' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to this applications executable folder - */ -gdjs.fileSystem.getExecutablePath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('exe') || ''; - } else { - return ''; - } -} - -/** - * Get the path to 'userdata' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to userdata folder - */ -gdjs.fileSystem.getUserdataPath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('userData') || ''; - } else { - return ''; - } -} - -/** - * Get the path to 'temp' folder. - * @param {gdjs.RuntimeScene} runtimeScene The current scene - * @return {string} The path to temp folder - */ -gdjs.fileSystem.getTempPath = function (runtimeScene) { - const electron = runtimeScene.getGame().getRenderer().getElectron(); - - if (electron) { - return electron.remote.app.getPath('temp') || ''; - } else { - return ''; - } -} - -/** - * Get the path delimiter specific to the operating system. - * @return {string} The path delimiter - */ -gdjs.fileSystem.getPathDelimiter = function () { - const path = typeof require !== 'undefined' ? require('path') : null; - - if (path) { - return path.sep || ''; - } else { - return ''; - } -} - -/** - * Create a new directory at the given path. - * @param {string} directory The path to create a new directory - * @param {scenevar} resultVar (optional) The variable to store the result of the operation - */ -gdjs.fileSystem.makeDirectory = function (directory, resultVar) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - let result = 'ok'; - - if (fileSystem) { - try { - fileSystem.mkdirSync(directory); - } - catch (err) { - console.error("Unable to create directory at: '" + directory + "': ", err); - result = 'error'; - } - } - resultVar.setString(result); -} - -/** - * Save a string into a file. - * @param {string} text The string to be saved - * @param {string} savePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation - */ -gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - - if (fileSystem) { - fileSystem.writeFile(savePath, text, (err) => { - resultVar.setString('ok'); - if (err) { - console.error("Unable to save the text to path: '" + savePath + "': ", err); - resultVar.setString('error'); - } - }); - } -} - -/** - * Load a string from a file into a scene variable. - * @param {scenevar} stringVar The scene variable to store the string - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation - */ -gdjs.fileSystem.loadStringFromFileSync = function (stringVar, loadPath, resultVar) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - let result = 'ok'; - - if (fileSystem) { - try { - const data = fileSystem.readFileSync(loadPath, 'utf8'); - - if (data) { - stringVar.setString(data); - } - } - catch (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); - result = 'error'; - } - } - resultVar.setString(result); -} - -/** - * Load a string from a file into a scene variable asyncrounousely. - * @param {scenevar} stringVar The scene variable to store the string - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation - */ -gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultVar) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - - if (fileSystem) { - fileSystem.readFile(loadPath, 'utf8', (err, data) => { - if (data) { - stringVar.setString(data); - resultVar.setString('ok'); - } - if (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); - resultVar.setString('error'); - } - }); - } -} - -/** - * Delete a file from the filesystem. - * @param {string} filePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation - */ -gdjs.fileSystem.deleteFile = function (filePath, resultVar) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - - if (fileSystem) { - fileSystem.unlink(filePath, (err) => { - resultVar.setString('ok'); - if (err) { - console.error("Unable to delete the file: '" + filePath + "': ", err); - resultVar.setString('error'); - } - }); - } -} - -/** - * Check if the file or directory exists. - * @param {string} path The path to the file or directory - * @return {boolean} True if fhe file or directory exists - */ -gdjs.fileSystem.pathExists = function (path) { - const fileSystem = typeof require !== 'undefined' ? require('fs') : null; - - if (fileSystem) { - return fileSystem.existsSync(path); - } else { - return false; - } -} +/** + * @memberof gdjs + * @class fileSystem + * @static + * @private + */ + +gdjs.fileSystem = {}; + +/** + * Get the path to 'Desktop' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to the desktop folder + */ +gdjs.fileSystem.getDesktopPath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("desktop") || ""; + } else { + return ""; + } +}; + +/** + * Get the path to 'Documents' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to the documents folder + */ +gdjs.fileSystem.getDocumentsPath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("documents") || ""; + } else { + return ""; + } +}; + +/** + * Get the path to 'Pictures' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to the pictures folder + */ +gdjs.fileSystem.getPicturesPath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("pictures") || ""; + } else { + return ""; + } +}; + +/** + * Get the path to this applications 'executable' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to this applications executable folder + */ +gdjs.fileSystem.getExecutablePath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("exe") || ""; + } else { + return ""; + } +}; + +/** + * Get the path to 'userdata' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to userdata folder + */ +gdjs.fileSystem.getUserdataPath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("userData") || ""; + } else { + return ""; + } +}; + +/** + * Get the path to 'temp' folder. + * @param {gdjs.RuntimeScene} runtimeScene The current scene + * @return {string} The path to temp folder + */ +gdjs.fileSystem.getTempPath = function (runtimeScene) { + const electron = runtimeScene + .getGame() + .getRenderer() + .getElectron(); + + if (electron) { + return electron.remote.app.getPath("temp") || ""; + } else { + return ""; + } +}; + +/** + * Get the path delimiter specific to the operating system. + * @return {string} The path delimiter + */ +gdjs.fileSystem.getPathDelimiter = function () { + const path = typeof require !== "undefined" ? require("path") : null; + + if (path) { + return path.sep || ""; + } else { + return ""; + } +}; + +/** + * Create a new directory at the given path. + * @param {string} directory The path to create a new directory + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.makeDirectory = function (directory, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + let result = "error"; + + if (fileSystem) { + try { + fileSystem.mkdirSync(directory); + result = "ok"; + } catch (err) { + console.error("Unable to create directory at: '" + directory + "': ", err); + } + } + resultVar.setString(result); +}; + +/** + * Save a string into a file asyncrounousely. + * @param {string} text The string to be saved + * @param {string} savePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.saveStringToFileAsync = function (text, savePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + + if (fileSystem) { + fileSystem.writeFile(savePath, text, "utf8", err => { + resultVar.setString("ok"); + if (err) { + console.error("Unable to save the text to path: '" + savePath + "': ", err); + resultVar.setString("error"); + } + }); + } +}; + +/** + * Save a string into a file. + * @param {string} text The string to be saved + * @param {string} savePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + let result = "error"; + + if (fileSystem) { + try { + fileSystem.writeFileSync(savePath, text, "utf8"); + result = "ok"; + } catch (err) { + console.error("Unable to save the text to path: '" + savePath + "': ", err); + } + } + resultVar.setString(result); +}; + +/** + * Save a structure into a file in JSON format. + * @param {scenevar} structure The structure to be saved + * @param {string} savePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.saveStructureToJSONFile = function (structure, savePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + const network = gdjs.evtTools.network; + let result = "error"; + + if (fileSystem && network) { + try { + fileSystem.writeFileSync(savePath, network.variableStructureToJSON(structure), "utf8"); + result = "ok"; + } catch (err) { + console.error("Unable to save the structure to path: '" + savePath + "': ", err); + } + } + resultVar.setString(result); +}; + +/** + * Save a structure into a file in JSON format asyncrounousely. + * @param {string} text The structure to be saved + * @param {string} savePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.saveStructureToJSONFileAsync = function (structure, savePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + const network = gdjs.evtTools.network; + + if (fileSystem && network) { + fileSystem.writeFile( + savePath, + network.variableStructureToJSON(structure), "utf8", err => { + resultVar.setString("ok"); + if (err) { + console.error("Unable to save the structure to path: '" + savePath + "': ", err); + resultVar.setString("error"); + } + } + ); + } +}; + +/** + * Load a string from a file into a scene variable. + * @param {scenevar} stringVar The scene variable to store the string + * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.loadStringFromFile = function (stringVar, loadPath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + let result = "error"; + + if (fileSystem) { + try { + const data = fileSystem.readFileSync(loadPath, "utf8"); + + if (data) { + stringVar.setString(data); + result = "ok"; + } + } catch (err) { + console.error("Unable to load the file at path: '" + loadPath + "': ", err); + } + } + resultVar.setString(result); +}; + +/** + * Load a JSON file and convert it into a structure. + * @param {scenevar} structureVar The scene variable to store the structure + * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.loadStructureFromJSONFile = function (structureVar, loadPath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + const network = gdjs.evtTools.network; + let result = "error"; + + if (fileSystem && network) { + try { + const data = fileSystem.readFileSync(loadPath, "utf8"); + if (data) { + network.jsonToVariableStructure(data, structureVar); + result = "ok"; + } + } catch (err) { + console.error("Unable to load structure from the file at path: '" + loadPath + "': ", err); + } + } + resultVar.setString(result); +}; + +/** + * Load a JSON file and convert it into a structure asyncrounousely. + * @param {scenevar} structureVar The scene variable to store the structure + * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.loadStructureFromJSONFileAsync = function (structureVar, loadPath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + const network = gdjs.evtTools.network; + + if (fileSystem && network) { + fileSystem.readFile(loadPath, "utf8", (err, data) => { + if (data) { + network.jsonToVariableStructure(data, structureVar); + resultVar.setString("ok"); + } + if (err) { + console.error("Unable to load structure from the file at path: '" + loadPath + "': ", err); + resultVar.setString("error"); + } + }); + } +}; + +/** + * Load a string from a file into a scene variable asyncrounousely. + * @param {scenevar} stringVar The scene variable to store the string + * @param {string} loadPath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + + if (fileSystem) { + fileSystem.readFile(loadPath, "utf8", (err, data) => { + if (data) { + stringVar.setString(data); + resultVar.setString("ok"); + } + if (err) { + console.error("Unable to load the file at path: '" + loadPath + "': ", err); + resultVar.setString("error"); + } + }); + } +}; + +/** + * Delete a file from the filesystem. + * @param {string} filePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.deleteFile = function (filePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + let result = "error"; + + if (fileSystem) { + try { + fileSystem.unlinkSync(filePath) + result = 'ok'; + } + catch (err) { + console.error("Unable to delete the file: '" + filePath + "': ", err); + result = "error"; + } + } + resultVar.setString(result); +}; + +/** + * Delete a file from the filesystem asyncrounousely. + * @param {string} filePath The absolute path on the filesystem + * @param {scenevar} resultVar (optional) The variable to store the result of the operation + */ +gdjs.fileSystem.deleteFileAsync = function (filePath, resultVar) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + + if (fileSystem) { + fileSystem.unlink(filePath, err => { + resultVar.setString("ok"); + if (err) { + console.error("Unable to delete the file: '" + filePath + "': ", err); + resultVar.setString("error"); + } + }); + } +}; + +/** + * Check if the file or directory exists. + * @param {string} filePath The path to the file or directory + * @return {boolean} True if fhe file or directory exists + */ +gdjs.fileSystem.pathExists = function (filePath) { + const fileSystem = typeof require !== "undefined" ? require("fs") : null; + + if (fileSystem) { + return fileSystem.existsSync(filePath); + } else { + return false; + } +}; From 363432e6950d469c0c0fbb3861b03625de5bc246 Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Wed, 23 Jan 2019 19:25:39 +0100 Subject: [PATCH 07/10] Merge master, fix typo --- Extensions/FileSystem/JsExtension.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Extensions/FileSystem/JsExtension.js b/Extensions/FileSystem/JsExtension.js index ac417e9be14f..226d272d4a1a 100644 --- a/Extensions/FileSystem/JsExtension.js +++ b/Extensions/FileSystem/JsExtension.js @@ -92,7 +92,7 @@ module.exports = { "SaveStringToFileAsync", t("Save a text into a file (Async)."), t( - "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 finised." + "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." ), t("Save _PARAM0_ into file _PARAM1_"), t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), @@ -144,7 +144,7 @@ module.exports = { "SaveStructureToJSONFileAsync", t("Save a structure into a file (Async)"), t( - "Save a structure with all its child variables 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 finised." + "Save a structure with all its child variables 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." ), t("Save structure _PARAM0_ into file _PARAM1_"), t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), @@ -170,7 +170,7 @@ module.exports = { "LoadStringFromFileAsync", t("Load a text from a file (Async)"), t( - "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 finised." + "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." ), t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), @@ -248,7 +248,7 @@ module.exports = { "LoadStructureFromJSONFileAsync", t("Load a structure from a file (Async)"), t( - "Load a JSON formatted text from a file and convert it into a structure. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finised." + "Load a JSON formatted text from a file and convert it into a structure. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished." ), t("Load JSON from _PARAM1_ into structure variable _PARAM0_"), t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), From 84b6eb6637a8940a40e797255c830255d1b0e9eb Mon Sep 17 00:00:00 2001 From: Matthias Meike Date: Thu, 24 Jan 2019 18:42:24 +0100 Subject: [PATCH 08/10] Cleanup - change naming of variables and descriptions --- Extensions/FileSystem/JsExtension.js | 36 ++++++++++++------------ Extensions/FileSystem/filesystemtools.js | 10 +++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Extensions/FileSystem/JsExtension.js b/Extensions/FileSystem/JsExtension.js index 226d272d4a1a..22fd8d178bdb 100644 --- a/Extensions/FileSystem/JsExtension.js +++ b/Extensions/FileSystem/JsExtension.js @@ -63,7 +63,7 @@ module.exports = { extension .addAction( - "SaveStringToFile", + "SaveStringToFileSync", t("Save a text into a file"), t( "Save a text into a file. Only use this on small files to avoid any lag or freeze during the the game execution." @@ -90,12 +90,12 @@ module.exports = { extension .addAction( "SaveStringToFileAsync", - t("Save a text into a file (Async)."), + t("Save a text into a file (Async)"), t( "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." ), t("Save _PARAM0_ into file _PARAM1_"), - t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + t("Filesystem/Windows, Linux, MacOS/Asynchronous"), "JsPlatform/Extensions/filesystem_save_file24.png", "JsPlatform/Extensions/filesystem_save_file32.png" ) @@ -116,11 +116,11 @@ module.exports = { extension .addAction( "SaveStructureToJSONFileSync", - t("Save a structure into a file"), + t("Save a scene variable into a JSON file"), t( "Save a structure with all its child variables into a file in JSON format. Only use this on small files to avoid any lag or freeze during the the game execution." ), - t("Save structure _PARAM0_ into file _PARAM1_"), + t("Save scene variable _PARAM0_ into file PARAM1 as JSON"), t("Filesystem/Windows, Linux, MacOS"), "JsPlatform/Extensions/filesystem_save_file24.png", "JsPlatform/Extensions/filesystem_save_file32.png" @@ -142,16 +142,16 @@ module.exports = { extension .addAction( "SaveStructureToJSONFileAsync", - t("Save a structure into a file (Async)"), + t("Save a scene variable into a JSON file (Async)"), t( "Save a structure with all its child variables 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." ), - t("Save structure _PARAM0_ into file _PARAM1_"), - t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + t("Save scene variable _PARAM0_ into file PARAM1 as JSON"), + t("Filesystem/Windows, Linux, MacOS/Asynchronous"), "JsPlatform/Extensions/filesystem_save_file24.png", "JsPlatform/Extensions/filesystem_save_file32.png" ) - .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("scenevar", t("Scene variable"), "", false) .addParameter("string", t("Save path"), "", false) .addParameter( "scenevar", @@ -168,12 +168,12 @@ module.exports = { extension .addAction( "LoadStringFromFileAsync", - t("Load a text from a file (Async)"), + t("Load a text from a JSON file (Async)"), t( "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." ), t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), - t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + t("Filesystem/Windows, Linux, MacOS/Asynchronous"), "JsPlatform/Extensions/filesystem_load_file24.png", "JsPlatform/Extensions/filesystem_load_file32.png" ) @@ -224,12 +224,12 @@ module.exports = { t( "Load a JSON formatted text from a file and convert it into a structure. Only use this on small files to avoid any lag or freeze during the the game execution." ), - t("Load JSON from _PARAM1_ into structure variable _PARAM0_"), + t("Load JSON from _PARAM1_ into scene variable _PARAM0_"), t("Filesystem/Windows, Linux, MacOS"), "JsPlatform/Extensions/filesystem_save_file24.png", "JsPlatform/Extensions/filesystem_save_file32.png" ) - .addParameter("scenevar", t("Variable structure"), "", false) + .addParameter("scenevar", t("Scene variable"), "", false) .addParameter("string", t("Load path"), "", false) .addParameter( "scenevar", @@ -246,12 +246,12 @@ module.exports = { extension .addAction( "LoadStructureFromJSONFileAsync", - t("Load a structure from a file (Async)"), + t("Load a scene variable from a JSON file (Async)"), t( - "Load a JSON formatted text from a file and convert it into a structure. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished." + "Load a JSON formatted text from a file and convert it into a scene variable. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished." ), - t("Load JSON from _PARAM1_ into structure variable _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + t("Load JSON from _PARAM1_ into scene variable _PARAM0_"), + t("Filesystem/Windows, Linux, MacOS/Asynchronous"), "JsPlatform/Extensions/filesystem_save_file24.png", "JsPlatform/Extensions/filesystem_save_file32.png" ) @@ -298,7 +298,7 @@ module.exports = { t("Delete a file (Async)"), t("Delete a file from the filesystem asyncrounouse."), t("Delete the file _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS/Asyncrounouse"), + t("Filesystem/Windows, Linux, MacOS/Asynchronous"), "JsPlatform/Extensions/filesystem_delete_file24.png", "JsPlatform/Extensions/filesystem_delete_file32.png" ) diff --git a/Extensions/FileSystem/filesystemtools.js b/Extensions/FileSystem/filesystemtools.js index 418fc4c2f28e..7864cac3bd46 100644 --- a/Extensions/FileSystem/filesystemtools.js +++ b/Extensions/FileSystem/filesystemtools.js @@ -62,7 +62,7 @@ gdjs.fileSystem.getPicturesPath = function (runtimeScene) { }; /** - * Get the path to this applications 'executable' folder. + * Get the path to this applications 'Executable' folder. * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to this applications executable folder */ @@ -80,7 +80,7 @@ gdjs.fileSystem.getExecutablePath = function (runtimeScene) { }; /** - * Get the path to 'userdata' folder. + * Get the path to 'UserData' folder. * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to userdata folder */ @@ -98,7 +98,7 @@ gdjs.fileSystem.getUserdataPath = function (runtimeScene) { }; /** - * Get the path to 'temp' folder. + * Get the path to 'Temp' folder. * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to temp folder */ @@ -191,7 +191,7 @@ gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { }; /** - * Save a structure into a file in JSON format. + * Save a variable into a file in JSON format. * @param {scenevar} structure The structure to be saved * @param {string} savePath The absolute path on the filesystem * @param {scenevar} resultVar (optional) The variable to store the result of the operation @@ -213,7 +213,7 @@ gdjs.fileSystem.saveStructureToJSONFile = function (structure, savePath, resultV }; /** - * Save a structure into a file in JSON format asyncrounousely. + * Save a variable into a file in JSON format asyncrounousely. * @param {string} text The structure to be saved * @param {string} savePath The absolute path on the filesystem * @param {scenevar} resultVar (optional) The variable to store the result of the operation From aa136d15920302ca562a5186f90f8652c2c8d4b0 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Thu, 24 Jan 2019 21:56:39 +0000 Subject: [PATCH 09/10] Fix wording and names of functions, run Prettier * Fix an action wrongly mentioning JSON * Add "asynchronously" where needed in descriptions * Always use scene variable for consistency, only mention structure as an information. * Update name of functions to remove reference to structure, use variable instead as it's the type expected in the JS functions. * Run Prettier --- Extensions/FileSystem/JsExtension.js | 440 +++++++++++++-------------- 1 file changed, 220 insertions(+), 220 deletions(-) diff --git a/Extensions/FileSystem/JsExtension.js b/Extensions/FileSystem/JsExtension.js index 22fd8d178bdb..de18dad194c9 100644 --- a/Extensions/FileSystem/JsExtension.js +++ b/Extensions/FileSystem/JsExtension.js @@ -11,410 +11,410 @@ * More information on https://github.com/4ian/GDevelop/blob/master/newIDE/README-extensions.md */ module.exports = { - createExtension: function (t, gd) { + createExtension: function(t, gd) { const extension = new gd.PlatformExtension(); extension .setExtensionInformation( - "FileSystem", - t("Filesystem"), - t("Access the filesystem of the operating system."), - "Matthias Meike", - "Open source (MIT License)" + 'FileSystem', + t('Filesystem'), + t('Access the filesystem of the operating system.'), + 'Matthias Meike', + 'Open source (MIT License)' ) - .setExtensionHelpPath("/all-features/filesystem"); + .setExtensionHelpPath('/all-features/filesystem'); extension .addCondition( - "PathExists", - t("File or directory exists"), - t("Check if the file or directory exists."), - t("The path _PARAM0_ exists"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_path_exists24.png", - "JsPlatform/Extensions/filesystem_path_exists32.png" + 'PathExists', + t('File or directory exists'), + t('Check if the file or directory exists.'), + t('The path _PARAM0_ exists'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_path_exists24.png', + 'JsPlatform/Extensions/filesystem_path_exists32.png' ) - .addParameter("string", t("Path to file or directory"), "", false) + .addParameter('string', t('Path to file or directory'), '', false) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.pathExists"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.pathExists'); extension .addAction( - "MakeDirectory", - t("Create a directory"), - t("Create a new directory at the specified path."), - t("Create directory _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_create_folder24.png", - "JsPlatform/Extensions/filesystem_create_folder32.png" + 'MakeDirectory', + t('Create a directory'), + t('Create a new directory at the specified path.'), + t('Create directory _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_create_folder24.png', + 'JsPlatform/Extensions/filesystem_create_folder32.png' ) - .addParameter("string", t("Directory"), "", false) + .addParameter('string', t('Directory'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.makeDirectory"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.makeDirectory'); extension .addAction( - "SaveStringToFileSync", - t("Save a text into a file"), + 'SaveStringToFileSync', + t('Save a text into a file'), t( - "Save a text into a file. Only use this on small files to avoid any lag or freeze during the the game execution." + 'Save a text into a file. Only use this on small files to avoid any lag or freeze during the the game execution.' ), - t("Save _PARAM0_ into file _PARAM1_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Save _PARAM0_ into file _PARAM1_'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("string", t("String (text)"), "", false) - .addParameter("string", t("Save path"), "", false) + .addParameter('string', t('String (text)'), '', false) + .addParameter('string', t('Save path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.saveStringToFile"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.saveStringToFile'); extension .addAction( - "SaveStringToFileAsync", - t("Save a text into a file (Async)"), + 'SaveStringToFileAsync', + t('Save a text into a file (Async)'), t( "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." ), - t("Save _PARAM0_ into file _PARAM1_"), - t("Filesystem/Windows, Linux, MacOS/Asynchronous"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Save _PARAM0_ into file _PARAM1_'), + t('Filesystem/Windows, Linux, MacOS/Asynchronous'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("string", t("String (text)"), "", false) - .addParameter("string", t("Save path"), "", false) + .addParameter('string', t('String (text)'), '', false) + .addParameter('string', t('Save path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.saveStringToFileAsync"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.saveStringToFileAsync'); extension .addAction( - "SaveStructureToJSONFileSync", - t("Save a scene variable into a JSON file"), + 'SaveVariableToJSONFileSync', + t('Save a scene variable into a JSON file'), t( - "Save a structure with all its child variables into a file in JSON format. Only use this on small files to avoid any lag or freeze during the the game execution." + '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 the game execution.' ), - t("Save scene variable _PARAM0_ into file PARAM1 as JSON"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Save scene variable _PARAM0_ into file PARAM1 as JSON'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("scenevar", t("Variable structure"), "", false) - .addParameter("string", t("Save path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Save path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.saveStructureToJSONFile"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.saveVariableToJSONFile'); extension .addAction( - "SaveStructureToJSONFileAsync", - t("Save a scene variable into a JSON file (Async)"), + 'SaveVariableToJSONFileAsync', + t('Save a scene variable into a JSON file (Async)'), t( - "Save a structure with all its child variables 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 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." ), - t("Save scene variable _PARAM0_ into file PARAM1 as JSON"), - t("Filesystem/Windows, Linux, MacOS/Asynchronous"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Save scene variable _PARAM0_ into file PARAM1 as JSON'), + t('Filesystem/Windows, Linux, MacOS/Asynchronous'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Save path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Save path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.saveStructureToJSONFileAsync"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.saveVariableToJSONFileAsync'); extension .addAction( - "LoadStringFromFileAsync", - t("Load a text from a JSON file (Async)"), + 'LoadStringFromFileAsync', + t('Load a text from a file (Async)'), t( - "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 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." ), - t("Load text from _PARAM1_ into scene variable _PARAM0_ (Async)"), - t("Filesystem/Windows, Linux, MacOS/Asynchronous"), - "JsPlatform/Extensions/filesystem_load_file24.png", - "JsPlatform/Extensions/filesystem_load_file32.png" + t('Load text from _PARAM1_ into scene variable _PARAM0_ (Async)'), + t('Filesystem/Windows, Linux, MacOS/Asynchronous'), + 'JsPlatform/Extensions/filesystem_load_file24.png', + 'JsPlatform/Extensions/filesystem_load_file32.png' ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Load path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Load path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.loadStringFromFileAsync"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.loadStringFromFileAsync'); extension .addAction( - "LoadStringFromFileSync", - t("Load a text from a file"), + 'LoadStringFromFileSync', + t('Load a text from a file'), t( - "Load a text from a file. Only use this on small files to avoid any lag or freeze during the the game execution." + 'Load a text from a file. Only use this on small files to avoid any lag or freeze during the the game execution.' ), - t("Load text from _PARAM1_ into scene variable _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_load_file24.png", - "JsPlatform/Extensions/filesystem_load_file32.png" + t('Load text from _PARAM1_ into scene variable _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_load_file24.png', + 'JsPlatform/Extensions/filesystem_load_file32.png' ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Load path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Load path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.loadStringFromFile"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.loadStringFromFile'); extension .addAction( - "LoadStructureFromJSONFileSync", - t("Load a structure from a file"), + 'LoadVariableFromJSONFileSync', + t('Load a scene variable from a JSON file'), t( - "Load a JSON formatted text from a file and convert it into a structure. Only use this on small files to avoid any lag or freeze during the the game execution." + '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 the game execution.' ), - t("Load JSON from _PARAM1_ into scene variable _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Load JSON from _PARAM1_ into scene variable _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("scenevar", t("Scene variable"), "", false) - .addParameter("string", t("Load path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Load path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.loadStructureFromJSONFile"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.loadVariableFromJSONFile'); extension .addAction( - "LoadStructureFromJSONFileAsync", - t("Load a scene variable from a JSON file (Async)"), + 'LoadVariableFromJSONFileAsync', + t('Load a scene variable from a JSON file (Async)'), t( - "Load a JSON formatted text from a file and convert it into a scene variable. 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 structure after a small delay (usually a few milliseconds). The 'result' variable gets updated when the operation has finished." + "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." ), - t("Load JSON from _PARAM1_ into scene variable _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS/Asynchronous"), - "JsPlatform/Extensions/filesystem_save_file24.png", - "JsPlatform/Extensions/filesystem_save_file32.png" + t('Load JSON from _PARAM1_ into scene variable _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS/Asynchronous'), + 'JsPlatform/Extensions/filesystem_save_file24.png', + 'JsPlatform/Extensions/filesystem_save_file32.png' ) - .addParameter("scenevar", t("Variable structure"), "", false) - .addParameter("string", t("Load path"), "", false) + .addParameter('scenevar', t('Scene variable'), '', false) + .addParameter('string', t('Load path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.loadStructureFromJSONFileAsync"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.loadVariableFromJSONFileAsync'); extension .addAction( - "DeleteFile", - t("Delete a file"), - t("Delete a file from the filesystem."), - t("Delete the file _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_delete_file24.png", - "JsPlatform/Extensions/filesystem_delete_file32.png" + 'DeleteFile', + t('Delete a file'), + t('Delete a file from the filesystem.'), + t('Delete the file _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_delete_file24.png', + 'JsPlatform/Extensions/filesystem_delete_file32.png' ) - .addParameter("string", t("File path"), "", false) + .addParameter('string', t('File path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.deleteFile"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.deleteFile'); extension .addAction( - "DeleteFileAsync", - t("Delete a file (Async)"), - t("Delete a file from the filesystem asyncrounouse."), - t("Delete the file _PARAM0_"), - t("Filesystem/Windows, Linux, MacOS/Asynchronous"), - "JsPlatform/Extensions/filesystem_delete_file24.png", - "JsPlatform/Extensions/filesystem_delete_file32.png" + 'DeleteFileAsync', + t('Delete a file (Async)'), + t('Delete a file from the filesystem asyncrounouse.'), + t('Delete the file _PARAM0_'), + t('Filesystem/Windows, Linux, MacOS/Asynchronous'), + 'JsPlatform/Extensions/filesystem_delete_file24.png', + 'JsPlatform/Extensions/filesystem_delete_file32.png' ) - .addParameter("string", t("File path"), "", false) + .addParameter('string', t('File path'), '', false) .addParameter( - "scenevar", + 'scenevar', t( "(Optional) Variable to store the result. 'ok': task was successful, 'error': an error occured." ), - "", + '', true ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.deleteFileAsync"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.deleteFileAsync'); extension .addStrExpression( - "DesktopPath", - t("Desktop folder"), - t("Get the path to the desktop folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'DesktopPath', + t('Desktop folder'), + t('Get the path to the desktop folder.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getDesktopPath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getDesktopPath'); extension .addStrExpression( - "DocumentsPath", - t("Documents folder"), - t("Get the path to the documents folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'DocumentsPath', + t('Documents folder'), + t('Get the path to the documents folder.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getDocumentsPath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getDocumentsPath'); extension .addStrExpression( - "PicturesPath", - t("Pictures folder"), - t("Get the path to the pictures folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'PicturesPath', + t('Pictures folder'), + t('Get the path to the pictures folder.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getPicturesPath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getPicturesPath'); extension .addStrExpression( - "ExecutablePath", - t("This games executable folder"), - t("Get the path to this games executable folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'ExecutablePath', + t('This games executable folder'), + t('Get the path to this games executable folder.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getExecutablePath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getExecutablePath'); extension .addStrExpression( - "UserdataPath", - t("Userdata folder (For application settings)"), - t("Get the path to userdata folder. (For application settings)"), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'UserdataPath', + t('Userdata folder (For application settings)'), + t('Get the path to userdata folder. (For application settings)'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getUserdataPath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getUserdataPath'); extension .addStrExpression( - "TempPath", - t("Temp folder"), - t("Get the path to temp folder."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'TempPath', + t('Temp folder'), + t('Get the path to temp folder.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) - .addCodeOnlyParameter("currentScene", "") + .addCodeOnlyParameter('currentScene', '') .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getTempPath"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getTempPath'); extension .addStrExpression( - "PathDelimiter", - t("Path delimiter"), - t("Get the operating system agnostic path delimiter."), - t("Filesystem/Windows, Linux, MacOS"), - "JsPlatform/Extensions/filesystem_folder24.png", - "JsPlatform/Extensions/filesystem_folder32.png" + 'PathDelimiter', + t('Path delimiter'), + t('Get the operating system agnostic path delimiter.'), + t('Filesystem/Windows, Linux, MacOS'), + 'JsPlatform/Extensions/filesystem_folder24.png', + 'JsPlatform/Extensions/filesystem_folder32.png' ) .getCodeExtraInformation() - .setIncludeFile("Extensions/FileSystem/filesystemtools.js") - .setFunctionName("gdjs.fileSystem.getPathDelimiter"); + .setIncludeFile('Extensions/FileSystem/filesystemtools.js') + .setFunctionName('gdjs.fileSystem.getPathDelimiter'); return extension; }, - runExtensionSanityTests: function (gd, extension) { + runExtensionSanityTests: function(gd, extension) { return []; - } + }, }; From c333a4ed8d4ac715cad2140a7a34d473b6c13a46 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Thu, 24 Jan 2019 21:57:56 +0000 Subject: [PATCH 10/10] Update function names * Typo asyncrounousely => asynchronously * `scenevar` is not a proper type in JavaScript, use `gdjs.Variable` instead * Remove "optional" in documentation are these variables as not optional arguments in JavaScript. --- Extensions/FileSystem/filesystemtools.js | 302 +++++++++++++---------- 1 file changed, 177 insertions(+), 125 deletions(-) diff --git a/Extensions/FileSystem/filesystemtools.js b/Extensions/FileSystem/filesystemtools.js index 7864cac3bd46..79439b07c7b8 100644 --- a/Extensions/FileSystem/filesystemtools.js +++ b/Extensions/FileSystem/filesystemtools.js @@ -12,16 +12,16 @@ gdjs.fileSystem = {}; * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to the desktop folder */ -gdjs.fileSystem.getDesktopPath = function (runtimeScene) { +gdjs.fileSystem.getDesktopPath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("desktop") || ""; + return electron.remote.app.getPath('desktop') || ''; } else { - return ""; + return ''; } }; @@ -30,16 +30,16 @@ gdjs.fileSystem.getDesktopPath = function (runtimeScene) { * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to the documents folder */ -gdjs.fileSystem.getDocumentsPath = function (runtimeScene) { +gdjs.fileSystem.getDocumentsPath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("documents") || ""; + return electron.remote.app.getPath('documents') || ''; } else { - return ""; + return ''; } }; @@ -48,34 +48,34 @@ gdjs.fileSystem.getDocumentsPath = function (runtimeScene) { * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to the pictures folder */ -gdjs.fileSystem.getPicturesPath = function (runtimeScene) { +gdjs.fileSystem.getPicturesPath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("pictures") || ""; + return electron.remote.app.getPath('pictures') || ''; } else { - return ""; + return ''; } }; /** - * Get the path to this applications 'Executable' folder. + * Get the path to this application 'Executable' folder. * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to this applications executable folder */ -gdjs.fileSystem.getExecutablePath = function (runtimeScene) { +gdjs.fileSystem.getExecutablePath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("exe") || ""; + return electron.remote.app.getPath('exe') || ''; } else { - return ""; + return ''; } }; @@ -84,16 +84,16 @@ gdjs.fileSystem.getExecutablePath = function (runtimeScene) { * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to userdata folder */ -gdjs.fileSystem.getUserdataPath = function (runtimeScene) { +gdjs.fileSystem.getUserdataPath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("userData") || ""; + return electron.remote.app.getPath('userData') || ''; } else { - return ""; + return ''; } }; @@ -102,16 +102,16 @@ gdjs.fileSystem.getUserdataPath = function (runtimeScene) { * @param {gdjs.RuntimeScene} runtimeScene The current scene * @return {string} The path to temp folder */ -gdjs.fileSystem.getTempPath = function (runtimeScene) { +gdjs.fileSystem.getTempPath = function(runtimeScene) { const electron = runtimeScene .getGame() .getRenderer() .getElectron(); if (electron) { - return electron.remote.app.getPath("temp") || ""; + return electron.remote.app.getPath('temp') || ''; } else { - return ""; + return ''; } }; @@ -119,51 +119,57 @@ gdjs.fileSystem.getTempPath = function (runtimeScene) { * Get the path delimiter specific to the operating system. * @return {string} The path delimiter */ -gdjs.fileSystem.getPathDelimiter = function () { - const path = typeof require !== "undefined" ? require("path") : null; +gdjs.fileSystem.getPathDelimiter = function() { + const path = typeof require !== 'undefined' ? require('path') : null; if (path) { - return path.sep || ""; + return path.sep || '/'; } else { - return ""; + return '/'; } }; /** * Create a new directory at the given path. * @param {string} directory The path to create a new directory - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.makeDirectory = function (directory, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; - let result = "error"; +gdjs.fileSystem.makeDirectory = function(directory, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'error'; if (fileSystem) { try { fileSystem.mkdirSync(directory); - result = "ok"; + result = 'ok'; } catch (err) { - console.error("Unable to create directory at: '" + directory + "': ", err); + console.error( + "Unable to create directory at: '" + directory + "': ", + err + ); } } resultVar.setString(result); }; /** - * Save a string into a file asyncrounousely. + * Save a string into a file, asynchronously. * @param {string} text The string to be saved - * @param {string} savePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {string} savePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.saveStringToFileAsync = function (text, savePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.saveStringToFileAsync = function(text, savePath, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; if (fileSystem) { - fileSystem.writeFile(savePath, text, "utf8", err => { - resultVar.setString("ok"); + fileSystem.writeFile(savePath, text, 'utf8', err => { + resultVar.setString('ok'); if (err) { - console.error("Unable to save the text to path: '" + savePath + "': ", err); - resultVar.setString("error"); + console.error( + "Unable to save the text to path: '" + savePath + "': ", + err + ); + resultVar.setString('error'); } }); } @@ -172,19 +178,22 @@ gdjs.fileSystem.saveStringToFileAsync = function (text, savePath, resultVar) { /** * Save a string into a file. * @param {string} text The string to be saved - * @param {string} savePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {string} savePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; - let result = "error"; +gdjs.fileSystem.saveStringToFile = function(text, savePath, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'error'; if (fileSystem) { try { - fileSystem.writeFileSync(savePath, text, "utf8"); - result = "ok"; + fileSystem.writeFileSync(savePath, text, 'utf8'); + result = 'ok'; } catch (err) { - console.error("Unable to save the text to path: '" + savePath + "': ", err); + console.error( + "Unable to save the text to path: '" + savePath + "': ", + err + ); } } resultVar.setString(result); @@ -192,44 +201,64 @@ gdjs.fileSystem.saveStringToFile = function (text, savePath, resultVar) { /** * Save a variable into a file in JSON format. - * @param {scenevar} structure The structure to be saved - * @param {string} savePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {gdjs.Variable} variable The variable to be saved + * @param {string} savePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.saveStructureToJSONFile = function (structure, savePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.saveVariableToJSONFile = function( + variable, + savePath, + resultVar +) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; const network = gdjs.evtTools.network; - let result = "error"; + let result = 'error'; if (fileSystem && network) { try { - fileSystem.writeFileSync(savePath, network.variableStructureToJSON(structure), "utf8"); - result = "ok"; + fileSystem.writeFileSync( + savePath, + network.variableStructureToJSON(variable), + 'utf8' + ); + result = 'ok'; } catch (err) { - console.error("Unable to save the structure to path: '" + savePath + "': ", err); + console.error( + "Unable to save the variable to path: '" + savePath + "': ", + err + ); } } resultVar.setString(result); }; /** - * Save a variable into a file in JSON format asyncrounousely. - * @param {string} text The structure to be saved - * @param {string} savePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * Save a variable into a file in JSON format, asynchronously. + * @param {string} text The variable to be saved + * @param {string} savePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.saveStructureToJSONFileAsync = function (structure, savePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.saveVariableToJSONFileAsync = function( + variable, + savePath, + resultVar +) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; const network = gdjs.evtTools.network; if (fileSystem && network) { fileSystem.writeFile( savePath, - network.variableStructureToJSON(structure), "utf8", err => { - resultVar.setString("ok"); + network.variableStructureToJSON(variable), + 'utf8', + err => { + resultVar.setString('ok'); if (err) { - console.error("Unable to save the structure to path: '" + savePath + "': ", err); - resultVar.setString("error"); + console.error( + "Unable to save the variable to path: '" + savePath + "': ", + err + ); + resultVar.setString('error'); } } ); @@ -238,96 +267,120 @@ gdjs.fileSystem.saveStructureToJSONFileAsync = function (structure, savePath, re /** * Load a string from a file into a scene variable. - * @param {scenevar} stringVar The scene variable to store the string - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {gdjs.Variable} stringVar Variable where to store the content + * @param {string} loadPath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.loadStringFromFile = function (stringVar, loadPath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; - let result = "error"; +gdjs.fileSystem.loadStringFromFile = function(stringVar, loadPath, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'error'; if (fileSystem) { try { - const data = fileSystem.readFileSync(loadPath, "utf8"); + const data = fileSystem.readFileSync(loadPath, 'utf8'); if (data) { stringVar.setString(data); - result = "ok"; + result = 'ok'; } } catch (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); + console.error( + "Unable to load the file at path: '" + loadPath + "': ", + err + ); } } resultVar.setString(result); }; /** - * Load a JSON file and convert it into a structure. - * @param {scenevar} structureVar The scene variable to store the structure - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * Load a JSON file and convert it into a variable. + * @param {gdjs.Variable} variable Variable to store the variable + * @param {string} loadPath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.loadStructureFromJSONFile = function (structureVar, loadPath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.loadVariableFromJSONFile = function( + variable, + loadPath, + resultVar +) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; const network = gdjs.evtTools.network; - let result = "error"; + let result = 'error'; if (fileSystem && network) { try { - const data = fileSystem.readFileSync(loadPath, "utf8"); + const data = fileSystem.readFileSync(loadPath, 'utf8'); if (data) { - network.jsonToVariableStructure(data, structureVar); - result = "ok"; + network.jsonToVariableStructure(data, variable); + result = 'ok'; } } catch (err) { - console.error("Unable to load structure from the file at path: '" + loadPath + "': ", err); + console.error( + "Unable to load variable from the file at path: '" + loadPath + "': ", + err + ); } } resultVar.setString(result); }; /** - * Load a JSON file and convert it into a structure asyncrounousely. - * @param {scenevar} structureVar The scene variable to store the structure - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * Load a JSON file and convert it into a variable, asynchronously. + * @param {gdjs.Variable} variable Variable to store the variable + * @param {string} loadPath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.loadStructureFromJSONFileAsync = function (structureVar, loadPath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.loadVariableFromJSONFileAsync = function( + variable, + loadPath, + resultVar +) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; const network = gdjs.evtTools.network; if (fileSystem && network) { - fileSystem.readFile(loadPath, "utf8", (err, data) => { + fileSystem.readFile(loadPath, 'utf8', (err, data) => { if (data) { - network.jsonToVariableStructure(data, structureVar); - resultVar.setString("ok"); + network.jsonToVariableStructure(data, variable); + resultVar.setString('ok'); } if (err) { - console.error("Unable to load structure from the file at path: '" + loadPath + "': ", err); - resultVar.setString("error"); + console.error( + "Unable to load variable from the file at path: '" + loadPath + "': ", + err + ); + resultVar.setString('error'); } }); } }; /** - * Load a string from a file into a scene variable asyncrounousely. - * @param {scenevar} stringVar The scene variable to store the string - * @param {string} loadPath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * Load a string from a file into a scene variable, asynchronously. + * @param {gdjs.Variable} stringVar Variable where to store the content + * @param {string} loadPath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.loadStringFromFileAsync = function( + stringVar, + loadPath, + resultVar +) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; if (fileSystem) { - fileSystem.readFile(loadPath, "utf8", (err, data) => { + fileSystem.readFile(loadPath, 'utf8', (err, data) => { if (data) { stringVar.setString(data); - resultVar.setString("ok"); + resultVar.setString('ok'); } if (err) { - console.error("Unable to load the file at path: '" + loadPath + "': ", err); - resultVar.setString("error"); + console.error( + "Unable to load the file at path: '" + loadPath + "': ", + err + ); + resultVar.setString('error'); } }); } @@ -335,40 +388,39 @@ gdjs.fileSystem.loadStringFromFileAsync = function (stringVar, loadPath, resultV /** * Delete a file from the filesystem. - * @param {string} filePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * @param {string} filePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.deleteFile = function (filePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; - let result = "error"; +gdjs.fileSystem.deleteFile = function(filePath, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; + let result = 'error'; if (fileSystem) { try { - fileSystem.unlinkSync(filePath) + fileSystem.unlinkSync(filePath); result = 'ok'; - } - catch (err) { + } catch (err) { console.error("Unable to delete the file: '" + filePath + "': ", err); - result = "error"; + result = 'error'; } } resultVar.setString(result); }; /** - * Delete a file from the filesystem asyncrounousely. - * @param {string} filePath The absolute path on the filesystem - * @param {scenevar} resultVar (optional) The variable to store the result of the operation + * Delete a file from the filesystem, asynchronously. + * @param {string} filePath Path to the file + * @param {gdjs.Variable} resultVar The variable where to store the result of the operation */ -gdjs.fileSystem.deleteFileAsync = function (filePath, resultVar) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.deleteFileAsync = function(filePath, resultVar) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; if (fileSystem) { fileSystem.unlink(filePath, err => { - resultVar.setString("ok"); + resultVar.setString('ok'); if (err) { console.error("Unable to delete the file: '" + filePath + "': ", err); - resultVar.setString("error"); + resultVar.setString('error'); } }); } @@ -377,10 +429,10 @@ gdjs.fileSystem.deleteFileAsync = function (filePath, resultVar) { /** * Check if the file or directory exists. * @param {string} filePath The path to the file or directory - * @return {boolean} True if fhe file or directory exists + * @return {boolean} true if fhe file or directory exists */ -gdjs.fileSystem.pathExists = function (filePath) { - const fileSystem = typeof require !== "undefined" ? require("fs") : null; +gdjs.fileSystem.pathExists = function(filePath) { + const fileSystem = typeof require !== 'undefined' ? require('fs') : null; if (fileSystem) { return fileSystem.existsSync(filePath);