project_converter_3_to_4.cpp 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962
  1. /**************************************************************************/
  2. /* project_converter_3_to_4.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "project_converter_3_to_4.h"
  31. #ifndef DISABLE_DEPRECATED
  32. #include "modules/modules_enabled.gen.h" // For regex.
  33. #ifdef MODULE_REGEX_ENABLED
  34. #include "core/error/error_macros.h"
  35. #include "core/io/dir_access.h"
  36. #include "core/io/file_access.h"
  37. #include "core/object/ref_counted.h"
  38. #include "core/os/time.h"
  39. #include "core/templates/hash_map.h"
  40. #include "core/templates/list.h"
  41. #include "editor/renames_map_3_to_4.h"
  42. #include "modules/regex/regex.h"
  43. // Find "OS.set_property(x)", capturing x into $1.
  44. static String make_regex_gds_os_property_set(const String &name_set) {
  45. return String("\\bOS\\.") + name_set + "\\s*\\((.*)\\)";
  46. }
  47. // Find "OS.property = x", capturing x into $1 or $2.
  48. static String make_regex_gds_os_property_assign(const String &name) {
  49. return String("\\bOS\\.") + name + "\\s*=\\s*([^#]+)";
  50. }
  51. // Find "OS.property" OR "OS.get_property()" / "OS.is_property()".
  52. static String make_regex_gds_os_property_get(const String &name, const String &get) {
  53. return String("\\bOS\\.(") + get + "_)?" + name + "(\\s*\\(\\s*\\))?";
  54. }
  55. class ProjectConverter3To4::RegExContainer {
  56. public:
  57. // Custom GDScript.
  58. RegEx reg_is_empty = RegEx("\\bempty\\(");
  59. RegEx reg_super = RegEx("([\t ])\\.([a-zA-Z_])");
  60. RegEx reg_json_to = RegEx("\\bto_json\\b");
  61. RegEx reg_json_parse = RegEx("([\t ]{0,})([^\n]+)parse_json\\(([^\n]+)");
  62. RegEx reg_json_non_new = RegEx("([\t ]{0,})([^\n]+)JSON\\.parse\\(([^\n]+)");
  63. RegEx reg_json_print = RegEx("\\bJSON\\b\\.print\\(");
  64. RegEx reg_export_simple = RegEx("export[ ]*\\(([a-zA-Z0-9_]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)");
  65. RegEx reg_export_typed = RegEx("export[ ]*\\(([a-zA-Z0-9_]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)[ ]*:[ ]*[a-zA-Z0-9_]+");
  66. RegEx reg_export_inferred_type = RegEx("export[ ]*\\([a-zA-Z0-9_]+\\)[ ]*var[ ]+([a-zA-Z0-9_]+)[ ]*:[ ]*=");
  67. RegEx reg_export_advanced = RegEx("export[ ]*\\(([^)^\n]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)([^\n]+)");
  68. RegEx reg_setget_setget = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+([a-zA-Z0-9_]+)[ \t]*,[ \t]*([a-zA-Z0-9_]+)");
  69. RegEx reg_setget_set = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+([a-zA-Z0-9_]+)[ \t]*[,]*[^\n]*$");
  70. RegEx reg_setget_get = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+,[ \t]*([a-zA-Z0-9_]+)[ \t]*$");
  71. RegEx reg_join = RegEx("([\\(\\)a-zA-Z0-9_]+)\\.join\\(([^\n^\\)]+)\\)");
  72. RegEx reg_image_lock = RegEx("([a-zA-Z0-9_\\.]+)\\.lock\\(\\)");
  73. RegEx reg_image_unlock = RegEx("([a-zA-Z0-9_\\.]+)\\.unlock\\(\\)");
  74. RegEx reg_instantiate = RegEx("\\.instance\\(([^\\)]*)\\)");
  75. // Simple OS properties with getters/setters.
  76. RegEx reg_os_current_screen = RegEx("\\bOS\\.((set_|get_)?)current_screen\\b");
  77. RegEx reg_os_min_window_size = RegEx("\\bOS\\.((set_|get_)?)min_window_size\\b");
  78. RegEx reg_os_max_window_size = RegEx("\\bOS\\.((set_|get_)?)max_window_size\\b");
  79. RegEx reg_os_window_position = RegEx("\\bOS\\.((set_|get_)?)window_position\\b");
  80. RegEx reg_os_window_size = RegEx("\\bOS\\.((set_|get_)?)window_size\\b");
  81. RegEx reg_os_getset_screen_orient = RegEx("\\bOS\\.(s|g)et_screen_orientation\\b");
  82. // OS property getters/setters for non trivial replacements.
  83. RegEx reg_os_set_window_resizable = RegEx(make_regex_gds_os_property_set("set_window_resizable"));
  84. RegEx reg_os_assign_window_resizable = RegEx(make_regex_gds_os_property_assign("window_resizable"));
  85. RegEx reg_os_is_window_resizable = RegEx(make_regex_gds_os_property_get("window_resizable", "is"));
  86. RegEx reg_os_set_fullscreen = RegEx(make_regex_gds_os_property_set("set_window_fullscreen"));
  87. RegEx reg_os_assign_fullscreen = RegEx(make_regex_gds_os_property_assign("window_fullscreen"));
  88. RegEx reg_os_is_fullscreen = RegEx(make_regex_gds_os_property_get("window_fullscreen", "is"));
  89. RegEx reg_os_set_maximized = RegEx(make_regex_gds_os_property_set("set_window_maximized"));
  90. RegEx reg_os_assign_maximized = RegEx(make_regex_gds_os_property_assign("window_maximized"));
  91. RegEx reg_os_is_maximized = RegEx(make_regex_gds_os_property_get("window_maximized", "is"));
  92. RegEx reg_os_set_minimized = RegEx(make_regex_gds_os_property_set("set_window_minimized"));
  93. RegEx reg_os_assign_minimized = RegEx(make_regex_gds_os_property_assign("window_minimized"));
  94. RegEx reg_os_is_minimized = RegEx(make_regex_gds_os_property_get("window_minimized", "is"));
  95. RegEx reg_os_set_vsync = RegEx(make_regex_gds_os_property_set("set_use_vsync"));
  96. RegEx reg_os_assign_vsync = RegEx(make_regex_gds_os_property_assign("vsync_enabled"));
  97. RegEx reg_os_is_vsync = RegEx(make_regex_gds_os_property_get("vsync_enabled", "is"));
  98. // OS properties specific cases & specific replacements.
  99. RegEx reg_os_assign_screen_orient = RegEx("^(\\s*)OS\\.screen_orientation\\s*=\\s*([^#]+)"); // $1 - indent, $2 - value
  100. RegEx reg_os_set_always_on_top = RegEx(make_regex_gds_os_property_set("set_window_always_on_top"));
  101. RegEx reg_os_is_always_on_top = RegEx("\\bOS\\.is_window_always_on_top\\s*\\(.*\\)");
  102. RegEx reg_os_set_borderless = RegEx(make_regex_gds_os_property_set("set_borderless_window"));
  103. RegEx reg_os_get_borderless = RegEx("\\bOS\\.get_borderless_window\\s*\\(\\s*\\)");
  104. RegEx reg_os_screen_orient_enum = RegEx("\\bOS\\.SCREEN_ORIENTATION_(\\w+)\\b"); // $1 - constant suffix
  105. // GDScript keywords.
  106. RegEx keyword_gdscript_tool = RegEx("^tool");
  107. RegEx keyword_gdscript_export_single = RegEx("^export");
  108. RegEx keyword_gdscript_export_multi = RegEx("([\t]+)export\\b");
  109. RegEx keyword_gdscript_onready = RegEx("^onready");
  110. RegEx keyword_gdscript_remote = RegEx("^remote func");
  111. RegEx keyword_gdscript_remotesync = RegEx("^remotesync func");
  112. RegEx keyword_gdscript_sync = RegEx("^sync func");
  113. RegEx keyword_gdscript_slave = RegEx("^slave func");
  114. RegEx keyword_gdscript_puppet = RegEx("^puppet func");
  115. RegEx keyword_gdscript_puppetsync = RegEx("^puppetsync func");
  116. RegEx keyword_gdscript_master = RegEx("^master func");
  117. RegEx keyword_gdscript_mastersync = RegEx("^mastersync func");
  118. RegEx gdscript_comment = RegEx("^\\s*#");
  119. RegEx csharp_comment = RegEx("^\\s*\\/\\/");
  120. // CSharp keywords.
  121. RegEx keyword_csharp_remote = RegEx("\\[Remote(Attribute)?(\\(\\))?\\]");
  122. RegEx keyword_csharp_remotesync = RegEx("\\[(Remote)?Sync(Attribute)?(\\(\\))?\\]");
  123. RegEx keyword_csharp_puppet = RegEx("\\[(Puppet|Slave)(Attribute)?(\\(\\))?\\]");
  124. RegEx keyword_csharp_puppetsync = RegEx("\\[PuppetSync(Attribute)?(\\(\\))?\\]");
  125. RegEx keyword_csharp_master = RegEx("\\[Master(Attribute)?(\\(\\))?\\]");
  126. RegEx keyword_csharp_mastersync = RegEx("\\[MasterSync(Attribute)?(\\(\\))?\\]");
  127. // Colors.
  128. LocalVector<RegEx *> color_regexes;
  129. LocalVector<String> color_renamed;
  130. RegEx color_hexadecimal_short_constructor = RegEx("Color\\(\"#?([a-fA-F0-9]{1})([a-fA-F0-9]{3})\\b");
  131. RegEx color_hexadecimal_full_constructor = RegEx("Color\\(\"#?([a-fA-F0-9]{2})([a-fA-F0-9]{6})\\b");
  132. // Classes.
  133. LocalVector<RegEx *> class_tscn_regexes;
  134. LocalVector<RegEx *> class_gd_regexes;
  135. LocalVector<RegEx *> class_shader_regexes;
  136. // Keycode.
  137. RegEx input_map_keycode = RegEx("\\b,\"((physical_)?)scancode\":(\\d+)\\b");
  138. // Button index and joypad axis.
  139. RegEx joypad_button_index = RegEx("\\b,\"button_index\":(\\d+),(\"pressure\":\\d+\\.\\d+,\"pressed\":(false|true))\\b");
  140. RegEx joypad_axis = RegEx("\\b,\"axis\":(\\d+)\\b");
  141. // Index represents Godot 3's value, entry represents Godot 4 value equivalency.
  142. // i.e: Button4(L1 - Godot3) -> joypad_button_mappings[4]=9 -> Button9(L1 - Godot4).
  143. int joypad_button_mappings[23] = { 0, 1, 2, 3, 9, 10, -1 /*L2*/, -1 /*R2*/, 7, 8, 4, 6, 11, 12, 13, 14, 5, 15, 16, 17, 18, 19, 20 };
  144. // Entries for L2 and R2 are -1 since they match to joypad axes and no longer to joypad buttons in Godot 4.
  145. LocalVector<RegEx *> class_regexes;
  146. RegEx class_temp_tscn = RegEx("\\bTEMP_RENAMED_CLASS.tscn\\b");
  147. RegEx class_temp_gd = RegEx("\\bTEMP_RENAMED_CLASS.gd\\b");
  148. RegEx class_temp_shader = RegEx("\\bTEMP_RENAMED_CLASS.shader\\b");
  149. LocalVector<String> class_temp_tscn_renames;
  150. LocalVector<String> class_temp_gd_renames;
  151. LocalVector<String> class_temp_shader_renames;
  152. // Common.
  153. LocalVector<RegEx *> enum_regexes;
  154. LocalVector<RegEx *> gdscript_function_regexes;
  155. LocalVector<RegEx *> project_settings_regexes;
  156. LocalVector<RegEx *> project_godot_regexes;
  157. LocalVector<RegEx *> input_map_regexes;
  158. LocalVector<RegEx *> gdscript_properties_regexes;
  159. LocalVector<RegEx *> gdscript_signals_regexes;
  160. LocalVector<RegEx *> shaders_regexes;
  161. LocalVector<RegEx *> builtin_types_regexes;
  162. LocalVector<RegEx *> theme_override_regexes;
  163. LocalVector<RegEx *> csharp_function_regexes;
  164. LocalVector<RegEx *> csharp_properties_regexes;
  165. LocalVector<RegEx *> csharp_signal_regexes;
  166. RegExContainer() {
  167. // Common.
  168. {
  169. // Enum.
  170. for (unsigned int current_index = 0; RenamesMap3To4::enum_renames[current_index][0]; current_index++) {
  171. enum_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::enum_renames[current_index][0] + "\\b")));
  172. }
  173. // GDScript functions.
  174. for (unsigned int current_index = 0; RenamesMap3To4::gdscript_function_renames[current_index][0]; current_index++) {
  175. gdscript_function_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_function_renames[current_index][0] + "\\b")));
  176. }
  177. // Project Settings in scripts.
  178. for (unsigned int current_index = 0; RenamesMap3To4::project_settings_renames[current_index][0]; current_index++) {
  179. project_settings_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::project_settings_renames[current_index][0] + "\\b")));
  180. }
  181. // Project Settings in project.godot.
  182. for (unsigned int current_index = 0; RenamesMap3To4::project_godot_renames[current_index][0]; current_index++) {
  183. project_godot_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::project_godot_renames[current_index][0] + "\\b")));
  184. }
  185. // Input Map.
  186. for (unsigned int current_index = 0; RenamesMap3To4::input_map_renames[current_index][0]; current_index++) {
  187. input_map_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::input_map_renames[current_index][0] + "\\b")));
  188. }
  189. // GDScript properties.
  190. for (unsigned int current_index = 0; RenamesMap3To4::gdscript_properties_renames[current_index][0]; current_index++) {
  191. gdscript_properties_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_properties_renames[current_index][0] + "\\b")));
  192. }
  193. // GDScript Signals.
  194. for (unsigned int current_index = 0; RenamesMap3To4::gdscript_signals_renames[current_index][0]; current_index++) {
  195. gdscript_signals_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_signals_renames[current_index][0] + "\\b")));
  196. }
  197. // Shaders.
  198. for (unsigned int current_index = 0; RenamesMap3To4::shaders_renames[current_index][0]; current_index++) {
  199. shaders_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::shaders_renames[current_index][0] + "\\b")));
  200. }
  201. // Builtin types.
  202. for (unsigned int current_index = 0; RenamesMap3To4::builtin_types_renames[current_index][0]; current_index++) {
  203. builtin_types_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::builtin_types_renames[current_index][0] + "\\b")));
  204. }
  205. // Theme overrides.
  206. for (unsigned int current_index = 0; RenamesMap3To4::theme_override_renames[current_index][0]; current_index++) {
  207. theme_override_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::theme_override_renames[current_index][0] + "\\b")));
  208. }
  209. // CSharp function renames.
  210. for (unsigned int current_index = 0; RenamesMap3To4::csharp_function_renames[current_index][0]; current_index++) {
  211. csharp_function_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_function_renames[current_index][0] + "\\b")));
  212. }
  213. // CSharp properties renames.
  214. for (unsigned int current_index = 0; RenamesMap3To4::csharp_properties_renames[current_index][0]; current_index++) {
  215. csharp_properties_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_properties_renames[current_index][0] + "\\b")));
  216. }
  217. // CSharp signals renames.
  218. for (unsigned int current_index = 0; RenamesMap3To4::csharp_signals_renames[current_index][0]; current_index++) {
  219. csharp_signal_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_signals_renames[current_index][0] + "\\b")));
  220. }
  221. }
  222. // Colors.
  223. {
  224. for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {
  225. color_regexes.push_back(memnew(RegEx(String("\\bColor.") + RenamesMap3To4::color_renames[current_index][0] + "\\b")));
  226. color_renamed.push_back(String("Color.") + RenamesMap3To4::color_renames[current_index][1]);
  227. }
  228. }
  229. // Classes.
  230. {
  231. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  232. const String class_name = RenamesMap3To4::class_renames[current_index][0];
  233. class_tscn_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".tscn\\b")));
  234. class_gd_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".gd\\b")));
  235. class_shader_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".shader\\b")));
  236. class_regexes.push_back(memnew(RegEx(String("\\b") + class_name + "\\b")));
  237. class_temp_tscn_renames.push_back(class_name + ".tscn");
  238. class_temp_gd_renames.push_back(class_name + ".gd");
  239. class_temp_shader_renames.push_back(class_name + ".shader");
  240. }
  241. }
  242. }
  243. ~RegExContainer() {
  244. for (RegEx *regex : color_regexes) {
  245. memdelete(regex);
  246. }
  247. for (unsigned int i = 0; i < class_tscn_regexes.size(); i++) {
  248. memdelete(class_tscn_regexes[i]);
  249. memdelete(class_gd_regexes[i]);
  250. memdelete(class_shader_regexes[i]);
  251. memdelete(class_regexes[i]);
  252. }
  253. for (RegEx *regex : enum_regexes) {
  254. memdelete(regex);
  255. }
  256. for (RegEx *regex : gdscript_function_regexes) {
  257. memdelete(regex);
  258. }
  259. for (RegEx *regex : project_settings_regexes) {
  260. memdelete(regex);
  261. }
  262. for (RegEx *regex : project_godot_regexes) {
  263. memdelete(regex);
  264. }
  265. for (RegEx *regex : input_map_regexes) {
  266. memdelete(regex);
  267. }
  268. for (RegEx *regex : gdscript_properties_regexes) {
  269. memdelete(regex);
  270. }
  271. for (RegEx *regex : gdscript_signals_regexes) {
  272. memdelete(regex);
  273. }
  274. for (RegEx *regex : shaders_regexes) {
  275. memdelete(regex);
  276. }
  277. for (RegEx *regex : builtin_types_regexes) {
  278. memdelete(regex);
  279. }
  280. for (RegEx *regex : theme_override_regexes) {
  281. memdelete(regex);
  282. }
  283. for (RegEx *regex : csharp_function_regexes) {
  284. memdelete(regex);
  285. }
  286. for (RegEx *regex : csharp_properties_regexes) {
  287. memdelete(regex);
  288. }
  289. for (RegEx *regex : csharp_signal_regexes) {
  290. memdelete(regex);
  291. }
  292. }
  293. };
  294. ProjectConverter3To4::ProjectConverter3To4(int p_maximum_file_size_kb, int p_maximum_line_length) {
  295. maximum_file_size = p_maximum_file_size_kb * 1024;
  296. maximum_line_length = p_maximum_line_length;
  297. }
  298. // Function responsible for converting project.
  299. bool ProjectConverter3To4::convert() {
  300. print_line("Starting conversion.");
  301. uint64_t conversion_start_time = Time::get_singleton()->get_ticks_msec();
  302. RegExContainer reg_container = RegExContainer();
  303. int cached_maximum_line_length = maximum_line_length;
  304. maximum_line_length = 10000; // Use only for tests bigger value, to not break them.
  305. ERR_FAIL_COND_V_MSG(!test_array_names(), false, "Cannot start converting due to problems with data in arrays.");
  306. ERR_FAIL_COND_V_MSG(!test_conversion(reg_container), false, "Aborting conversion due to validation tests failing");
  307. maximum_line_length = cached_maximum_line_length;
  308. // Checking if folder contains valid Godot 3 project.
  309. // Project should not be converted more than once.
  310. {
  311. String converter_text = "; Project was converted by built-in tool to Godot 4";
  312. ERR_FAIL_COND_V_MSG(!FileAccess::exists("project.godot"), false, "Current working directory doesn't contain a \"project.godot\" file for a Godot 3 project.");
  313. Error err = OK;
  314. String project_godot_content = FileAccess::get_file_as_string("project.godot", &err);
  315. ERR_FAIL_COND_V_MSG(err != OK, false, "Unable to read \"project.godot\".");
  316. ERR_FAIL_COND_V_MSG(project_godot_content.contains(converter_text), false, "Project was already converted with this tool.");
  317. Ref<FileAccess> file = FileAccess::open("project.godot", FileAccess::WRITE);
  318. ERR_FAIL_COND_V_MSG(file.is_null(), false, "Unable to open \"project.godot\".");
  319. file->store_string(converter_text + "\n" + project_godot_content);
  320. }
  321. Vector<String> collected_files = check_for_files();
  322. uint32_t converted_files = 0;
  323. // Check file by file.
  324. for (int i = 0; i < collected_files.size(); i++) {
  325. String file_name = collected_files[i];
  326. Vector<SourceLine> source_lines;
  327. uint32_t ignored_lines = 0;
  328. {
  329. Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::READ);
  330. ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to read content of \"%s\".", file_name));
  331. while (!file->eof_reached()) {
  332. String line = file->get_line();
  333. SourceLine source_line;
  334. source_line.line = line;
  335. source_line.is_comment = reg_container.gdscript_comment.search_all(line).size() > 0 || reg_container.csharp_comment.search_all(line).size() > 0;
  336. source_lines.append(source_line);
  337. }
  338. }
  339. String file_content_before = collect_string_from_vector(source_lines);
  340. uint64_t hash_before = file_content_before.hash();
  341. uint64_t file_size = file_content_before.size();
  342. print_line(vformat("Trying to convert\t%d/%d file - \"%s\" with size - %d KB", i + 1, collected_files.size(), file_name.trim_prefix("res://"), file_size / 1024));
  343. Vector<String> reason;
  344. bool is_ignored = false;
  345. uint64_t start_time = Time::get_singleton()->get_ticks_msec();
  346. if (file_name.ends_with(".shader")) {
  347. DirAccess::remove_file_or_error(file_name.trim_prefix("res://"));
  348. file_name = file_name.replace(".shader", ".gdshader");
  349. }
  350. if (file_size < uint64_t(maximum_file_size)) {
  351. // ".tscn" must work exactly the same as ".gd" files because they may contain built-in Scripts.
  352. if (file_name.ends_with(".gd")) {
  353. fix_tool_declaration(source_lines, reg_container);
  354. rename_classes(source_lines, reg_container); // Using only specialized function.
  355. rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, source_lines);
  356. rename_colors(source_lines, reg_container); // Require to additional rename.
  357. rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, source_lines);
  358. rename_gdscript_functions(source_lines, reg_container, false); // Require to additional rename.
  359. rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, source_lines);
  360. rename_gdscript_keywords(source_lines, reg_container, false);
  361. rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, source_lines);
  362. rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);
  363. rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
  364. rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
  365. rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);
  366. custom_rename(source_lines, "\\.shader", ".gdshader");
  367. convert_hexadecimal_colors(source_lines, reg_container);
  368. } else if (file_name.ends_with(".tscn")) {
  369. fix_pause_mode(source_lines, reg_container);
  370. rename_classes(source_lines, reg_container); // Using only specialized function.
  371. rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, source_lines);
  372. rename_colors(source_lines, reg_container); // Require to do additional renames.
  373. rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, source_lines);
  374. rename_gdscript_functions(source_lines, reg_container, true); // Require to do additional renames.
  375. rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, source_lines);
  376. rename_gdscript_keywords(source_lines, reg_container, true);
  377. rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, source_lines);
  378. rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);
  379. rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
  380. rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
  381. rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);
  382. custom_rename(source_lines, "\\.shader", ".gdshader");
  383. convert_hexadecimal_colors(source_lines, reg_container);
  384. } else if (file_name.ends_with(".cs")) { // TODO, C# should use different methods.
  385. rename_classes(source_lines, reg_container); // Using only specialized function.
  386. rename_common(RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, source_lines);
  387. rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
  388. rename_common(RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, source_lines);
  389. rename_common(RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, source_lines);
  390. rename_csharp_functions(source_lines, reg_container);
  391. rename_csharp_attributes(source_lines, reg_container);
  392. custom_rename(source_lines, "public class ", "public partial class ");
  393. convert_hexadecimal_colors(source_lines, reg_container);
  394. } else if (file_name.ends_with(".gdshader") || file_name.ends_with(".shader")) {
  395. rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
  396. } else if (file_name.ends_with("tres")) {
  397. rename_classes(source_lines, reg_container); // Using only specialized function.
  398. rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);
  399. rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
  400. custom_rename(source_lines, "\\.shader", ".gdshader");
  401. } else if (file_name.ends_with("project.godot")) {
  402. rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, source_lines);
  403. rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);
  404. rename_input_map_scancode(source_lines, reg_container);
  405. rename_joypad_buttons_and_axes(source_lines, reg_container);
  406. rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, source_lines);
  407. custom_rename(source_lines, "config_version=4", "config_version=5");
  408. } else if (file_name.ends_with(".csproj")) {
  409. // TODO
  410. } else if (file_name.ends_with(".import")) {
  411. for (SourceLine &source_line : source_lines) {
  412. String &line = source_line.line;
  413. if (line.contains("nodes/root_type=\"Spatial\"")) {
  414. line = "nodes/root_type=\"Node3D\"";
  415. } else if (line == "importer=\"ogg_vorbis\"") {
  416. line = "importer=\"oggvorbisstr\"";
  417. }
  418. }
  419. } else {
  420. ERR_PRINT(file_name + " is not supported!");
  421. continue;
  422. }
  423. for (SourceLine &source_line : source_lines) {
  424. if (source_line.is_comment) {
  425. continue;
  426. }
  427. String &line = source_line.line;
  428. if (uint64_t(line.length()) > maximum_line_length) {
  429. ignored_lines += 1;
  430. }
  431. }
  432. } else {
  433. reason.append(vformat(" ERROR: File has exceeded the maximum size allowed - %d KB", maximum_file_size / 1024));
  434. is_ignored = true;
  435. }
  436. uint64_t end_time = Time::get_singleton()->get_ticks_msec();
  437. if (is_ignored) {
  438. String end_message = vformat(" Checking file took %d ms.", end_time - start_time);
  439. print_line(end_message);
  440. } else {
  441. String file_content_after = collect_string_from_vector(source_lines);
  442. uint64_t hash_after = file_content_after.hash64();
  443. // Don't need to save file without any changes.
  444. // Save if this is a shader, because it was renamed.
  445. if (hash_before != hash_after || file_name.ends_with(".gdshader")) {
  446. converted_files++;
  447. Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::WRITE);
  448. ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to apply changes to \"%s\", no writing access.", file_name));
  449. file->store_string(file_content_after);
  450. reason.append(vformat(" File was changed, conversion took %d ms.", end_time - start_time));
  451. } else {
  452. reason.append(vformat(" File was left unchanged, checking took %d ms.", end_time - start_time));
  453. }
  454. if (ignored_lines != 0) {
  455. reason.append(vformat(" Ignored %d lines, because their length exceeds maximum allowed characters - %d.", ignored_lines, maximum_line_length));
  456. }
  457. }
  458. for (int k = 0; k < reason.size(); k++) {
  459. print_line(reason[k]);
  460. }
  461. }
  462. print_line(vformat("Conversion ended - all files(%d), converted files: (%d), not converted files: (%d).", collected_files.size(), converted_files, collected_files.size() - converted_files));
  463. uint64_t conversion_end_time = Time::get_singleton()->get_ticks_msec();
  464. print_line(vformat("Conversion of all files took %10.3f seconds.", (conversion_end_time - conversion_start_time) / 1000.0));
  465. return true;
  466. }
  467. // Function responsible for validating project conversion.
  468. bool ProjectConverter3To4::validate_conversion() {
  469. print_line("Starting checking if project conversion can be done.");
  470. uint64_t conversion_start_time = Time::get_singleton()->get_ticks_msec();
  471. RegExContainer reg_container = RegExContainer();
  472. int cached_maximum_line_length = maximum_line_length;
  473. maximum_line_length = 10000; // To avoid breaking the tests, only use this for the their larger value.
  474. ERR_FAIL_COND_V_MSG(!test_array_names(), false, "Cannot start converting due to problems with data in arrays.");
  475. ERR_FAIL_COND_V_MSG(!test_conversion(reg_container), false, "Aborting conversion due to validation tests failing");
  476. maximum_line_length = cached_maximum_line_length;
  477. // Checking if folder contains valid Godot 3 project.
  478. // Project should not be converted more than once.
  479. {
  480. String conventer_text = "; Project was converted by built-in tool to Godot 4";
  481. ERR_FAIL_COND_V_MSG(!FileAccess::exists("project.godot"), false, "Current directory doesn't contain any Godot 3 project");
  482. Error err = OK;
  483. String project_godot_content = FileAccess::get_file_as_string("project.godot", &err);
  484. ERR_FAIL_COND_V_MSG(err != OK, false, "Failed to read content of \"project.godot\" file.");
  485. ERR_FAIL_COND_V_MSG(project_godot_content.contains(conventer_text), false, "Project already was converted with this tool.");
  486. }
  487. Vector<String> collected_files = check_for_files();
  488. uint32_t converted_files = 0;
  489. // Check file by file.
  490. for (int i = 0; i < collected_files.size(); i++) {
  491. const String &file_name = collected_files[i];
  492. Vector<String> lines;
  493. uint32_t ignored_lines = 0;
  494. uint64_t file_size = 0;
  495. {
  496. Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::READ);
  497. ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to read content of \"%s\".", file_name));
  498. while (!file->eof_reached()) {
  499. String line = file->get_line();
  500. file_size += line.size();
  501. lines.append(line);
  502. }
  503. }
  504. print_line(vformat("Checking for conversion - %d/%d file - \"%s\" with size - %d KB", i + 1, collected_files.size(), file_name.trim_prefix("res://"), file_size / 1024));
  505. Vector<String> changed_elements;
  506. Vector<String> reason;
  507. bool is_ignored = false;
  508. uint64_t start_time = Time::get_singleton()->get_ticks_msec();
  509. if (file_name.ends_with(".shader")) {
  510. reason.append("\tFile extension will be renamed from \"shader\" to \"gdshader\".");
  511. }
  512. if (file_size < uint64_t(maximum_file_size)) {
  513. if (file_name.ends_with(".gd")) {
  514. changed_elements.append_array(check_for_rename_classes(lines, reg_container));
  515. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, lines));
  516. changed_elements.append_array(check_for_rename_colors(lines, reg_container));
  517. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, lines));
  518. changed_elements.append_array(check_for_rename_gdscript_functions(lines, reg_container, false));
  519. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, lines));
  520. changed_elements.append_array(check_for_rename_gdscript_keywords(lines, reg_container, false));
  521. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, lines));
  522. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));
  523. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
  524. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
  525. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));
  526. changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));
  527. } else if (file_name.ends_with(".tscn")) {
  528. changed_elements.append_array(check_for_rename_classes(lines, reg_container));
  529. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, lines));
  530. changed_elements.append_array(check_for_rename_colors(lines, reg_container));
  531. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, lines));
  532. changed_elements.append_array(check_for_rename_gdscript_functions(lines, reg_container, true));
  533. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, lines));
  534. changed_elements.append_array(check_for_rename_gdscript_keywords(lines, reg_container, true));
  535. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, lines));
  536. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));
  537. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
  538. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
  539. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));
  540. changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));
  541. } else if (file_name.ends_with(".cs")) {
  542. changed_elements.append_array(check_for_rename_classes(lines, reg_container));
  543. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, lines));
  544. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
  545. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, lines));
  546. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, lines));
  547. changed_elements.append_array(check_for_rename_csharp_functions(lines, reg_container));
  548. changed_elements.append_array(check_for_rename_csharp_attributes(lines, reg_container));
  549. changed_elements.append_array(check_for_custom_rename(lines, "public class ", "public partial class "));
  550. } else if (file_name.ends_with(".gdshader") || file_name.ends_with(".shader")) {
  551. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
  552. } else if (file_name.ends_with("tres")) {
  553. changed_elements.append_array(check_for_rename_classes(lines, reg_container));
  554. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));
  555. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
  556. changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));
  557. } else if (file_name.ends_with("project.godot")) {
  558. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, lines));
  559. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
  560. changed_elements.append_array(check_for_rename_input_map_scancode(lines, reg_container));
  561. changed_elements.append_array(check_for_rename_joypad_buttons_and_axes(lines, reg_container));
  562. changed_elements.append_array(check_for_rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, lines));
  563. } else if (file_name.ends_with(".csproj")) {
  564. // TODO
  565. } else {
  566. ERR_PRINT(vformat("\"%s\", is not supported!", file_name));
  567. continue;
  568. }
  569. for (String &line : lines) {
  570. if (uint64_t(line.length()) > maximum_line_length) {
  571. ignored_lines += 1;
  572. }
  573. }
  574. } else {
  575. reason.append(vformat("\tERROR: File has exceeded the maximum size allowed - %d KB.", maximum_file_size / 1024));
  576. is_ignored = true;
  577. }
  578. uint64_t end_time = Time::get_singleton()->get_ticks_msec();
  579. String end_message = vformat(" Checking file took %10.3f ms.", (end_time - start_time) / 1000.0);
  580. if (ignored_lines != 0) {
  581. end_message += vformat(" Ignored %d lines, because their length exceeds maximum allowed characters - %d.", ignored_lines, maximum_line_length);
  582. }
  583. print_line(end_message);
  584. for (int k = 0; k < reason.size(); k++) {
  585. print_line(reason[k]);
  586. }
  587. if (changed_elements.size() > 0 && !is_ignored) {
  588. converted_files++;
  589. for (int k = 0; k < changed_elements.size(); k++) {
  590. print_line(String("\t\t") + changed_elements[k]);
  591. }
  592. }
  593. }
  594. print_line(vformat("Checking for valid conversion ended - all files(%d), files which would be converted(%d), files which would not be converted(%d).", collected_files.size(), converted_files, collected_files.size() - converted_files));
  595. uint64_t conversion_end_time = Time::get_singleton()->get_ticks_msec();
  596. print_line(vformat("Conversion of all files took %10.3f seconds.", (conversion_end_time - conversion_start_time) / 1000.0));
  597. return true;
  598. }
  599. // Collect files which will be checked, excluding ".txt", ".mp4", ".wav" etc. files.
  600. Vector<String> ProjectConverter3To4::check_for_files() {
  601. Vector<String> collected_files = Vector<String>();
  602. Vector<String> directories_to_check = Vector<String>();
  603. directories_to_check.push_back("res://");
  604. while (!directories_to_check.is_empty()) {
  605. String path = directories_to_check.get(directories_to_check.size() - 1); // Is there any pop_back function?
  606. directories_to_check.resize(directories_to_check.size() - 1); // Remove last element
  607. Ref<DirAccess> dir = DirAccess::open(path);
  608. if (dir.is_valid()) {
  609. dir->set_include_hidden(true);
  610. dir->list_dir_begin();
  611. String current_dir = dir->get_current_dir();
  612. String file_name = dir->_get_next();
  613. while (file_name != "") {
  614. if (file_name == ".git" || file_name == ".godot") {
  615. file_name = dir->_get_next();
  616. continue;
  617. }
  618. if (dir->current_is_dir()) {
  619. directories_to_check.append(current_dir.path_join(file_name) + "/");
  620. } else {
  621. bool proper_extension = false;
  622. if (file_name.ends_with(".gd") || file_name.ends_with(".shader") || file_name.ends_with(".gdshader") || file_name.ends_with(".tscn") || file_name.ends_with(".tres") || file_name.ends_with(".godot") || file_name.ends_with(".cs") || file_name.ends_with(".csproj") || file_name.ends_with(".import"))
  623. proper_extension = true;
  624. if (proper_extension) {
  625. collected_files.append(current_dir.path_join(file_name));
  626. }
  627. }
  628. file_name = dir->_get_next();
  629. }
  630. } else {
  631. print_verbose("Failed to open " + path);
  632. }
  633. }
  634. return collected_files;
  635. }
  636. Vector<SourceLine> ProjectConverter3To4::split_lines(const String &text) {
  637. Vector<String> lines = text.split("\n");
  638. Vector<SourceLine> source_lines;
  639. for (String &line : lines) {
  640. SourceLine source_line;
  641. source_line.line = line;
  642. source_line.is_comment = false;
  643. source_lines.append(source_line);
  644. }
  645. return source_lines;
  646. }
  647. // Test expected results of gdscript
  648. bool ProjectConverter3To4::test_conversion_gdscript_builtin(const String &name, const String &expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &, bool), const String &what, const RegExContainer &reg_container, bool builtin_script) {
  649. Vector<SourceLine> got = split_lines(name);
  650. (this->*func)(got, reg_container, builtin_script);
  651. String got_str = collect_string_from_vector(got);
  652. ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));
  653. return true;
  654. }
  655. bool ProjectConverter3To4::test_conversion_with_regex(const String &name, const String &expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &), const String &what, const RegExContainer &reg_container) {
  656. Vector<SourceLine> got = split_lines(name);
  657. (this->*func)(got, reg_container);
  658. String got_str = collect_string_from_vector(got);
  659. ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));
  660. return true;
  661. }
  662. bool ProjectConverter3To4::test_conversion_basic(const String &name, const String &expected, const char *array[][2], LocalVector<RegEx *> &regex_cache, const String &what) {
  663. Vector<SourceLine> got = split_lines(name);
  664. rename_common(array, regex_cache, got);
  665. String got_str = collect_string_from_vector(got);
  666. ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));
  667. return true;
  668. }
  669. // Validate if conversions are proper.
  670. bool ProjectConverter3To4::test_conversion(RegExContainer &reg_container) {
  671. bool valid = true;
  672. valid = valid && test_conversion_with_regex("tool", "@tool", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);
  673. valid = valid && test_conversion_with_regex("\n tool", "\n tool", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);
  674. valid = valid && test_conversion_with_regex("\n\ntool", "@tool\n\n", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);
  675. valid = valid && test_conversion_with_regex("pause_mode = 2", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);
  676. valid = valid && test_conversion_with_regex("pause_mode = 1", "pause_mode = 1", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);
  677. valid = valid && test_conversion_with_regex("pause_mode = 3", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);
  678. valid = valid && test_conversion_with_regex("somepause_mode = 2", "somepause_mode = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);
  679. valid = valid && test_conversion_with_regex("pause_mode_ext = 2", "pause_mode_ext = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);
  680. valid = valid && test_conversion_basic("TYPE_REAL", "TYPE_FLOAT", RenamesMap3To4::enum_renames, reg_container.enum_regexes, "enum");
  681. valid = valid && test_conversion_basic("can_instance", "can_instantiate", RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, "gdscript function");
  682. valid = valid && test_conversion_basic("CanInstance", "CanInstantiate", RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, "csharp function");
  683. valid = valid && test_conversion_basic("translation", "position", RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, "gdscript property");
  684. valid = valid && test_conversion_basic("Translation", "Position", RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, "csharp property");
  685. valid = valid && test_conversion_basic("NORMALMAP", "NORMAL_MAP", RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, "shader");
  686. valid = valid && test_conversion_basic("text_entered", "text_submitted", RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, "gdscript signal");
  687. valid = valid && test_conversion_basic("TextEntered", "TextSubmitted", RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, "csharp signal");
  688. valid = valid && test_conversion_basic("audio/channel_disable_threshold_db", "audio/buses/channel_disable_threshold_db", RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, "project setting");
  689. valid = valid && test_conversion_basic("\"device\":-1,\"alt\":false,\"shift\":false,\"control\":false,\"meta\":false,\"doubleclick\":false,\"scancode\":0,\"physical_scancode\":16777254,\"script\":null", "\"device\":-1,\"alt_pressed\":false,\"shift_pressed\":false,\"ctrl_pressed\":false,\"meta_pressed\":false,\"double_click\":false,\"keycode\":0,\"physical_keycode\":16777254,\"script\":null", RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, "input map");
  690. valid = valid && test_conversion_basic("Transform", "Transform3D", RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, "builtin type");
  691. valid = valid && test_conversion_basic("custom_constants/margin_right", "theme_override_constants/margin_right", RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, "theme overrides");
  692. // Custom Renames.
  693. valid = valid && test_conversion_with_regex("(Connect(A,B,C,D,E,F,G) != OK):", "(Connect(A, new Callable(B, C), D, E, F, G) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename csharp", reg_container);
  694. valid = valid && test_conversion_with_regex("(Disconnect(A,B,C) != OK):", "(Disconnect(A, new Callable(B, C)) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename csharp", reg_container);
  695. valid = valid && test_conversion_with_regex("(IsConnected(A,B,C) != OK):", "(IsConnected(A, new Callable(B, C)) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename", reg_container);
  696. valid = valid && test_conversion_with_regex("[Remote]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  697. valid = valid && test_conversion_with_regex("[RemoteSync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  698. valid = valid && test_conversion_with_regex("[Sync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  699. valid = valid && test_conversion_with_regex("[Slave]", "[RPC]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  700. valid = valid && test_conversion_with_regex("[Puppet]", "[RPC]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  701. valid = valid && test_conversion_with_regex("[PuppetSync]", "[RPC(CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  702. valid = valid && test_conversion_with_regex("[Master]", "The master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using Multiplayer.GetRemoteSenderId()\n[RPC]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  703. valid = valid && test_conversion_with_regex("[MasterSync]", "The master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using Multiplayer.GetRemoteSenderId()\n[RPC(CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);
  704. valid = valid && test_conversion_gdscript_builtin("\tif OS.window_resizable: pass", "\tif (not get_window().unresizable): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  705. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_window_resizable(): pass", "\tif (not get_window().unresizable): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  706. valid = valid && test_conversion_gdscript_builtin("\tOS.set_window_resizable(Settings.resizable)", "\tget_window().unresizable = not (Settings.resizable)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  707. valid = valid && test_conversion_gdscript_builtin("\tOS.window_resizable = Settings.resizable", "\tget_window().unresizable = not (Settings.resizable)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  708. valid = valid && test_conversion_gdscript_builtin("\tif OS.window_fullscreen: pass", "\tif ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN)): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  709. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_window_fullscreen(): pass", "\tif ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN)): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  710. valid = valid && test_conversion_gdscript_builtin("\tOS.set_window_fullscreen(Settings.fullscreen)", "\tget_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (Settings.fullscreen) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  711. valid = valid && test_conversion_gdscript_builtin("\tOS.window_fullscreen = Settings.fullscreen", "\tget_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (Settings.fullscreen) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  712. valid = valid && test_conversion_gdscript_builtin("\tif OS.window_maximized: pass", "\tif (get_window().mode == Window.MODE_MAXIMIZED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  713. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_window_maximized(): pass", "\tif (get_window().mode == Window.MODE_MAXIMIZED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  714. valid = valid && test_conversion_gdscript_builtin("\tOS.set_window_maximized(Settings.maximized)", "\tget_window().mode = Window.MODE_MAXIMIZED if (Settings.maximized) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  715. valid = valid && test_conversion_gdscript_builtin("\tOS.window_maximized = Settings.maximized", "\tget_window().mode = Window.MODE_MAXIMIZED if (Settings.maximized) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  716. valid = valid && test_conversion_gdscript_builtin("\tif OS.window_minimized: pass", "\tif (get_window().mode == Window.MODE_MINIMIZED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  717. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_window_minimized(): pass", "\tif (get_window().mode == Window.MODE_MINIMIZED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  718. valid = valid && test_conversion_gdscript_builtin("\tOS.set_window_minimized(Settings.minimized)", "\tget_window().mode = Window.MODE_MINIMIZED if (Settings.minimized) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  719. valid = valid && test_conversion_gdscript_builtin("\tOS.window_minimized = Settings.minimized", "\tget_window().mode = Window.MODE_MINIMIZED if (Settings.minimized) else Window.MODE_WINDOWED", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  720. valid = valid && test_conversion_gdscript_builtin("\tif OS.vsync_enabled: pass", "\tif (DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  721. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_vsync_enabled(): pass", "\tif (DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED): pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  722. valid = valid && test_conversion_gdscript_builtin("\tOS.set_use_vsync(Settings.vsync)", "\tDisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (Settings.vsync) else DisplayServer.VSYNC_DISABLED)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  723. valid = valid && test_conversion_gdscript_builtin("\tOS.vsync_enabled = Settings.vsync", "\tDisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (Settings.vsync) else DisplayServer.VSYNC_DISABLED)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  724. valid = valid && test_conversion_gdscript_builtin("\tif OS.screen_orientation = OS.SCREEN_ORIENTATION_VERTICAL: pass", "\tif DisplayServer.screen_get_orientation() = DisplayServer.SCREEN_VERTICAL: pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  725. valid = valid && test_conversion_gdscript_builtin("\tif OS.get_screen_orientation() = OS.SCREEN_ORIENTATION_LANDSCAPE: pass", "\tif DisplayServer.screen_get_orientation() = DisplayServer.SCREEN_LANDSCAPE: pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  726. valid = valid && test_conversion_gdscript_builtin("\tOS.set_screen_orientation(Settings.orient)", "\tDisplayServer.screen_set_orientation(Settings.orient)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  727. valid = valid && test_conversion_gdscript_builtin("\tOS.screen_orientation = Settings.orient", "\tDisplayServer.screen_set_orientation(Settings.orient)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  728. valid = valid && test_conversion_gdscript_builtin("\tif OS.is_window_always_on_top(): pass", "\tif get_window().always_on_top: pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  729. valid = valid && test_conversion_gdscript_builtin("\tOS.set_window_always_on_top(Settings.alwaystop)", "\tget_window().always_on_top = (Settings.alwaystop)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  730. valid = valid && test_conversion_gdscript_builtin("\tif OS.get_borderless_window(): pass", "\tif get_window().borderless: pass", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  731. valid = valid && test_conversion_gdscript_builtin("\tOS.set_borderless_window(Settings.borderless)", "\tget_window().borderless = (Settings.borderless)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  732. valid = valid && test_conversion_gdscript_builtin("\tvar aa = roman(r.move_and_slide( a, b, c, d, e, f )) # Roman", "\tr.set_velocity(a)\n\tr.set_up_direction(b)\n\tr.set_floor_stop_on_slope_enabled(c)\n\tr.set_max_slides(d)\n\tr.set_floor_max_angle(e)\n\t# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `f`\n\tr.move_and_slide()\n\tvar aa = roman(r.velocity) # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  733. valid = valid && test_conversion_gdscript_builtin("\tmove_and_slide( a, b, c, d, e, f ) # Roman", "\tset_velocity(a)\n\tset_up_direction(b)\n\tset_floor_stop_on_slope_enabled(c)\n\tset_max_slides(d)\n\tset_floor_max_angle(e)\n\t# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `f`\n\tmove_and_slide() # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  734. valid = valid && test_conversion_gdscript_builtin("\tvar aa = roman(r.move_and_slide_with_snap( a, g, b, c, d, e, f )) # Roman", "\tr.set_velocity(a)\n\t# TODOConverter3To4 looks that snap in Godot 4 is float, not vector like in Godot 3 - previous value `g`\n\tr.set_up_direction(b)\n\tr.set_floor_stop_on_slope_enabled(c)\n\tr.set_max_slides(d)\n\tr.set_floor_max_angle(e)\n\t# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `f`\n\tr.move_and_slide()\n\tvar aa = roman(r.velocity) # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  735. valid = valid && test_conversion_gdscript_builtin("\tmove_and_slide_with_snap( a, g, b, c, d, e, f ) # Roman", "\tset_velocity(a)\n\t# TODOConverter3To4 looks that snap in Godot 4 is float, not vector like in Godot 3 - previous value `g`\n\tset_up_direction(b)\n\tset_floor_stop_on_slope_enabled(c)\n\tset_max_slides(d)\n\tset_floor_max_angle(e)\n\t# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `f`\n\tmove_and_slide() # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  736. valid = valid && test_conversion_gdscript_builtin("remove_and_slide(a,b,c,d,e,f)", "remove_and_slide(a,b,c,d,e,f)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  737. valid = valid && test_conversion_gdscript_builtin("list_dir_begin( a , b )", "list_dir_begin() # TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  738. valid = valid && test_conversion_gdscript_builtin("list_dir_begin( a )", "list_dir_begin() # TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  739. valid = valid && test_conversion_gdscript_builtin("list_dir_begin( )", "list_dir_begin() # TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  740. valid = valid && test_conversion_gdscript_builtin("sort_custom( a , b )", "sort_custom(Callable(a, b))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  741. valid = valid && test_conversion_gdscript_builtin("func c(var a, var b)", "func c(a, b)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  742. valid = valid && test_conversion_gdscript_builtin("draw_line(1, 2, 3, 4, 5)", "draw_line(1, 2, 3, 4)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  743. valid = valid && test_conversion_gdscript_builtin("\timage.lock()", "\tfalse # image.lock() # TODOConverter3To4, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  744. valid = valid && test_conversion_gdscript_builtin("\timage.unlock()", "\tfalse # image.unlock() # TODOConverter3To4, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  745. valid = valid && test_conversion_gdscript_builtin("\troman.image.unlock()", "\tfalse # roman.image.unlock() # TODOConverter3To4, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  746. valid = valid && test_conversion_gdscript_builtin("\tmtx.lock()", "\tmtx.lock()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  747. valid = valid && test_conversion_gdscript_builtin("\tmutex.unlock()", "\tmutex.unlock()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  748. valid = valid && test_conversion_with_regex("extends CSGBox", "extends CSGBox3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  749. valid = valid && test_conversion_with_regex("CSGBox", "CSGBox3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  750. valid = valid && test_conversion_with_regex("Spatial", "Node3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  751. valid = valid && test_conversion_with_regex("Spatial.tscn", "Spatial.tscn", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  752. valid = valid && test_conversion_with_regex("Spatial.gd", "Spatial.gd", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  753. valid = valid && test_conversion_with_regex("Spatial.shader", "Spatial.shader", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  754. valid = valid && test_conversion_with_regex("Spatial.other", "Node3D.other", &ProjectConverter3To4::rename_classes, "classes", reg_container);
  755. valid = valid && test_conversion_gdscript_builtin("\nonready", "\n@onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  756. valid = valid && test_conversion_gdscript_builtin("onready", "@onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  757. valid = valid && test_conversion_gdscript_builtin(" onready", " onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  758. valid = valid && test_conversion_gdscript_builtin("\nexport", "\n@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  759. valid = valid && test_conversion_gdscript_builtin("\texport", "\t@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  760. valid = valid && test_conversion_gdscript_builtin("\texport_dialog", "\texport_dialog", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  761. valid = valid && test_conversion_gdscript_builtin("export", "@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  762. valid = valid && test_conversion_gdscript_builtin(" export", " export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  763. valid = valid && test_conversion_gdscript_builtin("\n\nremote func", "\n\n@rpc(\"any_peer\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  764. valid = valid && test_conversion_gdscript_builtin("\n\nremote func", "\n\n@rpc(\\\"any_peer\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);
  765. valid = valid && test_conversion_gdscript_builtin("\n\nremotesync func", "\n\n@rpc(\"any_peer\", \"call_local\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  766. valid = valid && test_conversion_gdscript_builtin("\n\nremotesync func", "\n\n@rpc(\\\"any_peer\\\", \\\"call_local\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);
  767. valid = valid && test_conversion_gdscript_builtin("\n\nsync func", "\n\n@rpc(\"any_peer\", \"call_local\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  768. valid = valid && test_conversion_gdscript_builtin("\n\nsync func", "\n\n@rpc(\\\"any_peer\\\", \\\"call_local\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);
  769. valid = valid && test_conversion_gdscript_builtin("\n\nslave func", "\n\n@rpc func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  770. valid = valid && test_conversion_gdscript_builtin("\n\npuppet func", "\n\n@rpc func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  771. valid = valid && test_conversion_gdscript_builtin("\n\npuppetsync func", "\n\n@rpc(\"call_local\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  772. valid = valid && test_conversion_gdscript_builtin("\n\npuppetsync func", "\n\n@rpc(\\\"call_local\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);
  773. valid = valid && test_conversion_gdscript_builtin("\n\nmaster func", "\n\nThe master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using get_multiplayer().get_remote_sender_id()\n@rpc func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  774. valid = valid && test_conversion_gdscript_builtin("\n\nmastersync func", "\n\nThe master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using get_multiplayer().get_remote_sender_id()\n@rpc(\"call_local\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);
  775. valid = valid && test_conversion_gdscript_builtin("var size: Vector2 = Vector2() setget set_function, get_function", "var size: Vector2 = Vector2(): get = get_function, set = set_function", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  776. valid = valid && test_conversion_gdscript_builtin("var size: Vector2 = Vector2() setget set_function, ", "var size: Vector2 = Vector2(): set = set_function", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  777. valid = valid && test_conversion_gdscript_builtin("var size: Vector2 = Vector2() setget set_function", "var size: Vector2 = Vector2(): set = set_function", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  778. valid = valid && test_conversion_gdscript_builtin("var size: Vector2 = Vector2() setget , get_function", "var size: Vector2 = Vector2(): get = get_function", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  779. valid = valid && test_conversion_gdscript_builtin("get_node(@", "get_node(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  780. valid = valid && test_conversion_gdscript_builtin("yield(this, \"timeout\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  781. valid = valid && test_conversion_gdscript_builtin("yield(this, \\\"timeout\\\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, true);
  782. valid = valid && test_conversion_gdscript_builtin(" Transform.xform(Vector3(a,b,c) + Vector3.UP) ", " Transform * (Vector3(a,b,c) + Vector3.UP) ", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  783. valid = valid && test_conversion_gdscript_builtin(" Transform.xform_inv(Vector3(a,b,c) + Vector3.UP) ", " (Vector3(a,b,c) + Vector3.UP) * Transform ", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  784. valid = valid && test_conversion_gdscript_builtin("export(float) var lifetime = 3.0", "export var lifetime: float = 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  785. valid = valid && test_conversion_gdscript_builtin("export (int)var spaces=1", "export var spaces: int=1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  786. valid = valid && test_conversion_gdscript_builtin("export(String, 'AnonymousPro', 'CourierPrime') var _font_name = 'AnonymousPro'", "export var _font_name = 'AnonymousPro' # (String, 'AnonymousPro', 'CourierPrime')", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false); // TODO, this is only a workaround
  787. valid = valid && test_conversion_gdscript_builtin("export(PackedScene) var mob_scene", "export var mob_scene: PackedScene", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  788. valid = valid && test_conversion_gdscript_builtin("export(float) var lifetime: float = 3.0", "export var lifetime: float = 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  789. valid = valid && test_conversion_gdscript_builtin("export var lifetime: float = 3.0", "export var lifetime: float = 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  790. valid = valid && test_conversion_gdscript_builtin("export var lifetime := 3.0", "export var lifetime := 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  791. valid = valid && test_conversion_gdscript_builtin("export(float) var lifetime := 3.0", "export var lifetime := 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  792. valid = valid && test_conversion_gdscript_builtin("var d = parse_json(roman(sfs))", "var test_json_conv = JSON.new()\ntest_json_conv.parse(roman(sfs))\nvar d = test_json_conv.get_data()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  793. valid = valid && test_conversion_gdscript_builtin("to_json( AA ) szon", "JSON.new().stringify( AA ) szon", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  794. valid = valid && test_conversion_gdscript_builtin("s to_json", "s JSON.new().stringify", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  795. valid = valid && test_conversion_gdscript_builtin("AF to_json2", "AF to_json2", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  796. valid = valid && test_conversion_gdscript_builtin("var rr = JSON.parse(a)", "var test_json_conv = JSON.new()\ntest_json_conv.parse(a)\nvar rr = test_json_conv.get_data()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  797. valid = valid && test_conversion_gdscript_builtin("empty()", "is_empty()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  798. valid = valid && test_conversion_gdscript_builtin(".empty", ".empty", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  799. valid = valid && test_conversion_gdscript_builtin(").roman(", ").roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  800. valid = valid && test_conversion_gdscript_builtin("\t.roman(", "\tsuper.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  801. valid = valid && test_conversion_gdscript_builtin(" .roman(", " super.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  802. valid = valid && test_conversion_gdscript_builtin(".1", ".1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  803. valid = valid && test_conversion_gdscript_builtin(" .1", " .1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  804. valid = valid && test_conversion_gdscript_builtin("'.'", "'.'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  805. valid = valid && test_conversion_gdscript_builtin("'.a'", "'.a'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  806. valid = valid && test_conversion_gdscript_builtin("\t._input(_event)", "\tsuper._input(_event)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  807. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C) != OK):", "(connect(A, Callable(B, C)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  808. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C,D) != OK):", "(connect(A, Callable(B, C).bind(D)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  809. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C,[D]) != OK):", "(connect(A, Callable(B, C).bind(D)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  810. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C,[D,E]) != OK):", "(connect(A, Callable(B, C).bind(D,E)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  811. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C,[D,E],F) != OK):", "(connect(A, Callable(B, C).bind(D,E), F) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  812. valid = valid && test_conversion_gdscript_builtin("(connect(A,B,C,D,E) != OK):", "(connect(A, Callable(B, C).bind(D), E) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  813. valid = valid && test_conversion_gdscript_builtin(".connect(A,B,C)", ".connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  814. valid = valid && test_conversion_gdscript_builtin("abc.connect(A,B,C)", "abc.connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  815. valid = valid && test_conversion_gdscript_builtin("\tconnect(A,B,C)", "\tconnect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  816. valid = valid && test_conversion_gdscript_builtin(" connect(A,B,C)", " connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  817. valid = valid && test_conversion_gdscript_builtin("_connect(A,B,C)", "_connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  818. valid = valid && test_conversion_gdscript_builtin("do_connect(A,B,C)", "do_connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  819. valid = valid && test_conversion_gdscript_builtin("$connect(A,B,C)", "$connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  820. valid = valid && test_conversion_gdscript_builtin("@connect(A,B,C)", "@connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  821. valid = valid && test_conversion_gdscript_builtin("(start(A,B) != OK):", "(start(Callable(A, B)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  822. valid = valid && test_conversion_gdscript_builtin("func start(A,B):", "func start(A,B):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  823. valid = valid && test_conversion_gdscript_builtin("(start(A,B,C,D,E,F,G) != OK):", "(start(Callable(A, B).bind(C), D, E, F, G) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  824. valid = valid && test_conversion_gdscript_builtin("disconnect(A,B,C) != OK):", "disconnect(A, Callable(B, C)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  825. valid = valid && test_conversion_gdscript_builtin("is_connected(A,B,C) != OK):", "is_connected(A, Callable(B, C)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  826. valid = valid && test_conversion_gdscript_builtin("is_connected(A,B,C))", "is_connected(A, Callable(B, C)))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  827. valid = valid && test_conversion_gdscript_builtin("(tween_method(A,B,C,D,E).foo())", "(tween_method(Callable(A, B), C, D, E).foo())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  828. valid = valid && test_conversion_gdscript_builtin("(tween_method(A,B,C,D,E,[F,G]).foo())", "(tween_method(Callable(A, B).bind(F,G), C, D, E).foo())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  829. valid = valid && test_conversion_gdscript_builtin("(tween_callback(A,B).foo())", "(tween_callback(Callable(A, B)).foo())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  830. valid = valid && test_conversion_gdscript_builtin("(tween_callback(A,B,[C,D]).foo())", "(tween_callback(Callable(A, B).bind(C,D)).foo())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  831. valid = valid && test_conversion_gdscript_builtin("func _init(", "func _init(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  832. valid = valid && test_conversion_gdscript_builtin("func _init(a,b,c).(d,e,f):", "func _init(a,b,c):\n\tsuper(d,e,f)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  833. valid = valid && test_conversion_gdscript_builtin("func _init(a,b,c).(a.b(),c.d()):", "func _init(a,b,c):\n\tsuper(a.b(),c.d())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  834. valid = valid && test_conversion_gdscript_builtin("func _init(p_x:int)->void:", "func _init(p_x:int)->void:", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  835. valid = valid && test_conversion_gdscript_builtin("func _init(a: int).(d,e,f) -> void:", "func _init(a: int) -> void:\n\tsuper(d,e,f)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  836. valid = valid && test_conversion_gdscript_builtin("q_PackedDataContainer._iter_init(variable1)", "q_PackedDataContainer._iter_init(variable1)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  837. valid = valid && test_conversion_gdscript_builtin("create_from_image(aa, bb)", "create_from_image(aa) #,bb", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  838. valid = valid && test_conversion_gdscript_builtin("q_ImageTexture.create_from_image(variable1, variable2)", "q_ImageTexture.create_from_image(variable1) #,variable2", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  839. valid = valid && test_conversion_gdscript_builtin("set_cell_item(a, b, c, d ,e) # AA", "set_cell_item(Vector3(a, b, c), d, e) # AA", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  840. valid = valid && test_conversion_gdscript_builtin("set_cell_item(a, b)", "set_cell_item(a, b)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  841. valid = valid && test_conversion_gdscript_builtin("get_cell_item_orientation(a, b,c)", "get_cell_item_orientation(Vector3i(a, b, c))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  842. valid = valid && test_conversion_gdscript_builtin("get_cell_item(a, b,c)", "get_cell_item(Vector3i(a, b, c))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  843. valid = valid && test_conversion_gdscript_builtin("map_to_world(a, b,c)", "map_to_local(Vector3i(a, b, c))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  844. valid = valid && test_conversion_gdscript_builtin("PackedStringArray(req_godot).join('.')", "'.'.join(PackedStringArray(req_godot))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  845. valid = valid && test_conversion_gdscript_builtin("=PackedStringArray(req_godot).join('.')", "='.'.join(PackedStringArray(req_godot))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  846. valid = valid && test_conversion_gdscript_builtin("apply_force(position, impulse)", "apply_force(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  847. valid = valid && test_conversion_gdscript_builtin("apply_impulse(position, impulse)", "apply_impulse(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  848. valid = valid && test_conversion_gdscript_builtin("draw_rect(a,b,c,d,e).abc", "draw_rect(a, b, c, d).abc# e) TODOConverter3To4 Antialiasing argument is missing", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  849. valid = valid && test_conversion_gdscript_builtin("get_focus_owner()", "get_viewport().gui_get_focus_owner()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  850. valid = valid && test_conversion_gdscript_builtin("button.pressed = 1", "button.button_pressed = 1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  851. valid = valid && test_conversion_gdscript_builtin("button.pressed=1", "button.button_pressed=1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  852. valid = valid && test_conversion_gdscript_builtin("button.pressed SF", "button.pressed SF", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  853. valid = valid && test_conversion_with_regex("Color(\"#f47d\")", "Color(\"#47df\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  854. valid = valid && test_conversion_with_regex("Color(\"#ff478cbf\")", "Color(\"#478cbfff\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  855. valid = valid && test_conversion_with_regex("Color(\"#de32bf\")", "Color(\"#de32bf\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  856. valid = valid && test_conversion_with_regex("AAA Color.white AF", "AAA Color.WHITE AF", &ProjectConverter3To4::rename_colors, "color constants", reg_container);
  857. // Note: Do not change to *scancode*, it is applied before that conversion.
  858. valid = valid && test_conversion_with_regex("\"device\":-1,\"scancode\":16777231,\"physical_scancode\":16777232", "\"device\":-1,\"scancode\":4194319,\"physical_scancode\":4194320", &ProjectConverter3To4::rename_input_map_scancode, "custom rename", reg_container);
  859. valid = valid && test_conversion_with_regex("\"device\":-1,\"scancode\":65,\"physical_scancode\":66", "\"device\":-1,\"scancode\":65,\"physical_scancode\":66", &ProjectConverter3To4::rename_input_map_scancode, "custom rename", reg_container);
  860. valid = valid && test_conversion_with_regex("\"device\":0,\"button_index\":5,\"pressure\":0.0,\"pressed\":false,", "\"device\":0,\"button_index\":10,\"pressure\":0.0,\"pressed\":false,", &ProjectConverter3To4::rename_joypad_buttons_and_axes, "custom rename", reg_container);
  861. valid = valid && test_conversion_with_regex("\"device\":0,\"axis\":6,", "\"device\":0,\"axis\":4,", &ProjectConverter3To4::rename_joypad_buttons_and_axes, "custom rename", reg_container);
  862. valid = valid && test_conversion_with_regex("InputEventJoypadButton,\"button_index\":7,\"pressure\":0.0,\"pressed\":false,\"script\":null", "InputEventJoypadMotion,\"axis\":5,\"axis_value\":1.0,\"script\":null", &ProjectConverter3To4::rename_joypad_buttons_and_axes, "custom rename", reg_container);
  863. // Custom rule conversion
  864. {
  865. String from = "instance";
  866. String to = "instantiate";
  867. String name = "AA.instance()";
  868. Vector<SourceLine> got = split_lines(name);
  869. String expected = "AA.instantiate()";
  870. custom_rename(got, from, to);
  871. String got_str = collect_string_from_vector(got);
  872. if (got_str != expected) {
  873. ERR_PRINT(vformat("Failed to convert custom rename \"%s\" to \"%s\", got \"%s\", instead.", name, expected, got_str));
  874. }
  875. valid = valid && (got_str == expected);
  876. }
  877. // get_object_of_execution
  878. {
  879. String base = "var roman = kieliszek.";
  880. String expected = "kieliszek.";
  881. String got = get_object_of_execution(base);
  882. if (got != expected) {
  883. ERR_PRINT(vformat("Failed to get proper data from get_object_of_execution. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", base, expected, expected.size(), got, got.size()));
  884. }
  885. valid = valid && (got == expected);
  886. }
  887. {
  888. String base = "r.";
  889. String expected = "r.";
  890. String got = get_object_of_execution(base);
  891. if (got != expected) {
  892. ERR_PRINT(vformat("Failed to get proper data from get_object_of_execution. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", base, expected, expected.size(), got, got.size()));
  893. }
  894. valid = valid && (got == expected);
  895. }
  896. {
  897. String base = "mortadela(";
  898. String expected = "";
  899. String got = get_object_of_execution(base);
  900. if (got != expected) {
  901. ERR_PRINT(vformat("Failed to get proper data from get_object_of_execution. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", base, expected, expected.size(), got, got.size()));
  902. }
  903. valid = valid && (got == expected);
  904. }
  905. {
  906. String base = "var node = $world/ukraine/lviv.";
  907. String expected = "$world/ukraine/lviv.";
  908. String got = get_object_of_execution(base);
  909. if (got != expected) {
  910. ERR_PRINT(vformat("Failed to get proper data from get_object_of_execution. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", base, expected, expected.size(), got, got.size()));
  911. }
  912. valid = valid && (got == expected);
  913. }
  914. // get_starting_space
  915. {
  916. String base = "\t\t\t var roman = kieliszek.";
  917. String expected = "\t\t\t";
  918. String got = get_starting_space(base);
  919. if (got != expected) {
  920. ERR_PRINT(vformat("Failed to get proper data from get_object_of_execution. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", base, expected, expected.size(), got, got.size()));
  921. }
  922. valid = valid && (got == expected);
  923. }
  924. // Parse Arguments
  925. {
  926. String line = "( )";
  927. Vector<String> got_vector = parse_arguments(line);
  928. String got = "";
  929. String expected = "";
  930. for (String &part : got_vector) {
  931. got += part + "|||";
  932. }
  933. if (got != expected) {
  934. ERR_PRINT(vformat("Failed to get proper data from parse_arguments. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", line, expected, expected.size(), got, got.size()));
  935. }
  936. valid = valid && (got == expected);
  937. }
  938. {
  939. String line = "(a , b , c)";
  940. Vector<String> got_vector = parse_arguments(line);
  941. String got = "";
  942. String expected = "a|||b|||c|||";
  943. for (String &part : got_vector) {
  944. got += part + "|||";
  945. }
  946. if (got != expected) {
  947. ERR_PRINT(vformat("Failed to get proper data from parse_arguments. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", line, expected, expected.size(), got, got.size()));
  948. }
  949. valid = valid && (got == expected);
  950. }
  951. {
  952. String line = "(a , \"b,\" , c)";
  953. Vector<String> got_vector = parse_arguments(line);
  954. String got = "";
  955. String expected = "a|||\"b,\"|||c|||";
  956. for (String &part : got_vector) {
  957. got += part + "|||";
  958. }
  959. if (got != expected) {
  960. ERR_PRINT(vformat("Failed to get proper data from parse_arguments. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", line, expected, expected.size(), got, got.size()));
  961. }
  962. valid = valid && (got == expected);
  963. }
  964. {
  965. String line = "(a , \"(,),,,,\" , c)";
  966. Vector<String> got_vector = parse_arguments(line);
  967. String got = "";
  968. String expected = "a|||\"(,),,,,\"|||c|||";
  969. for (String &part : got_vector) {
  970. got += part + "|||";
  971. }
  972. if (got != expected) {
  973. ERR_PRINT(vformat("Failed to get proper data from parse_arguments. \"%s\" should return \"%s\"(%d), got \"%s\"(%d), instead.", line, expected, expected.size(), got, got.size()));
  974. }
  975. valid = valid && (got == expected);
  976. }
  977. return valid;
  978. }
  979. // Validate in all arrays if names don't do cyclic renames "Node" -> "Node2D" | "Node2D" -> "2DNode"
  980. bool ProjectConverter3To4::test_array_names() {
  981. bool valid = true;
  982. Vector<String> names = Vector<String>();
  983. // Validate if all classes are valid.
  984. {
  985. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  986. const String old_class = RenamesMap3To4::class_renames[current_index][0];
  987. const String new_class = RenamesMap3To4::class_renames[current_index][1];
  988. // Light2D, Texture, Viewport are special classes(probably virtual ones).
  989. if (ClassDB::class_exists(StringName(old_class)) && old_class != "Light2D" && old_class != "Texture" && old_class != "Viewport") {
  990. ERR_PRINT(vformat("Class \"%s\" exists in Godot 4, so it cannot be renamed to something else.", old_class));
  991. valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.
  992. }
  993. // Callable is special class, to which normal classes may be renamed.
  994. if (!ClassDB::class_exists(StringName(new_class)) && new_class != "Callable") {
  995. ERR_PRINT(vformat("Class \"%s\" does not exist in Godot 4, so it cannot be used in the conversion.", new_class));
  996. valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.
  997. }
  998. }
  999. }
  1000. {
  1001. HashSet<String> all_functions;
  1002. // List of excluded functions from builtin types and global namespace, because currently it is not possible to get list of functions from them.
  1003. // This will be available when https://github.com/godotengine/godot/pull/49053 or similar will be included into Godot.
  1004. static const char *builtin_types_excluded_functions[] = { "dict_to_inst", "inst_to_dict", "bytes_to_var", "bytes_to_var_with_objects", "db_to_linear", "deg_to_rad", "linear_to_db", "rad_to_deg", "randf_range", "snapped", "str_to_var", "var_to_str", "var_to_bytes", "var_to_bytes_with_objects", "move_toward", "uri_encode", "uri_decode", "remove_at", "get_rotation_quaternion", "limit_length", "grow_side", "is_absolute_path", "is_valid_int", "lerp", "to_ascii_buffer", "to_utf8_buffer", "to_utf32_buffer", "to_wchar_buffer", "snapped", "remap", "rfind", nullptr };
  1005. for (int current_index = 0; builtin_types_excluded_functions[current_index]; current_index++) {
  1006. all_functions.insert(builtin_types_excluded_functions[current_index]);
  1007. }
  1008. //for (int type = Variant::Type::NIL + 1; type < Variant::Type::VARIANT_MAX; type++) {
  1009. // List<MethodInfo> method_list;
  1010. // Variant::get_method_list_by_type(&method_list, Variant::Type(type));
  1011. // for (MethodInfo &function_data : method_list) {
  1012. // if (!all_functions.has(function_data.name)) {
  1013. // all_functions.insert(function_data.name);
  1014. // }
  1015. // }
  1016. //}
  1017. List<StringName> classes_list;
  1018. ClassDB::get_class_list(&classes_list);
  1019. for (StringName &name_of_class : classes_list) {
  1020. List<MethodInfo> method_list;
  1021. ClassDB::get_method_list(name_of_class, &method_list, true);
  1022. for (MethodInfo &function_data : method_list) {
  1023. if (!all_functions.has(function_data.name)) {
  1024. all_functions.insert(function_data.name);
  1025. }
  1026. }
  1027. }
  1028. int current_element = 0;
  1029. while (RenamesMap3To4::gdscript_function_renames[current_element][0] != nullptr) {
  1030. String name_3_x = RenamesMap3To4::gdscript_function_renames[current_element][0];
  1031. String name_4_0 = RenamesMap3To4::gdscript_function_renames[current_element][1];
  1032. if (!all_functions.has(name_4_0)) {
  1033. ERR_PRINT(vformat("Missing GDScript function in pair (%s - ===> %s <===)", name_3_x, name_4_0));
  1034. valid = false;
  1035. }
  1036. current_element++;
  1037. }
  1038. }
  1039. if (!valid) {
  1040. ERR_PRINT("Found function which is used in the converter, but it cannot be found in Godot 4. Rename this element or remove its entry if it's obsolete.");
  1041. }
  1042. valid = valid && test_single_array(RenamesMap3To4::enum_renames);
  1043. valid = valid && test_single_array(RenamesMap3To4::class_renames, true);
  1044. valid = valid && test_single_array(RenamesMap3To4::gdscript_function_renames, true);
  1045. valid = valid && test_single_array(RenamesMap3To4::csharp_function_renames, true);
  1046. valid = valid && test_single_array(RenamesMap3To4::gdscript_properties_renames, true);
  1047. valid = valid && test_single_array(RenamesMap3To4::csharp_properties_renames, true);
  1048. valid = valid && test_single_array(RenamesMap3To4::shaders_renames, true);
  1049. valid = valid && test_single_array(RenamesMap3To4::gdscript_signals_renames);
  1050. valid = valid && test_single_array(RenamesMap3To4::project_settings_renames);
  1051. valid = valid && test_single_array(RenamesMap3To4::project_godot_renames);
  1052. valid = valid && test_single_array(RenamesMap3To4::input_map_renames);
  1053. valid = valid && test_single_array(RenamesMap3To4::builtin_types_renames);
  1054. valid = valid && test_single_array(RenamesMap3To4::color_renames);
  1055. return valid;
  1056. }
  1057. // Validates the array to prevent cyclic renames, such as `Node` -> `Node2D`, then `Node2D` -> `2DNode`.
  1058. // Also checks if names contain leading or trailing spaces.
  1059. bool ProjectConverter3To4::test_single_array(const char *p_array[][2], bool p_ignore_4_0_name) {
  1060. bool valid = true;
  1061. Vector<String> names = Vector<String>();
  1062. for (unsigned int current_index = 0; p_array[current_index][0]; current_index++) {
  1063. String name_3_x = p_array[current_index][0];
  1064. String name_4_0 = p_array[current_index][1];
  1065. if (name_3_x != name_3_x.strip_edges()) {
  1066. ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));
  1067. valid = false;
  1068. }
  1069. if (names.has(name_3_x)) {
  1070. ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));
  1071. valid = false;
  1072. }
  1073. names.append(name_3_x);
  1074. if (name_4_0 != name_4_0.strip_edges()) {
  1075. ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));
  1076. valid = false;
  1077. }
  1078. if (names.has(name_4_0)) {
  1079. ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));
  1080. valid = false;
  1081. }
  1082. if (!p_ignore_4_0_name) {
  1083. names.append(name_4_0);
  1084. }
  1085. }
  1086. return valid;
  1087. };
  1088. // Returns arguments from given function execution, this cannot be really done as regex.
  1089. // `abc(d,e(f,g),h)` -> [d], [e(f,g)], [h]
  1090. Vector<String> ProjectConverter3To4::parse_arguments(const String &line) {
  1091. Vector<String> parts;
  1092. int string_size = line.length();
  1093. int start_part = 0; // Index of beginning of start part.
  1094. int parts_counter = 0;
  1095. char32_t previous_character = '\0';
  1096. bool is_inside_string = false; // If true, it ignores these 3 characters ( , ) inside string.
  1097. ERR_FAIL_COND_V_MSG(line.count("(") != line.count(")"), parts, vformat("Converter internal bug: substring should have equal number of open and close parentheses in line - \"%s\".", line));
  1098. for (int current_index = 0; current_index < string_size; current_index++) {
  1099. char32_t character = line.get(current_index);
  1100. switch (character) {
  1101. case '(':
  1102. case '[':
  1103. case '{': {
  1104. parts_counter++;
  1105. if (parts_counter == 1 && !is_inside_string) {
  1106. start_part = current_index;
  1107. }
  1108. break;
  1109. };
  1110. case ')':
  1111. case '}': {
  1112. parts_counter--;
  1113. if (parts_counter == 0 && !is_inside_string) {
  1114. parts.append(line.substr(start_part + 1, current_index - start_part - 1));
  1115. start_part = current_index;
  1116. }
  1117. break;
  1118. };
  1119. case ']': {
  1120. parts_counter--;
  1121. if (parts_counter == 0 && !is_inside_string) {
  1122. parts.append(line.substr(start_part, current_index - start_part));
  1123. start_part = current_index;
  1124. }
  1125. break;
  1126. };
  1127. case ',': {
  1128. if (parts_counter == 1 && !is_inside_string) {
  1129. parts.append(line.substr(start_part + 1, current_index - start_part - 1));
  1130. start_part = current_index;
  1131. }
  1132. break;
  1133. };
  1134. case '"': {
  1135. if (previous_character != '\\')
  1136. is_inside_string = !is_inside_string;
  1137. }
  1138. }
  1139. previous_character = character;
  1140. }
  1141. Vector<String> clean_parts;
  1142. for (String &part : parts) {
  1143. part = part.strip_edges();
  1144. if (!part.is_empty()) {
  1145. clean_parts.append(part);
  1146. }
  1147. }
  1148. return clean_parts;
  1149. }
  1150. // Finds latest parenthesis owned by function.
  1151. // `function(abc(a,b),DD)):` finds this parenthess `function(abc(a,b),DD => ) <= ):`
  1152. int ProjectConverter3To4::get_end_parenthesis(const String &line) const {
  1153. int current_state = 0;
  1154. for (int current_index = 0; line.length() > current_index; current_index++) {
  1155. char32_t character = line.get(current_index);
  1156. if (character == '(') {
  1157. current_state++;
  1158. }
  1159. if (character == ')') {
  1160. current_state--;
  1161. if (current_state == 0) {
  1162. return current_index;
  1163. }
  1164. }
  1165. }
  1166. return -1;
  1167. }
  1168. // Merges multiple arguments into a single String.
  1169. // Needed when after processing e.g. 2 arguments, later arguments are not changed in any way.
  1170. String ProjectConverter3To4::connect_arguments(const Vector<String> &arguments, int from, int to) const {
  1171. if (to == -1) {
  1172. to = arguments.size();
  1173. }
  1174. String value;
  1175. if (arguments.size() > 0 && from != 0 && from < to) {
  1176. value = ", ";
  1177. }
  1178. for (int i = from; i < to; i++) {
  1179. value += arguments[i];
  1180. if (i != to - 1) {
  1181. value += ", ";
  1182. }
  1183. }
  1184. return value;
  1185. }
  1186. // Returns the indentation (spaces and tabs) at the start of the line e.g. `\t\tmove_this` returns `\t\t`.
  1187. String ProjectConverter3To4::get_starting_space(const String &line) const {
  1188. String empty_space;
  1189. int current_character = 0;
  1190. if (line.is_empty()) {
  1191. return empty_space;
  1192. }
  1193. if (line[0] == ' ') {
  1194. while (current_character < line.size()) {
  1195. if (line[current_character] == ' ') {
  1196. empty_space += ' ';
  1197. current_character++;
  1198. } else {
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. if (line[0] == '\t') {
  1204. while (current_character < line.size()) {
  1205. if (line[current_character] == '\t') {
  1206. empty_space += '\t';
  1207. current_character++;
  1208. } else {
  1209. break;
  1210. }
  1211. }
  1212. }
  1213. return empty_space;
  1214. }
  1215. // Returns the object that’s executing the function in the line.
  1216. // e.g. Passing the line "var roman = kieliszek.funkcja()" to this function returns "kieliszek".
  1217. String ProjectConverter3To4::get_object_of_execution(const String &line) const {
  1218. int end = line.size() - 1; // Last one is \0
  1219. int variable_start = end - 1;
  1220. int start = end - 1;
  1221. bool is_possibly_nodepath = false;
  1222. bool is_valid_nodepath = false;
  1223. while (start >= 0) {
  1224. char32_t character = line[start];
  1225. bool is_variable_char = (character >= 'A' && character <= 'Z') || (character >= 'a' && character <= 'z') || character == '.' || character == '_';
  1226. bool is_nodepath_start = character == '$';
  1227. bool is_nodepath_sep = character == '/';
  1228. if (is_variable_char || is_nodepath_start || is_nodepath_sep) {
  1229. if (start == 0) {
  1230. break;
  1231. } else if (is_nodepath_sep) {
  1232. // Freeze variable_start, try to fetch more chars since this might be a Node path literal.
  1233. is_possibly_nodepath = true;
  1234. } else if (is_nodepath_start) {
  1235. // Found $, this is a Node path literal.
  1236. is_valid_nodepath = true;
  1237. break;
  1238. }
  1239. if (!is_possibly_nodepath) {
  1240. variable_start--;
  1241. }
  1242. start--;
  1243. continue;
  1244. } else {
  1245. // Abandon all hope, this is neither a variable nor a Node path literal.
  1246. variable_start++; // Found invalid character, needs to be ignored.
  1247. break;
  1248. }
  1249. }
  1250. if (is_valid_nodepath) {
  1251. variable_start = start;
  1252. }
  1253. return line.substr(variable_start, (end - variable_start));
  1254. }
  1255. void ProjectConverter3To4::rename_colors(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1256. for (SourceLine &source_line : source_lines) {
  1257. if (source_line.is_comment) {
  1258. continue;
  1259. }
  1260. String &line = source_line.line;
  1261. if (uint64_t(line.length()) <= maximum_line_length) {
  1262. if (line.contains("Color.")) {
  1263. for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {
  1264. line = reg_container.color_regexes[current_index]->sub(line, reg_container.color_renamed[current_index], true);
  1265. }
  1266. }
  1267. }
  1268. }
  1269. };
  1270. // Convert hexadecimal colors from ARGB to RGBA
  1271. void ProjectConverter3To4::convert_hexadecimal_colors(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1272. for (SourceLine &source_line : source_lines) {
  1273. if (source_line.is_comment) {
  1274. continue;
  1275. }
  1276. String &line = source_line.line;
  1277. if (uint64_t(line.length()) <= maximum_line_length) {
  1278. if (line.contains("Color(\"")) {
  1279. line = reg_container.color_hexadecimal_short_constructor.sub(line, "Color(\"#$2$1", true);
  1280. line = reg_container.color_hexadecimal_full_constructor.sub(line, "Color(\"#$2$1", true);
  1281. }
  1282. }
  1283. }
  1284. }
  1285. Vector<String> ProjectConverter3To4::check_for_rename_colors(Vector<String> &lines, const RegExContainer &reg_container) {
  1286. Vector<String> found_renames;
  1287. int current_line = 1;
  1288. for (String &line : lines) {
  1289. if (uint64_t(line.length()) <= maximum_line_length) {
  1290. if (line.contains("Color.")) {
  1291. for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {
  1292. TypedArray<RegExMatch> reg_match = reg_container.color_regexes[current_index]->search_all(line);
  1293. if (reg_match.size() > 0) {
  1294. found_renames.append(line_formatter(current_line, RenamesMap3To4::color_renames[current_index][0], RenamesMap3To4::color_renames[current_index][1], line));
  1295. }
  1296. }
  1297. }
  1298. }
  1299. current_line++;
  1300. }
  1301. return found_renames;
  1302. }
  1303. void ProjectConverter3To4::fix_tool_declaration(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1304. // In godot4, "tool" became "@tool" and must be located at the top of the file.
  1305. for (int i = 0; i < source_lines.size(); ++i) {
  1306. if (source_lines[i].line == "tool") {
  1307. source_lines.remove_at(i);
  1308. source_lines.insert(0, { "@tool", false });
  1309. return; // assuming there's at most 1 tool declaration.
  1310. }
  1311. }
  1312. }
  1313. void ProjectConverter3To4::fix_pause_mode(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1314. // In Godot 3, the pause_mode 2 equals the PAUSE_MODE_PROCESS value.
  1315. // In Godot 4, the pause_mode PAUSE_MODE_PROCESS was renamed to PROCESS_MODE_ALWAYS and equals the number 3.
  1316. // We therefore convert pause_mode = 2 to pause_mode = 3.
  1317. for (SourceLine &source_line : source_lines) {
  1318. String &line = source_line.line;
  1319. if (line == "pause_mode = 2") {
  1320. // Note: pause_mode is renamed to process_mode later on, so no need to do it here.
  1321. line = "pause_mode = 3";
  1322. }
  1323. }
  1324. }
  1325. void ProjectConverter3To4::rename_classes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1326. for (SourceLine &source_line : source_lines) {
  1327. if (source_line.is_comment) {
  1328. continue;
  1329. }
  1330. String &line = source_line.line;
  1331. if (uint64_t(line.length()) <= maximum_line_length) {
  1332. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  1333. if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {
  1334. bool found_ignored_items = false;
  1335. // Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.
  1336. if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {
  1337. found_ignored_items = true;
  1338. line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);
  1339. line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);
  1340. line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);
  1341. }
  1342. // Causal renaming Spatial -> Node3D.
  1343. line = reg_container.class_regexes[current_index]->sub(line, RenamesMap3To4::class_renames[current_index][1], true);
  1344. // Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.
  1345. if (found_ignored_items) {
  1346. line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);
  1347. line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);
  1348. line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. };
  1355. Vector<String> ProjectConverter3To4::check_for_rename_classes(Vector<String> &lines, const RegExContainer &reg_container) {
  1356. Vector<String> found_renames;
  1357. int current_line = 1;
  1358. for (String &line : lines) {
  1359. if (uint64_t(line.length()) <= maximum_line_length) {
  1360. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  1361. if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {
  1362. String old_line = line;
  1363. bool found_ignored_items = false;
  1364. // Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.
  1365. if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {
  1366. found_ignored_items = true;
  1367. line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);
  1368. line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);
  1369. line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);
  1370. }
  1371. // Causal renaming Spatial -> Node3D.
  1372. TypedArray<RegExMatch> reg_match = reg_container.class_regexes[current_index]->search_all(line);
  1373. if (reg_match.size() > 0) {
  1374. found_renames.append(line_formatter(current_line, RenamesMap3To4::class_renames[current_index][0], RenamesMap3To4::class_renames[current_index][1], old_line));
  1375. }
  1376. // Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.
  1377. if (found_ignored_items) {
  1378. line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);
  1379. line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);
  1380. line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);
  1381. }
  1382. }
  1383. }
  1384. }
  1385. current_line++;
  1386. }
  1387. return found_renames;
  1388. }
  1389. void ProjectConverter3To4::rename_gdscript_functions(Vector<SourceLine> &source_lines, const RegExContainer &reg_container, bool builtin) {
  1390. for (SourceLine &source_line : source_lines) {
  1391. if (source_line.is_comment) {
  1392. continue;
  1393. }
  1394. String &line = source_line.line;
  1395. if (uint64_t(line.length()) <= maximum_line_length) {
  1396. process_gdscript_line(line, reg_container, builtin);
  1397. }
  1398. }
  1399. };
  1400. Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector<String> &lines, const RegExContainer &reg_container, bool builtin) {
  1401. int current_line = 1;
  1402. Vector<String> found_renames;
  1403. for (String &line : lines) {
  1404. if (uint64_t(line.length()) <= maximum_line_length) {
  1405. String old_line = line;
  1406. process_gdscript_line(line, reg_container, builtin);
  1407. if (old_line != line) {
  1408. found_renames.append(simple_line_formatter(current_line, old_line, line));
  1409. }
  1410. }
  1411. }
  1412. return found_renames;
  1413. }
  1414. bool ProjectConverter3To4::contains_function_call(const String &line, const String &function) const {
  1415. // We want to convert the function only if it is completely standalone.
  1416. // For example, when we search for "connect(", we don't want to accidentally convert "reconnect(".
  1417. if (!line.contains(function)) {
  1418. return false;
  1419. }
  1420. int index = line.find(function);
  1421. if (index == 0) {
  1422. return true;
  1423. }
  1424. char32_t previous_char = line.get(index - 1);
  1425. return (previous_char < '0' || previous_char > '9') && (previous_char < 'a' || previous_char > 'z') && (previous_char < 'A' || previous_char > 'Z') && previous_char != '_' && previous_char != '$' && previous_char != '@';
  1426. }
  1427. // TODO, this function should run only on all ".gd" files and also on lines in ".tscn" files which are parts of built-in Scripts.
  1428. void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContainer &reg_container, bool builtin) {
  1429. // In this and other functions, reg.sub() is used only after checking lines with str.contains().
  1430. // With longer lines, doing so can sometimes be significantly faster.
  1431. if ((line.contains(".lock") || line.contains(".unlock")) && !line.contains("mtx") && !line.contains("mutex") && !line.contains("Mutex")) {
  1432. line = reg_container.reg_image_lock.sub(line, "false # $1.lock() # TODOConverter3To4, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed", true);
  1433. line = reg_container.reg_image_unlock.sub(line, "false # $1.unlock() # TODOConverter3To4, Image no longer requires locking, `false` helps to not break one line if/else, so it can freely be removed", true);
  1434. }
  1435. // PackedStringArray(req_godot).join('.') -> '.'.join(PackedStringArray(req_godot)) PoolStringArray
  1436. if (line.contains(".join")) {
  1437. line = reg_container.reg_join.sub(line, "$2.join($1)", true);
  1438. }
  1439. // -- empty() -> is_empty() Pool*Array
  1440. if (line.contains("empty")) {
  1441. line = reg_container.reg_is_empty.sub(line, "is_empty(", true);
  1442. }
  1443. // -- \t.func() -> \tsuper.func() Object
  1444. if (line.contains("(") && line.contains(".")) {
  1445. line = reg_container.reg_super.sub(line, "$1super.$2", true); // TODO, not sure if possible, but for now this broke String text e.g. "Chosen .gitignore" -> "Chosen super.gitignore"
  1446. }
  1447. // -- JSON.parse(a) -> JSON.new().parse(a) etc. JSON
  1448. if (line.contains("parse")) {
  1449. line = reg_container.reg_json_non_new.sub(line, "$1var test_json_conv = JSON.new()\n$1test_json_conv.parse($3\n$1$2test_json_conv.get_data()", true);
  1450. }
  1451. // -- to_json(a) -> JSON.new().stringify(a) Object
  1452. if (line.contains("to_json")) {
  1453. line = reg_container.reg_json_to.sub(line, "JSON.new().stringify", true);
  1454. }
  1455. // -- parse_json(a) -> JSON.get_data() etc. Object
  1456. if (line.contains("parse_json")) {
  1457. line = reg_container.reg_json_parse.sub(line, "$1var test_json_conv = JSON.new()\n$1test_json_conv.parse($3\n$1$2test_json_conv.get_data()", true);
  1458. }
  1459. // -- JSON.print( -> JSON.stringify(
  1460. if (line.contains("JSON.print(")) {
  1461. line = reg_container.reg_json_print.sub(line, "JSON.stringify(", true);
  1462. }
  1463. // -- get_node(@ -> get_node( Node
  1464. if (line.contains("get_node")) {
  1465. line = line.replace("get_node(@", "get_node(");
  1466. }
  1467. if (line.contains("export")) {
  1468. // 1. export(float) var lifetime: float = 3.0 -> export var lifetime: float = 3.0
  1469. line = reg_container.reg_export_typed.sub(line, "export var $2: $1");
  1470. // 2. export(float) var lifetime := 3.0 -> export var lifetime := 3.0
  1471. line = reg_container.reg_export_inferred_type.sub(line, "export var $1 :=");
  1472. // 3. export(float) var lifetime = 3.0 -> export var lifetime: float = 3.0 GDScript
  1473. line = reg_container.reg_export_simple.sub(line, "export var $2: $1");
  1474. // 4. export(String, 'AnonymousPro', 'CourierPrime') var _font_name = 'AnonymousPro' -> export var _font_name = 'AnonymousPro' #(String, 'AnonymousPro', 'CourierPrime') GDScript
  1475. line = reg_container.reg_export_advanced.sub(line, "export var $2$3 # ($1)");
  1476. }
  1477. // Setget Setget
  1478. if (line.contains("setget")) {
  1479. line = reg_container.reg_setget_setget.sub(line, "var $1$2: get = $4, set = $3", true);
  1480. }
  1481. // Setget set
  1482. if (line.contains("setget")) {
  1483. line = reg_container.reg_setget_set.sub(line, "var $1$2: set = $3", true);
  1484. }
  1485. // Setget get
  1486. if (line.contains("setget")) {
  1487. line = reg_container.reg_setget_get.sub(line, "var $1$2: get = $3", true);
  1488. }
  1489. if (line.contains("window_resizable")) {
  1490. // OS.set_window_resizable(a) -> get_window().unresizable = not (a)
  1491. line = reg_container.reg_os_set_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);
  1492. // OS.window_resizable = a -> same
  1493. line = reg_container.reg_os_assign_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);
  1494. // OS.[is_]window_resizable() -> (not get_window().unresizable)
  1495. line = reg_container.reg_os_is_window_resizable.sub(line, "(not get_window().unresizable)", true);
  1496. }
  1497. if (line.contains("window_fullscreen")) {
  1498. // OS.window_fullscreen(a) -> get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (a) else Window.MODE_WINDOWED
  1499. line = reg_container.reg_os_set_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);
  1500. // window_fullscreen = a -> same
  1501. line = reg_container.reg_os_assign_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);
  1502. // OS.[is_]window_fullscreen() -> ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))
  1503. line = reg_container.reg_os_is_fullscreen.sub(line, "((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))", true);
  1504. }
  1505. if (line.contains("window_maximized")) {
  1506. // OS.window_maximized(a) -> get_window().mode = Window.MODE_MAXIMIZED if (a) else Window.MODE_WINDOWED
  1507. line = reg_container.reg_os_set_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1508. // window_maximized = a -> same
  1509. line = reg_container.reg_os_assign_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1510. // OS.[is_]window_maximized() -> (get_window().mode == Window.MODE_MAXIMIZED)
  1511. line = reg_container.reg_os_is_maximized.sub(line, "(get_window().mode == Window.MODE_MAXIMIZED)", true);
  1512. }
  1513. if (line.contains("window_minimized")) {
  1514. // OS.window_minimized(a) -> get_window().mode = Window.MODE_MINIMIZED if (a) else Window.MODE_WINDOWED
  1515. line = reg_container.reg_os_set_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1516. // window_minimized = a -> same
  1517. line = reg_container.reg_os_assign_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1518. // OS.[is_]window_minimized() -> (get_window().mode == Window.MODE_MINIMIZED)
  1519. line = reg_container.reg_os_is_minimized.sub(line, "(get_window().mode == Window.MODE_MINIMIZED)", true);
  1520. }
  1521. if (line.contains("set_use_vsync")) {
  1522. // OS.set_use_vsync(a) -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)
  1523. line = reg_container.reg_os_set_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);
  1524. }
  1525. if (line.contains("vsync_enabled")) {
  1526. // vsync_enabled = a -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)
  1527. line = reg_container.reg_os_assign_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);
  1528. // OS.[is_]vsync_enabled() -> (DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)
  1529. line = reg_container.reg_os_is_vsync.sub(line, "(DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)", true);
  1530. }
  1531. if (line.contains("OS.screen_orientation")) { // keep "OS." at start
  1532. // OS.screen_orientation = a -> DisplayServer.screen_set_orientation(a)
  1533. line = reg_container.reg_os_assign_screen_orient.sub(line, "$1DisplayServer.screen_set_orientation($2)", true); // assignment
  1534. line = line.replace("OS.screen_orientation", "DisplayServer.screen_get_orientation()"); // value access
  1535. }
  1536. if (line.contains("_window_always_on_top")) {
  1537. // OS.set_window_always_on_top(a) -> get_window().always_on_top = (a)
  1538. line = reg_container.reg_os_set_always_on_top.sub(line, "get_window().always_on_top = ($1)", true);
  1539. // OS.is_window_always_on_top() -> get_window().always_on_top
  1540. line = reg_container.reg_os_is_always_on_top.sub(line, "get_window().always_on_top", true);
  1541. }
  1542. if (line.contains("et_borderless_window")) {
  1543. // OS.set_borderless_window(a) -> get_window().borderless = (a)
  1544. line = reg_container.reg_os_set_borderless.sub(line, "get_window().borderless = ($1)", true);
  1545. // OS.get_borderless_window() -> get_window().borderless
  1546. line = reg_container.reg_os_get_borderless.sub(line, "get_window().borderless", true);
  1547. }
  1548. // OS.SCREEN_ORIENTATION_* -> DisplayServer.SCREEN_*
  1549. if (line.contains("OS.SCREEN_ORIENTATION_")) {
  1550. line = reg_container.reg_os_screen_orient_enum.sub(line, "DisplayServer.SCREEN_$1", true);
  1551. }
  1552. // OS -> Window simple replacements with optional set/get.
  1553. if (line.contains("current_screen")) {
  1554. line = reg_container.reg_os_current_screen.sub(line, "get_window().$1current_screen", true);
  1555. }
  1556. if (line.contains("min_window_size")) {
  1557. line = reg_container.reg_os_min_window_size.sub(line, "get_window().$1min_size", true);
  1558. }
  1559. if (line.contains("max_window_size")) {
  1560. line = reg_container.reg_os_max_window_size.sub(line, "get_window().$1max_size", true);
  1561. }
  1562. if (line.contains("window_position")) {
  1563. line = reg_container.reg_os_window_position.sub(line, "get_window().$1position", true);
  1564. }
  1565. if (line.contains("window_size")) {
  1566. line = reg_container.reg_os_window_size.sub(line, "get_window().$1size", true);
  1567. }
  1568. if (line.contains("et_screen_orientation")) {
  1569. line = reg_container.reg_os_getset_screen_orient.sub(line, "DisplayServer.screen_$1et_orientation", true);
  1570. }
  1571. // Instantiate
  1572. if (contains_function_call(line, "instance")) {
  1573. line = reg_container.reg_instantiate.sub(line, ".instantiate($1)", true);
  1574. }
  1575. // -- r.move_and_slide( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody
  1576. if (contains_function_call(line, "move_and_slide(")) {
  1577. int start = line.find("move_and_slide(");
  1578. int end = get_end_parenthesis(line.substr(start)) + 1;
  1579. if (end > -1) {
  1580. String base_obj = get_object_of_execution(line.substr(0, start));
  1581. String starting_space = get_starting_space(line);
  1582. Vector<String> parts = parse_arguments(line.substr(start, end));
  1583. if (parts.size() >= 1) {
  1584. String line_new;
  1585. // motion_velocity
  1586. line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";
  1587. // up_direction
  1588. if (parts.size() >= 2) {
  1589. line_new += starting_space + base_obj + "set_up_direction(" + parts[1] + ")\n";
  1590. }
  1591. // stop_on_slope
  1592. if (parts.size() >= 3) {
  1593. line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[2] + ")\n";
  1594. }
  1595. // max_slides
  1596. if (parts.size() >= 4) {
  1597. line_new += starting_space + base_obj + "set_max_slides(" + parts[3] + ")\n";
  1598. }
  1599. // floor_max_angle
  1600. if (parts.size() >= 5) {
  1601. line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[4] + ")\n";
  1602. }
  1603. // infiinite_interia
  1604. if (parts.size() >= 6) {
  1605. line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[5] + "`\n";
  1606. }
  1607. line_new += starting_space + base_obj + "move_and_slide()";
  1608. if (!line.begins_with(starting_space + "move_and_slide")) {
  1609. line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);
  1610. } else {
  1611. line = line_new + line.substr(end + start);
  1612. }
  1613. }
  1614. }
  1615. }
  1616. // -- r.move_and_slide_with_snap( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody
  1617. if (contains_function_call(line, "move_and_slide_with_snap(")) {
  1618. int start = line.find("move_and_slide_with_snap(");
  1619. int end = get_end_parenthesis(line.substr(start)) + 1;
  1620. if (end > -1) {
  1621. String base_obj = get_object_of_execution(line.substr(0, start));
  1622. String starting_space = get_starting_space(line);
  1623. Vector<String> parts = parse_arguments(line.substr(start, end));
  1624. if (parts.size() >= 1) {
  1625. String line_new;
  1626. // motion_velocity
  1627. line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";
  1628. // snap
  1629. if (parts.size() >= 2) {
  1630. line_new += starting_space + "# TODOConverter3To4 looks that snap in Godot 4 is float, not vector like in Godot 3 - previous value `" + parts[1] + "`\n";
  1631. }
  1632. // up_direction
  1633. if (parts.size() >= 3) {
  1634. line_new += starting_space + base_obj + "set_up_direction(" + parts[2] + ")\n";
  1635. }
  1636. // stop_on_slope
  1637. if (parts.size() >= 4) {
  1638. line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[3] + ")\n";
  1639. }
  1640. // max_slides
  1641. if (parts.size() >= 5) {
  1642. line_new += starting_space + base_obj + "set_max_slides(" + parts[4] + ")\n";
  1643. }
  1644. // floor_max_angle
  1645. if (parts.size() >= 6) {
  1646. line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[5] + ")\n";
  1647. }
  1648. // infiinite_interia
  1649. if (parts.size() >= 7) {
  1650. line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[6] + "`\n";
  1651. }
  1652. line_new += starting_space + base_obj + "move_and_slide()";
  1653. if (!line.begins_with(starting_space + "move_and_slide_with_snap")) {
  1654. line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);
  1655. } else {
  1656. line = line_new + line.substr(end + start);
  1657. }
  1658. }
  1659. }
  1660. }
  1661. // -- sort_custom( a , b ) -> sort_custom(Callable( a , b )) Object
  1662. if (contains_function_call(line, "sort_custom(")) {
  1663. int start = line.find("sort_custom(");
  1664. int end = get_end_parenthesis(line.substr(start)) + 1;
  1665. if (end > -1) {
  1666. Vector<String> parts = parse_arguments(line.substr(start, end));
  1667. if (parts.size() == 2) {
  1668. line = line.substr(0, start) + "sort_custom(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1669. }
  1670. }
  1671. }
  1672. // -- list_dir_begin( ) -> list_dir_begin() Object
  1673. if (contains_function_call(line, "list_dir_begin(")) {
  1674. int start = line.find("list_dir_begin(");
  1675. int end = get_end_parenthesis(line.substr(start)) + 1;
  1676. if (end > -1) {
  1677. line = line.substr(0, start) + "list_dir_begin() " + line.substr(end + start) + "# TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547";
  1678. }
  1679. }
  1680. // -- draw_line(1,2,3,4,5) -> draw_line(1, 2, 3, 4) CanvasItem
  1681. if (contains_function_call(line, "draw_line(")) {
  1682. int start = line.find("draw_line(");
  1683. int end = get_end_parenthesis(line.substr(start)) + 1;
  1684. if (end > -1) {
  1685. Vector<String> parts = parse_arguments(line.substr(start, end));
  1686. if (parts.size() == 5) {
  1687. line = line.substr(0, start) + "draw_line(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ", " + parts[3] + ")" + line.substr(end + start);
  1688. }
  1689. }
  1690. }
  1691. // -- func c(var a, var b) -> func c(a, b)
  1692. if (line.contains("func ") && line.contains("var ")) {
  1693. int start = line.find("func ");
  1694. start = line.substr(start).find("(") + start;
  1695. int end = get_end_parenthesis(line.substr(start)) + 1;
  1696. if (end > -1) {
  1697. Vector<String> parts = parse_arguments(line.substr(start, end));
  1698. String start_string = line.substr(0, start) + "(";
  1699. for (int i = 0; i < parts.size(); i++) {
  1700. start_string += parts[i].strip_edges().trim_prefix("var ");
  1701. if (i != parts.size() - 1) {
  1702. start_string += ", ";
  1703. }
  1704. }
  1705. line = start_string + ")" + line.substr(end + start);
  1706. }
  1707. }
  1708. // -- yield(this, \"timeout\") -> await this.timeout GDScript
  1709. if (contains_function_call(line, "yield(")) {
  1710. int start = line.find("yield(");
  1711. int end = get_end_parenthesis(line.substr(start)) + 1;
  1712. if (end > -1) {
  1713. Vector<String> parts = parse_arguments(line.substr(start, end));
  1714. if (parts.size() == 2) {
  1715. if (builtin) {
  1716. line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\\\"", "").replace("\\'", "").replace(" ", "") + line.substr(end + start);
  1717. } else {
  1718. line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start);
  1719. }
  1720. }
  1721. }
  1722. }
  1723. // -- parse_json( AA ) -> TODO Object
  1724. if (contains_function_call(line, "parse_json(")) {
  1725. int start = line.find("parse_json(");
  1726. int end = get_end_parenthesis(line.substr(start)) + 1;
  1727. if (end > -1) {
  1728. Vector<String> parts = parse_arguments(line.substr(start, end));
  1729. line = line.substr(0, start) + "JSON.new().stringify(" + connect_arguments(parts, 0) + ")" + line.substr(end + start);
  1730. }
  1731. }
  1732. // -- .xform(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform
  1733. if (line.contains(".xform(")) {
  1734. int start = line.find(".xform(");
  1735. int end = get_end_parenthesis(line.substr(start)) + 1;
  1736. if (end > -1) {
  1737. Vector<String> parts = parse_arguments(line.substr(start, end));
  1738. if (parts.size() == 1) {
  1739. line = line.substr(0, start) + " * (" + parts[0] + ")" + line.substr(end + start);
  1740. }
  1741. }
  1742. }
  1743. // -- .xform_inv(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform
  1744. if (line.contains(".xform_inv(")) {
  1745. int start = line.find(".xform_inv(");
  1746. int end = get_end_parenthesis(line.substr(start)) + 1;
  1747. if (end > -1) {
  1748. String object_exec = get_object_of_execution(line.substr(0, start));
  1749. if (line.contains(object_exec + ".xform")) {
  1750. int start2 = line.find(object_exec + ".xform");
  1751. Vector<String> parts = parse_arguments(line.substr(start, end));
  1752. if (parts.size() == 1) {
  1753. line = line.substr(0, start2) + "(" + parts[0] + ") * " + object_exec + line.substr(end + start);
  1754. }
  1755. }
  1756. }
  1757. }
  1758. // -- "(connect(A,B,C,D,E) != OK):", "(connect(A, Callable(B, C).bind(D), E) Object
  1759. if (contains_function_call(line, "connect(")) {
  1760. int start = line.find("connect(");
  1761. int end = get_end_parenthesis(line.substr(start)) + 1;
  1762. if (end > -1) {
  1763. Vector<String> parts = parse_arguments(line.substr(start, end));
  1764. if (parts.size() == 3) {
  1765. line = line.substr(0, start) + "connect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1766. } else if (parts.size() >= 4) {
  1767. line = line.substr(0, start) + "connect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + ").bind(" + parts[3].lstrip(" [").rstrip("] ") + ")" + connect_arguments(parts, 4) + ")" + line.substr(end + start);
  1768. }
  1769. }
  1770. }
  1771. // -- disconnect(a,b,c) -> disconnect(a,Callable(b,c)) Object
  1772. if (contains_function_call(line, "disconnect(")) {
  1773. int start = line.find("disconnect(");
  1774. int end = get_end_parenthesis(line.substr(start)) + 1;
  1775. if (end > -1) {
  1776. Vector<String> parts = parse_arguments(line.substr(start, end));
  1777. if (parts.size() == 3) {
  1778. line = line.substr(0, start) + "disconnect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1779. }
  1780. }
  1781. }
  1782. // -- is_connected(a,b,c) -> is_connected(a,Callable(b,c)) Object
  1783. if (contains_function_call(line, "is_connected(")) {
  1784. int start = line.find("is_connected(");
  1785. int end = get_end_parenthesis(line.substr(start)) + 1;
  1786. if (end > -1) {
  1787. Vector<String> parts = parse_arguments(line.substr(start, end));
  1788. if (parts.size() == 3) {
  1789. line = line.substr(0, start) + "is_connected(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1790. }
  1791. }
  1792. }
  1793. // -- "(tween_method(A,B,C,D,E) != OK):", "(tween_method(Callable(A,B),C,D,E) Object
  1794. // -- "(tween_method(A,B,C,D,E,[F,G]) != OK):", "(tween_method(Callable(A,B).bind(F,G),C,D,E) Object
  1795. if (contains_function_call(line, "tween_method(")) {
  1796. int start = line.find("tween_method(");
  1797. int end = get_end_parenthesis(line.substr(start)) + 1;
  1798. if (end > -1) {
  1799. Vector<String> parts = parse_arguments(line.substr(start, end));
  1800. if (parts.size() == 5) {
  1801. line = line.substr(0, start) + "tween_method(Callable(" + parts[0] + ", " + parts[1] + "), " + parts[2] + ", " + parts[3] + ", " + parts[4] + ")" + line.substr(end + start);
  1802. } else if (parts.size() >= 6) {
  1803. line = line.substr(0, start) + "tween_method(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + connect_arguments(parts, 5).substr(1).lstrip(" [").rstrip("] ") + "), " + parts[2] + ", " + parts[3] + ", " + parts[4] + ")" + line.substr(end + start);
  1804. }
  1805. }
  1806. }
  1807. // -- "(tween_callback(A,B,[C,D]) != OK):", "(connect(Callable(A,B).bind(C,D)) Object
  1808. if (contains_function_call(line, "tween_callback(")) {
  1809. int start = line.find("tween_callback(");
  1810. int end = get_end_parenthesis(line.substr(start)) + 1;
  1811. if (end > -1) {
  1812. Vector<String> parts = parse_arguments(line.substr(start, end));
  1813. if (parts.size() == 2) {
  1814. line = line.substr(0, start) + "tween_callback(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1815. } else if (parts.size() >= 3) {
  1816. line = line.substr(0, start) + "tween_callback(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + connect_arguments(parts, 2).substr(1).lstrip(" [").rstrip("] ") + "))" + line.substr(end + start);
  1817. }
  1818. }
  1819. }
  1820. // -- start(a,b) -> start(Callable(a, b)) Thread
  1821. // -- start(a,b,c,d) -> start(Callable(a, b).bind(c), d) Thread
  1822. if (contains_function_call(line, "start(")) {
  1823. int start = line.find("start(");
  1824. int end = get_end_parenthesis(line.substr(start)) + 1;
  1825. // Protection from 'func start'
  1826. if (!line.begins_with("func ")) {
  1827. if (end > -1) {
  1828. Vector<String> parts = parse_arguments(line.substr(start, end));
  1829. if (parts.size() == 2) {
  1830. line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1831. } else if (parts.size() >= 3) {
  1832. line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);
  1833. }
  1834. }
  1835. }
  1836. }
  1837. // -- func _init(p_x:int).(p_x): -> func _init(p_x:int):\n\tsuper(p_x) Object # https://github.com/godotengine/godot/issues/70542
  1838. if (line.contains(" _init(") && line.rfind(":") > 0) {
  1839. // func _init(p_arg1).(super4, super5, super6)->void:
  1840. // ^--^indent ^super_start super_end^
  1841. int indent = line.count("\t", 0, line.find("func"));
  1842. int super_start = line.find(".(");
  1843. int super_end = line.rfind(")");
  1844. if (super_start > 0 && super_end > super_start) {
  1845. line = line.substr(0, super_start) + line.substr(super_end + 1) + "\n" + String("\t").repeat(indent + 1) + "super" + line.substr(super_start + 1, super_end - super_start);
  1846. }
  1847. }
  1848. // create_from_image(aa, bb) -> create_from_image(aa) #, bb ImageTexture
  1849. if (contains_function_call(line, "create_from_image(")) {
  1850. int start = line.find("create_from_image(");
  1851. int end = get_end_parenthesis(line.substr(start)) + 1;
  1852. if (end > -1) {
  1853. Vector<String> parts = parse_arguments(line.substr(start, end));
  1854. if (parts.size() == 2) {
  1855. line = line.substr(0, start) + "create_from_image(" + parts[0] + ") " + "#," + parts[1] + line.substr(end + start);
  1856. }
  1857. }
  1858. }
  1859. // set_cell_item(a, b, c, d ,e) -> set_cell_item(Vector3(a, b, c), d ,e)
  1860. if (contains_function_call(line, "set_cell_item(")) {
  1861. int start = line.find("set_cell_item(");
  1862. int end = get_end_parenthesis(line.substr(start)) + 1;
  1863. if (end > -1) {
  1864. Vector<String> parts = parse_arguments(line.substr(start, end));
  1865. if (parts.size() > 2) {
  1866. line = line.substr(0, start) + "set_cell_item(Vector3(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3).lstrip(" ") + ")" + line.substr(end + start);
  1867. }
  1868. }
  1869. }
  1870. // get_cell_item(a, b, c) -> get_cell_item(Vector3i(a, b, c))
  1871. if (contains_function_call(line, "get_cell_item(")) {
  1872. int start = line.find("get_cell_item(");
  1873. int end = get_end_parenthesis(line.substr(start)) + 1;
  1874. if (end > -1) {
  1875. Vector<String> parts = parse_arguments(line.substr(start, end));
  1876. if (parts.size() == 3) {
  1877. line = line.substr(0, start) + "get_cell_item(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1878. }
  1879. }
  1880. }
  1881. // get_cell_item_orientation(a, b, c) -> get_cell_item_orientation(Vector3i(a, b, c))
  1882. if (contains_function_call(line, "get_cell_item_orientation(")) {
  1883. int start = line.find("get_cell_item_orientation(");
  1884. int end = get_end_parenthesis(line.substr(start)) + 1;
  1885. if (end > -1) {
  1886. Vector<String> parts = parse_arguments(line.substr(start, end));
  1887. if (parts.size() == 3) {
  1888. line = line.substr(0, start) + "get_cell_item_orientation(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1889. }
  1890. }
  1891. }
  1892. // apply_impulse(A, B) -> apply_impulse(B, A)
  1893. if (contains_function_call(line, "apply_impulse(")) {
  1894. int start = line.find("apply_impulse(");
  1895. int end = get_end_parenthesis(line.substr(start)) + 1;
  1896. if (end > -1) {
  1897. Vector<String> parts = parse_arguments(line.substr(start, end));
  1898. if (parts.size() == 2) {
  1899. line = line.substr(0, start) + "apply_impulse(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);
  1900. }
  1901. }
  1902. }
  1903. // apply_force(A, B) -> apply_force(B, A)
  1904. if (contains_function_call(line, "apply_force(")) {
  1905. int start = line.find("apply_force(");
  1906. int end = get_end_parenthesis(line.substr(start)) + 1;
  1907. if (end > -1) {
  1908. Vector<String> parts = parse_arguments(line.substr(start, end));
  1909. if (parts.size() == 2) {
  1910. line = line.substr(0, start) + "apply_force(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);
  1911. }
  1912. }
  1913. }
  1914. // map_to_world(a, b, c) -> map_to_local(Vector3i(a, b, c))
  1915. if (contains_function_call(line, "map_to_world(")) {
  1916. int start = line.find("map_to_world(");
  1917. int end = get_end_parenthesis(line.substr(start)) + 1;
  1918. if (end > -1) {
  1919. Vector<String> parts = parse_arguments(line.substr(start, end));
  1920. if (parts.size() == 3) {
  1921. line = line.substr(0, start) + "map_to_local(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1922. } else if (parts.size() == 1) {
  1923. line = line.substr(0, start) + "map_to_local(" + parts[0] + ")" + line.substr(end + start);
  1924. }
  1925. }
  1926. }
  1927. // set_rotating(true) -> set_ignore_rotation(false)
  1928. if (contains_function_call(line, "set_rotating(")) {
  1929. int start = line.find("set_rotating(");
  1930. int end = get_end_parenthesis(line.substr(start)) + 1;
  1931. if (end > -1) {
  1932. Vector<String> parts = parse_arguments(line.substr(start, end));
  1933. if (parts.size() == 1) {
  1934. String opposite = parts[0] == "true" ? "false" : "true";
  1935. line = line.substr(0, start) + "set_ignore_rotation(" + opposite + ")";
  1936. }
  1937. }
  1938. }
  1939. // OS.get_window_safe_area() -> DisplayServer.get_display_safe_area()
  1940. if (line.contains("OS.get_window_safe_area(")) {
  1941. int start = line.find("OS.get_window_safe_area(");
  1942. int end = get_end_parenthesis(line.substr(start)) + 1;
  1943. if (end > -1) {
  1944. Vector<String> parts = parse_arguments(line.substr(start, end));
  1945. if (parts.size() == 0) {
  1946. line = line.substr(0, start) + "DisplayServer.get_display_safe_area()" + line.substr(end + start);
  1947. }
  1948. }
  1949. }
  1950. // draw_rect(a,b,c,d,e) -> draw_rect(a,b,c,d)#e) TODOConverter3To4 Antialiasing argument is missing
  1951. if (contains_function_call(line, "draw_rect(")) {
  1952. int start = line.find("draw_rect(");
  1953. int end = get_end_parenthesis(line.substr(start)) + 1;
  1954. if (end > -1) {
  1955. Vector<String> parts = parse_arguments(line.substr(start, end));
  1956. if (parts.size() == 5) {
  1957. line = line.substr(0, start) + "draw_rect(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ", " + parts[3] + ")" + line.substr(end + start) + "# " + parts[4] + ") TODOConverter3To4 Antialiasing argument is missing";
  1958. }
  1959. }
  1960. }
  1961. // get_focus_owner() -> get_viewport().gui_get_focus_owner()
  1962. if (contains_function_call(line, "get_focus_owner()")) {
  1963. line = line.replace("get_focus_owner()", "get_viewport().gui_get_focus_owner()");
  1964. }
  1965. // button.pressed = 1 -> button.button_pressed = 1
  1966. if (line.contains(".pressed")) {
  1967. int start = line.find(".pressed");
  1968. bool foundNextEqual = false;
  1969. String line_to_check = line.substr(start + String(".pressed").length());
  1970. for (int current_index = 0; line_to_check.length() > current_index; current_index++) {
  1971. char32_t chr = line_to_check.get(current_index);
  1972. if (chr == '\t' || chr == ' ') {
  1973. continue;
  1974. } else if (chr == '=') {
  1975. foundNextEqual = true;
  1976. } else {
  1977. break;
  1978. }
  1979. }
  1980. if (foundNextEqual) {
  1981. line = line.substr(0, start) + ".button_pressed" + line.substr(start + String(".pressed").length());
  1982. }
  1983. }
  1984. // rotating = true -> ignore_rotation = false # reversed "rotating" for Camera2D
  1985. if (contains_function_call(line, "rotating")) {
  1986. String function_name = "rotating";
  1987. int start = line.find(function_name);
  1988. bool foundNextEqual = false;
  1989. String line_to_check = line.substr(start + function_name.length());
  1990. String assigned_value;
  1991. for (int current_index = 0; line_to_check.length() > current_index; current_index++) {
  1992. char32_t chr = line_to_check.get(current_index);
  1993. if (chr == '\t' || chr == ' ') {
  1994. continue;
  1995. } else if (chr == '=') {
  1996. foundNextEqual = true;
  1997. assigned_value = line.substr(start + function_name.length() + current_index + 1).strip_edges();
  1998. assigned_value = assigned_value == "true" ? "false" : "true";
  1999. } else {
  2000. break;
  2001. }
  2002. }
  2003. if (foundNextEqual) {
  2004. line = line.substr(0, start) + "ignore_rotation = " + assigned_value + " # reversed \"rotating\" for Camera2D";
  2005. }
  2006. }
  2007. // OS -> Time functions
  2008. if (line.contains("OS.get_ticks_msec")) {
  2009. line = line.replace("OS.get_ticks_msec", "Time.get_ticks_msec");
  2010. }
  2011. if (line.contains("OS.get_ticks_usec")) {
  2012. line = line.replace("OS.get_ticks_usec", "Time.get_ticks_usec");
  2013. }
  2014. if (line.contains("OS.get_unix_time")) {
  2015. line = line.replace("OS.get_unix_time", "Time.get_unix_time_from_system");
  2016. }
  2017. if (line.contains("OS.get_datetime")) {
  2018. line = line.replace("OS.get_datetime", "Time.get_datetime_dict_from_system");
  2019. }
  2020. // OS -> DisplayServer
  2021. if (line.contains("OS.get_display_cutouts")) {
  2022. line = line.replace("OS.get_display_cutouts", "DisplayServer.get_display_cutouts");
  2023. }
  2024. if (line.contains("OS.get_screen_count")) {
  2025. line = line.replace("OS.get_screen_count", "DisplayServer.get_screen_count");
  2026. }
  2027. if (line.contains("OS.get_screen_dpi")) {
  2028. line = line.replace("OS.get_screen_dpi", "DisplayServer.screen_get_dpi");
  2029. }
  2030. if (line.contains("OS.get_screen_max_scale")) {
  2031. line = line.replace("OS.get_screen_max_scale", "DisplayServer.screen_get_max_scale");
  2032. }
  2033. if (line.contains("OS.get_screen_position")) {
  2034. line = line.replace("OS.get_screen_position", "DisplayServer.screen_get_position");
  2035. }
  2036. if (line.contains("OS.get_screen_refresh_rate")) {
  2037. line = line.replace("OS.get_screen_refresh_rate", "DisplayServer.screen_get_refresh_rate");
  2038. }
  2039. if (line.contains("OS.get_screen_scale")) {
  2040. line = line.replace("OS.get_screen_scale", "DisplayServer.screen_get_scale");
  2041. }
  2042. if (line.contains("OS.get_screen_size")) {
  2043. line = line.replace("OS.get_screen_size", "DisplayServer.screen_get_size");
  2044. }
  2045. if (line.contains("OS.set_icon")) {
  2046. line = line.replace("OS.set_icon", "DisplayServer.set_icon");
  2047. }
  2048. if (line.contains("OS.set_native_icon")) {
  2049. line = line.replace("OS.set_native_icon", "DisplayServer.set_native_icon");
  2050. }
  2051. // OS -> Window
  2052. if (line.contains("OS.window_borderless")) {
  2053. line = line.replace("OS.window_borderless", "get_window().borderless");
  2054. }
  2055. if (line.contains("OS.get_real_window_size")) {
  2056. line = line.replace("OS.get_real_window_size", "get_window().get_size_with_decorations");
  2057. }
  2058. if (line.contains("OS.is_window_focused")) {
  2059. line = line.replace("OS.is_window_focused", "get_window().has_focus");
  2060. }
  2061. if (line.contains("OS.move_window_to_foreground")) {
  2062. line = line.replace("OS.move_window_to_foreground", "get_window().grab_focus");
  2063. }
  2064. if (line.contains("OS.request_attention")) {
  2065. line = line.replace("OS.request_attention", "get_window().request_attention");
  2066. }
  2067. if (line.contains("OS.set_window_title")) {
  2068. line = line.replace("OS.set_window_title", "get_window().set_title");
  2069. }
  2070. // get_tree().set_input_as_handled() -> get_viewport().set_input_as_handled()
  2071. if (line.contains("get_tree().set_input_as_handled()")) {
  2072. line = line.replace("get_tree().set_input_as_handled()", "get_viewport().set_input_as_handled()");
  2073. }
  2074. // Fix the simple case of using _unhandled_key_input
  2075. // func _unhandled_key_input(event: InputEventKey) -> _unhandled_key_input(event: InputEvent)
  2076. if (line.contains("_unhandled_key_input(event: InputEventKey)")) {
  2077. line = line.replace("_unhandled_key_input(event: InputEventKey)", "_unhandled_key_input(event: InputEvent)");
  2078. }
  2079. if (line.contains("Engine.editor_hint")) {
  2080. line = line.replace("Engine.editor_hint", "Engine.is_editor_hint()");
  2081. }
  2082. }
  2083. void ProjectConverter3To4::process_csharp_line(String &line, const RegExContainer &reg_container) {
  2084. line = line.replace("OS.GetWindowSafeArea()", "DisplayServer.ScreenGetUsableRect()");
  2085. // GetTree().SetInputAsHandled() -> GetViewport().SetInputAsHandled()
  2086. if (line.contains("GetTree().SetInputAsHandled()")) {
  2087. line = line.replace("GetTree().SetInputAsHandled()", "GetViewport().SetInputAsHandled()");
  2088. }
  2089. // Fix the simple case of using _UnhandledKeyInput
  2090. // func _UnhandledKeyInput(InputEventKey @event) -> _UnhandledKeyInput(InputEvent @event)
  2091. if (line.contains("_UnhandledKeyInput(InputEventKey @event)")) {
  2092. line = line.replace("_UnhandledKeyInput(InputEventKey @event)", "_UnhandledKeyInput(InputEvent @event)");
  2093. }
  2094. // -- Connect(,,,things) -> Connect(,Callable(,),things) Object
  2095. if (line.contains("Connect(")) {
  2096. int start = line.find("Connect(");
  2097. // Protection from disconnect
  2098. if (start == 0 || line.get(start - 1) != 's') {
  2099. int end = get_end_parenthesis(line.substr(start)) + 1;
  2100. if (end > -1) {
  2101. Vector<String> parts = parse_arguments(line.substr(start, end));
  2102. if (parts.size() >= 3) {
  2103. line = line.substr(0, start) + "Connect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);
  2104. }
  2105. }
  2106. }
  2107. }
  2108. // -- Disconnect(a,b,c) -> Disconnect(a,Callable(b,c)) Object
  2109. if (line.contains("Disconnect(")) {
  2110. int start = line.find("Disconnect(");
  2111. int end = get_end_parenthesis(line.substr(start)) + 1;
  2112. if (end > -1) {
  2113. Vector<String> parts = parse_arguments(line.substr(start, end));
  2114. if (parts.size() == 3) {
  2115. line = line.substr(0, start) + "Disconnect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  2116. }
  2117. }
  2118. }
  2119. // -- IsConnected(a,b,c) -> IsConnected(a,Callable(b,c)) Object
  2120. if (line.contains("IsConnected(")) {
  2121. int start = line.find("IsConnected(");
  2122. int end = get_end_parenthesis(line.substr(start)) + 1;
  2123. if (end > -1) {
  2124. Vector<String> parts = parse_arguments(line.substr(start, end));
  2125. if (parts.size() == 3) {
  2126. line = line.substr(0, start) + "IsConnected(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  2127. }
  2128. }
  2129. }
  2130. }
  2131. void ProjectConverter3To4::rename_csharp_functions(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2132. for (SourceLine &source_line : source_lines) {
  2133. if (source_line.is_comment) {
  2134. continue;
  2135. }
  2136. String &line = source_line.line;
  2137. if (uint64_t(line.length()) <= maximum_line_length) {
  2138. process_csharp_line(line, reg_container);
  2139. }
  2140. }
  2141. };
  2142. Vector<String> ProjectConverter3To4::check_for_rename_csharp_functions(Vector<String> &lines, const RegExContainer &reg_container) {
  2143. int current_line = 1;
  2144. Vector<String> found_renames;
  2145. for (String &line : lines) {
  2146. if (uint64_t(line.length()) <= maximum_line_length) {
  2147. String old_line = line;
  2148. process_csharp_line(line, reg_container);
  2149. if (old_line != line) {
  2150. found_renames.append(simple_line_formatter(current_line, old_line, line));
  2151. }
  2152. }
  2153. }
  2154. return found_renames;
  2155. }
  2156. void ProjectConverter3To4::rename_csharp_attributes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2157. static String error_message = "The master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using Multiplayer.GetRemoteSenderId()\n";
  2158. for (SourceLine &source_line : source_lines) {
  2159. if (source_line.is_comment) {
  2160. continue;
  2161. }
  2162. String &line = source_line.line;
  2163. if (uint64_t(line.length()) <= maximum_line_length) {
  2164. line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);
  2165. line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);
  2166. line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);
  2167. line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);
  2168. line = reg_container.keyword_csharp_master.sub(line, error_message + "[RPC]", true);
  2169. line = reg_container.keyword_csharp_mastersync.sub(line, error_message + "[RPC(CallLocal = true)]", true);
  2170. }
  2171. }
  2172. }
  2173. Vector<String> ProjectConverter3To4::check_for_rename_csharp_attributes(Vector<String> &lines, const RegExContainer &reg_container) {
  2174. int current_line = 1;
  2175. Vector<String> found_renames;
  2176. for (String &line : lines) {
  2177. if (uint64_t(line.length()) <= maximum_line_length) {
  2178. String old;
  2179. old = line;
  2180. line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);
  2181. if (old != line) {
  2182. found_renames.append(line_formatter(current_line, "[Remote]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", line));
  2183. }
  2184. old = line;
  2185. line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);
  2186. if (old != line) {
  2187. found_renames.append(line_formatter(current_line, "[RemoteSync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", line));
  2188. }
  2189. old = line;
  2190. line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);
  2191. if (old != line) {
  2192. found_renames.append(line_formatter(current_line, "[Puppet]", "[RPC]", line));
  2193. }
  2194. old = line;
  2195. line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);
  2196. if (old != line) {
  2197. found_renames.append(line_formatter(current_line, "[PuppetSync]", "[RPC(CallLocal = true)]", line));
  2198. }
  2199. old = line;
  2200. line = reg_container.keyword_csharp_master.sub(line, "[RPC]", true);
  2201. if (old != line) {
  2202. found_renames.append(line_formatter(current_line, "[Master]", "[RPC]", line));
  2203. }
  2204. old = line;
  2205. line = reg_container.keyword_csharp_mastersync.sub(line, "[RPC(CallLocal = true)]", true);
  2206. if (old != line) {
  2207. found_renames.append(line_formatter(current_line, "[MasterSync]", "[RPC(CallLocal = true)]", line));
  2208. }
  2209. }
  2210. current_line++;
  2211. }
  2212. return found_renames;
  2213. }
  2214. _FORCE_INLINE_ static String builtin_escape(const String &p_str, bool p_builtin) {
  2215. if (p_builtin) {
  2216. return p_str.replace("\"", "\\\"");
  2217. } else {
  2218. return p_str;
  2219. }
  2220. }
  2221. void ProjectConverter3To4::rename_gdscript_keywords(Vector<SourceLine> &source_lines, const RegExContainer &reg_container, bool builtin) {
  2222. static String error_message = "The master and mastersync rpc behavior is not officially supported anymore. Try using another keyword or making custom logic using get_multiplayer().get_remote_sender_id()\n";
  2223. for (SourceLine &source_line : source_lines) {
  2224. if (source_line.is_comment) {
  2225. continue;
  2226. }
  2227. String &line = source_line.line;
  2228. if (uint64_t(line.length()) <= maximum_line_length) {
  2229. if (line.contains("export")) {
  2230. line = reg_container.keyword_gdscript_export_single.sub(line, "@export", true);
  2231. }
  2232. if (line.contains("export")) {
  2233. line = reg_container.keyword_gdscript_export_multi.sub(line, "$1@export", true);
  2234. }
  2235. if (line.contains("onready")) {
  2236. line = reg_container.keyword_gdscript_onready.sub(line, "@onready", true);
  2237. }
  2238. if (line.contains("remote")) {
  2239. line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);
  2240. }
  2241. if (line.contains("remote")) {
  2242. line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);
  2243. }
  2244. if (line.contains("sync")) {
  2245. line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);
  2246. }
  2247. if (line.contains("slave")) {
  2248. line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);
  2249. }
  2250. if (line.contains("puppet")) {
  2251. line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);
  2252. }
  2253. if (line.contains("puppet")) {
  2254. line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2255. }
  2256. if (line.contains("master")) {
  2257. line = reg_container.keyword_gdscript_master.sub(line, error_message + "@rpc func", true);
  2258. }
  2259. if (line.contains("master")) {
  2260. line = reg_container.keyword_gdscript_mastersync.sub(line, error_message + builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2261. }
  2262. }
  2263. }
  2264. }
  2265. Vector<String> ProjectConverter3To4::check_for_rename_gdscript_keywords(Vector<String> &lines, const RegExContainer &reg_container, bool builtin) {
  2266. Vector<String> found_renames;
  2267. int current_line = 1;
  2268. for (String &line : lines) {
  2269. if (uint64_t(line.length()) <= maximum_line_length) {
  2270. String old;
  2271. if (line.contains("tool")) {
  2272. old = line;
  2273. line = reg_container.keyword_gdscript_tool.sub(line, "@tool", true);
  2274. if (old != line) {
  2275. found_renames.append(line_formatter(current_line, "tool", "@tool", line));
  2276. }
  2277. }
  2278. if (line.contains("export")) {
  2279. old = line;
  2280. line = reg_container.keyword_gdscript_export_single.sub(line, "$1@export", true);
  2281. if (old != line) {
  2282. found_renames.append(line_formatter(current_line, "export", "@export", line));
  2283. }
  2284. }
  2285. if (line.contains("export")) {
  2286. old = line;
  2287. line = reg_container.keyword_gdscript_export_multi.sub(line, "@export", true);
  2288. if (old != line) {
  2289. found_renames.append(line_formatter(current_line, "export", "@export", line));
  2290. }
  2291. }
  2292. if (line.contains("onready")) {
  2293. old = line;
  2294. line = reg_container.keyword_gdscript_tool.sub(line, "@onready", true);
  2295. if (old != line) {
  2296. found_renames.append(line_formatter(current_line, "onready", "@onready", line));
  2297. }
  2298. }
  2299. if (line.contains("remote")) {
  2300. old = line;
  2301. line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);
  2302. if (old != line) {
  2303. found_renames.append(line_formatter(current_line, "remote func", builtin_escape("@rpc(\"any_peer\") func", builtin), line));
  2304. }
  2305. }
  2306. if (line.contains("remote")) {
  2307. old = line;
  2308. line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);
  2309. if (old != line) {
  2310. found_renames.append(line_formatter(current_line, "remotesync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));
  2311. }
  2312. }
  2313. if (line.contains("sync")) {
  2314. old = line;
  2315. line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);
  2316. if (old != line) {
  2317. found_renames.append(line_formatter(current_line, "sync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));
  2318. }
  2319. }
  2320. if (line.contains("slave")) {
  2321. old = line;
  2322. line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);
  2323. if (old != line) {
  2324. found_renames.append(line_formatter(current_line, "slave func", "@rpc func", line));
  2325. }
  2326. }
  2327. if (line.contains("puppet")) {
  2328. old = line;
  2329. line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);
  2330. if (old != line) {
  2331. found_renames.append(line_formatter(current_line, "puppet func", "@rpc func", line));
  2332. }
  2333. }
  2334. if (line.contains("puppet")) {
  2335. old = line;
  2336. line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2337. if (old != line) {
  2338. found_renames.append(line_formatter(current_line, "puppetsync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));
  2339. }
  2340. }
  2341. if (line.contains("master")) {
  2342. old = line;
  2343. line = reg_container.keyword_gdscript_master.sub(line, "@rpc func", true);
  2344. if (old != line) {
  2345. found_renames.append(line_formatter(current_line, "master func", "@rpc func", line));
  2346. }
  2347. }
  2348. if (line.contains("master")) {
  2349. old = line;
  2350. line = reg_container.keyword_gdscript_master.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2351. if (old != line) {
  2352. found_renames.append(line_formatter(current_line, "mastersync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));
  2353. }
  2354. }
  2355. }
  2356. current_line++;
  2357. }
  2358. return found_renames;
  2359. }
  2360. void ProjectConverter3To4::rename_input_map_scancode(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2361. // The old Special Key, now colliding with CMD_OR_CTRL.
  2362. const int old_spkey = (1 << 24);
  2363. for (SourceLine &source_line : source_lines) {
  2364. if (source_line.is_comment) {
  2365. continue;
  2366. }
  2367. String &line = source_line.line;
  2368. if (uint64_t(line.length()) <= maximum_line_length) {
  2369. TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
  2370. for (int i = 0; i < reg_match.size(); ++i) {
  2371. Ref<RegExMatch> match = reg_match[i];
  2372. PackedStringArray strings = match->get_strings();
  2373. int key = strings[3].to_int();
  2374. if (key & old_spkey) {
  2375. // Create new key, clearing old Special Key and setting new one.
  2376. key = (key & ~old_spkey) | (int)Key::SPECIAL;
  2377. line = line.replace(strings[0], String(",\"") + strings[1] + "scancode\":" + String::num_int64(key));
  2378. }
  2379. }
  2380. }
  2381. }
  2382. }
  2383. void ProjectConverter3To4::rename_joypad_buttons_and_axes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2384. for (SourceLine &source_line : source_lines) {
  2385. if (source_line.is_comment) {
  2386. continue;
  2387. }
  2388. String &line = source_line.line;
  2389. if (uint64_t(line.length()) <= maximum_line_length) {
  2390. // Remap button indexes.
  2391. TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);
  2392. for (int i = 0; i < reg_match.size(); ++i) {
  2393. Ref<RegExMatch> match = reg_match[i];
  2394. PackedStringArray strings = match->get_strings();
  2395. const String &button_index_entry = strings[0];
  2396. int button_index_value = strings[1].to_int();
  2397. if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.
  2398. line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");
  2399. line = line.replace(button_index_entry, ",\"axis\":4,\"axis_value\":1.0");
  2400. } else if (button_index_value == 7) {
  2401. line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");
  2402. line = line.replace(button_index_entry, ",\"axis\":5,\"axis_value\":1.0");
  2403. } else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.
  2404. const String &pressure_and_pressed_properties = strings[2];
  2405. line = line.replace(button_index_entry, ",\"button_index\":" + String::num_int64(reg_container.joypad_button_mappings[button_index_value]) + "," + pressure_and_pressed_properties);
  2406. }
  2407. }
  2408. // Remap axes. Only L2 and R2 need remapping.
  2409. reg_match = reg_container.joypad_axis.search_all(line);
  2410. for (int i = 0; i < reg_match.size(); ++i) {
  2411. Ref<RegExMatch> match = reg_match[i];
  2412. PackedStringArray strings = match->get_strings();
  2413. const String &axis_entry = strings[0];
  2414. int axis_value = strings[1].to_int();
  2415. if (axis_value == 6) {
  2416. line = line.replace(axis_entry, ",\"axis\":4");
  2417. } else if (axis_value == 7) {
  2418. line = line.replace(axis_entry, ",\"axis\":5");
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. Vector<String> ProjectConverter3To4::check_for_rename_joypad_buttons_and_axes(Vector<String> &lines, const RegExContainer &reg_container) {
  2425. Vector<String> found_renames;
  2426. int current_line = 1;
  2427. for (String &line : lines) {
  2428. if (uint64_t(line.length()) <= maximum_line_length) {
  2429. // Remap button indexes.
  2430. TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);
  2431. for (int i = 0; i < reg_match.size(); ++i) {
  2432. Ref<RegExMatch> match = reg_match[i];
  2433. PackedStringArray strings = match->get_strings();
  2434. const String &button_index_entry = strings[0];
  2435. int button_index_value = strings[1].to_int();
  2436. if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.
  2437. found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));
  2438. found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":4", line));
  2439. } else if (button_index_value == 7) {
  2440. found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));
  2441. found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":5", line));
  2442. } else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.
  2443. found_renames.append(line_formatter(current_line, "\"button_index\":" + strings[1], "\"button_index\":" + String::num_int64(reg_container.joypad_button_mappings[button_index_value]), line));
  2444. }
  2445. }
  2446. // Remap axes. Only L2 and R2 need remapping.
  2447. reg_match = reg_container.joypad_axis.search_all(line);
  2448. for (int i = 0; i < reg_match.size(); ++i) {
  2449. Ref<RegExMatch> match = reg_match[i];
  2450. PackedStringArray strings = match->get_strings();
  2451. const String &axis_entry = strings[0];
  2452. int axis_value = strings[1].to_int();
  2453. if (axis_value == 6) {
  2454. found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":4", line));
  2455. } else if (axis_value == 7) {
  2456. found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":5", line));
  2457. }
  2458. }
  2459. current_line++;
  2460. }
  2461. }
  2462. return found_renames;
  2463. }
  2464. Vector<String> ProjectConverter3To4::check_for_rename_input_map_scancode(Vector<String> &lines, const RegExContainer &reg_container) {
  2465. Vector<String> found_renames;
  2466. // The old Special Key, now colliding with CMD_OR_CTRL.
  2467. const int old_spkey = (1 << 24);
  2468. int current_line = 1;
  2469. for (String &line : lines) {
  2470. if (uint64_t(line.length()) <= maximum_line_length) {
  2471. TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
  2472. for (int i = 0; i < reg_match.size(); ++i) {
  2473. Ref<RegExMatch> match = reg_match[i];
  2474. PackedStringArray strings = match->get_strings();
  2475. int key = strings[3].to_int();
  2476. if (key & old_spkey) {
  2477. // Create new key, clearing old Special Key and setting new one.
  2478. key = (key & ~old_spkey) | (int)Key::SPECIAL;
  2479. found_renames.append(line_formatter(current_line, strings[3], String::num_int64(key), line));
  2480. }
  2481. }
  2482. }
  2483. current_line++;
  2484. }
  2485. return found_renames;
  2486. }
  2487. void ProjectConverter3To4::custom_rename(Vector<SourceLine> &source_lines, const String &from, const String &to) {
  2488. RegEx reg = RegEx(String("\\b") + from + "\\b");
  2489. CRASH_COND(!reg.is_valid());
  2490. for (SourceLine &source_line : source_lines) {
  2491. if (source_line.is_comment) {
  2492. continue;
  2493. }
  2494. String &line = source_line.line;
  2495. if (uint64_t(line.length()) <= maximum_line_length) {
  2496. line = reg.sub(line, to, true);
  2497. }
  2498. }
  2499. };
  2500. Vector<String> ProjectConverter3To4::check_for_custom_rename(Vector<String> &lines, const String &from, const String &to) {
  2501. Vector<String> found_renames;
  2502. RegEx reg = RegEx(String("\\b") + from + "\\b");
  2503. CRASH_COND(!reg.is_valid());
  2504. int current_line = 1;
  2505. for (String &line : lines) {
  2506. if (uint64_t(line.length()) <= maximum_line_length) {
  2507. TypedArray<RegExMatch> reg_match = reg.search_all(line);
  2508. if (reg_match.size() > 0) {
  2509. found_renames.append(line_formatter(current_line, from.replace("\\.", "."), to, line)); // Without replacing it will print "\.shader" instead ".shader".
  2510. }
  2511. }
  2512. current_line++;
  2513. }
  2514. return found_renames;
  2515. }
  2516. void ProjectConverter3To4::rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<SourceLine> &source_lines) {
  2517. for (SourceLine &source_line : source_lines) {
  2518. if (source_line.is_comment) {
  2519. continue;
  2520. }
  2521. String &line = source_line.line;
  2522. if (uint64_t(line.length()) <= maximum_line_length) {
  2523. for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {
  2524. if (line.contains(array[current_index][0])) {
  2525. line = cached_regexes[current_index]->sub(line, array[current_index][1], true);
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. Vector<String> ProjectConverter3To4::check_for_rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<String> &lines) {
  2532. Vector<String> found_renames;
  2533. int current_line = 1;
  2534. for (String &line : lines) {
  2535. if (uint64_t(line.length()) <= maximum_line_length) {
  2536. for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {
  2537. if (line.contains(array[current_index][0])) {
  2538. TypedArray<RegExMatch> reg_match = cached_regexes[current_index]->search_all(line);
  2539. if (reg_match.size() > 0) {
  2540. found_renames.append(line_formatter(current_line, array[current_index][0], array[current_index][1], line));
  2541. }
  2542. }
  2543. }
  2544. }
  2545. current_line++;
  2546. }
  2547. return found_renames;
  2548. }
  2549. // Prints full info about renamed things e.g.:
  2550. // Line (67) remove -> remove_at - LINE """ doubler._blacklist.remove(0) """
  2551. String ProjectConverter3To4::line_formatter(int current_line, String from, String to, String line) {
  2552. if (from.size() > 200) {
  2553. from = from.substr(0, 197) + "...";
  2554. }
  2555. if (to.size() > 200) {
  2556. to = to.substr(0, 197) + "...";
  2557. }
  2558. if (line.size() > 400) {
  2559. line = line.substr(0, 397) + "...";
  2560. }
  2561. from = from.strip_escapes();
  2562. to = to.strip_escapes();
  2563. line = line.replace("\r", "").replace("\n", "").strip_edges();
  2564. return vformat("Line(%d), %s -> %s - LINE \"\"\" %s \"\"\"", current_line, from, to, line);
  2565. }
  2566. // Prints only full lines e.g.:
  2567. // Line (1) - FULL LINES - """yield(get_tree().create_timer(3), 'timeout')""" =====> """ await get_tree().create_timer(3).timeout """
  2568. String ProjectConverter3To4::simple_line_formatter(int current_line, String old_line, String new_line) {
  2569. if (old_line.size() > 1000) {
  2570. old_line = old_line.substr(0, 997) + "...";
  2571. }
  2572. if (new_line.size() > 1000) {
  2573. new_line = new_line.substr(0, 997) + "...";
  2574. }
  2575. old_line = old_line.replace("\r", "").replace("\n", "").strip_edges();
  2576. new_line = new_line.replace("\r", "").replace("\n", "").strip_edges();
  2577. return vformat("Line (%d) - FULL LINES - \"\"\" %s \"\"\" =====> \"\"\" %s \"\"\"", current_line, old_line, new_line);
  2578. }
  2579. // Collects string from vector strings
  2580. String ProjectConverter3To4::collect_string_from_vector(Vector<SourceLine> &vector) {
  2581. String string = "";
  2582. for (int i = 0; i < vector.size(); i++) {
  2583. string += vector[i].line;
  2584. if (i != vector.size() - 1) {
  2585. string += "\n";
  2586. }
  2587. }
  2588. return string;
  2589. }
  2590. #endif // MODULE_REGEX_ENABLED
  2591. #endif // DISABLE_DEPRECATED