project_converter_3_to_4.cpp 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961
  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(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(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(String name, 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_mutli = 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. 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(String name, String expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &, bool), 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(String name, String expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &), 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(String name, String expected, const char *array[][2], LocalVector<RegEx *> &regex_cache, 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(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
  786. 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);
  787. 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);
  788. 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);
  789. 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);
  790. 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);
  791. 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);
  792. valid = valid && test_conversion_gdscript_builtin("to_json( AA ) szon", "JSON.new().stringify( AA ) szon", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  793. valid = valid && test_conversion_gdscript_builtin("s to_json", "s JSON.new().stringify", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  794. valid = valid && test_conversion_gdscript_builtin("AF to_json2", "AF to_json2", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  795. 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);
  796. valid = valid && test_conversion_gdscript_builtin("empty()", "is_empty()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  797. valid = valid && test_conversion_gdscript_builtin(".empty", ".empty", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  798. valid = valid && test_conversion_gdscript_builtin(").roman(", ").roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  799. valid = valid && test_conversion_gdscript_builtin("\t.roman(", "\tsuper.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  800. valid = valid && test_conversion_gdscript_builtin(" .roman(", " super.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  801. valid = valid && test_conversion_gdscript_builtin(".1", ".1", &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("'.'", "'.'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  804. valid = valid && test_conversion_gdscript_builtin("'.a'", "'.a'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  805. valid = valid && test_conversion_gdscript_builtin("\t._input(_event)", "\tsuper._input(_event)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  806. 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);
  807. 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);
  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,E]) != OK):", "(connect(A, Callable(B, C).bind(D,E)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  810. 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);
  811. 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);
  812. valid = valid && test_conversion_gdscript_builtin(".connect(A,B,C)", ".connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  813. 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);
  814. valid = valid && test_conversion_gdscript_builtin("\tconnect(A,B,C)", "\tconnect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  815. valid = valid && test_conversion_gdscript_builtin(" connect(A,B,C)", " connect(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,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  817. 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);
  818. valid = valid && test_conversion_gdscript_builtin("$connect(A,B,C)", "$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("(start(A,B) != OK):", "(start(Callable(A, B)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  821. valid = valid && test_conversion_gdscript_builtin("func start(A,B):", "func start(A,B):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  822. 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);
  823. 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);
  824. 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);
  825. 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);
  826. 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);
  827. 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);
  828. 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);
  829. 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);
  830. valid = valid && test_conversion_gdscript_builtin("func _init(", "func _init(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  831. 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);
  832. 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);
  833. 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);
  834. 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);
  835. 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);
  836. 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);
  837. 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);
  838. 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);
  839. 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);
  840. 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);
  841. 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);
  842. 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);
  843. valid = valid && test_conversion_gdscript_builtin("PackedStringArray(req_godot).join('.')", "'.'.join(PackedStringArray(req_godot))", &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("apply_force(position, impulse)", "apply_force(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  846. valid = valid && test_conversion_gdscript_builtin("apply_impulse(position, impulse)", "apply_impulse(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  847. 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);
  848. valid = valid && test_conversion_gdscript_builtin("get_focus_owner()", "get_viewport().gui_get_focus_owner()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  849. valid = valid && test_conversion_gdscript_builtin("button.pressed = 1", "button.button_pressed = 1", &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 SF", "button.pressed SF", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
  852. valid = valid && test_conversion_with_regex("Color(\"#f47d\")", "Color(\"#47df\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  853. valid = valid && test_conversion_with_regex("Color(\"#ff478cbf\")", "Color(\"#478cbfff\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  854. valid = valid && test_conversion_with_regex("Color(\"#de32bf\")", "Color(\"#de32bf\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);
  855. valid = valid && test_conversion_with_regex("AAA Color.white AF", "AAA Color.WHITE AF", &ProjectConverter3To4::rename_colors, "color constants", reg_container);
  856. // Note: Do not change to *scancode*, it is applied before that conversion.
  857. 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);
  858. 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);
  859. 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);
  860. valid = valid && test_conversion_with_regex("\"device\":0,\"axis\":6,", "\"device\":0,\"axis\":4,", &ProjectConverter3To4::rename_joypad_buttons_and_axes, "custom rename", reg_container);
  861. 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);
  862. // Custom rule conversion
  863. {
  864. String from = "instance";
  865. String to = "instantiate";
  866. String name = "AA.instance()";
  867. Vector<SourceLine> got = split_lines(name);
  868. String expected = "AA.instantiate()";
  869. custom_rename(got, from, to);
  870. String got_str = collect_string_from_vector(got);
  871. if (got_str != expected) {
  872. ERR_PRINT(vformat("Failed to convert custom rename \"%s\" to \"%s\", got \"%s\", instead.", name, expected, got_str));
  873. }
  874. valid = valid && (got_str == expected);
  875. }
  876. // get_object_of_execution
  877. {
  878. String base = "var roman = kieliszek.";
  879. String expected = "kieliszek.";
  880. String got = get_object_of_execution(base);
  881. if (got != expected) {
  882. 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()));
  883. }
  884. valid = valid && (got == expected);
  885. }
  886. {
  887. String base = "r.";
  888. String expected = "r.";
  889. String got = get_object_of_execution(base);
  890. if (got != expected) {
  891. 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()));
  892. }
  893. valid = valid && (got == expected);
  894. }
  895. {
  896. String base = "mortadela(";
  897. String expected = "";
  898. String got = get_object_of_execution(base);
  899. if (got != expected) {
  900. 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()));
  901. }
  902. valid = valid && (got == expected);
  903. }
  904. {
  905. String base = "var node = $world/ukraine/lviv.";
  906. String expected = "$world/ukraine/lviv.";
  907. String got = get_object_of_execution(base);
  908. if (got != expected) {
  909. 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()));
  910. }
  911. valid = valid && (got == expected);
  912. }
  913. // get_starting_space
  914. {
  915. String base = "\t\t\t var roman = kieliszek.";
  916. String expected = "\t\t\t";
  917. String got = get_starting_space(base);
  918. if (got != expected) {
  919. 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()));
  920. }
  921. valid = valid && (got == expected);
  922. }
  923. // Parse Arguments
  924. {
  925. String line = "( )";
  926. Vector<String> got_vector = parse_arguments(line);
  927. String got = "";
  928. String expected = "";
  929. for (String &part : got_vector) {
  930. got += part + "|||";
  931. }
  932. if (got != expected) {
  933. 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()));
  934. }
  935. valid = valid && (got == expected);
  936. }
  937. {
  938. String line = "(a , b , c)";
  939. Vector<String> got_vector = parse_arguments(line);
  940. String got = "";
  941. String expected = "a|||b|||c|||";
  942. for (String &part : got_vector) {
  943. got += part + "|||";
  944. }
  945. if (got != expected) {
  946. 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()));
  947. }
  948. valid = valid && (got == expected);
  949. }
  950. {
  951. String line = "(a , \"b,\" , c)";
  952. Vector<String> got_vector = parse_arguments(line);
  953. String got = "";
  954. String expected = "a|||\"b,\"|||c|||";
  955. for (String &part : got_vector) {
  956. got += part + "|||";
  957. }
  958. if (got != expected) {
  959. 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()));
  960. }
  961. valid = valid && (got == expected);
  962. }
  963. {
  964. String line = "(a , \"(,),,,,\" , c)";
  965. Vector<String> got_vector = parse_arguments(line);
  966. String got = "";
  967. String expected = "a|||\"(,),,,,\"|||c|||";
  968. for (String &part : got_vector) {
  969. got += part + "|||";
  970. }
  971. if (got != expected) {
  972. 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()));
  973. }
  974. valid = valid && (got == expected);
  975. }
  976. return valid;
  977. }
  978. // Validate in all arrays if names don't do cyclic renames "Node" -> "Node2D" | "Node2D" -> "2DNode"
  979. bool ProjectConverter3To4::test_array_names() {
  980. bool valid = true;
  981. Vector<String> names = Vector<String>();
  982. // Validate if all classes are valid.
  983. {
  984. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  985. const String old_class = RenamesMap3To4::class_renames[current_index][0];
  986. const String new_class = RenamesMap3To4::class_renames[current_index][1];
  987. // Light2D, Texture, Viewport are special classes(probably virtual ones).
  988. if (ClassDB::class_exists(StringName(old_class)) && old_class != "Light2D" && old_class != "Texture" && old_class != "Viewport") {
  989. ERR_PRINT(vformat("Class \"%s\" exists in Godot 4, so it cannot be renamed to something else.", old_class));
  990. valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.
  991. }
  992. // Callable is special class, to which normal classes may be renamed.
  993. if (!ClassDB::class_exists(StringName(new_class)) && new_class != "Callable") {
  994. ERR_PRINT(vformat("Class \"%s\" does not exist in Godot 4, so it cannot be used in the conversion.", old_class));
  995. valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.
  996. }
  997. }
  998. }
  999. {
  1000. HashSet<String> all_functions;
  1001. // List of excluded functions from builtin types and global namespace, because currently it is not possible to get list of functions from them.
  1002. // This will be available when https://github.com/godotengine/godot/pull/49053 or similar will be included into Godot.
  1003. 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 };
  1004. for (int current_index = 0; builtin_types_excluded_functions[current_index]; current_index++) {
  1005. all_functions.insert(builtin_types_excluded_functions[current_index]);
  1006. }
  1007. //for (int type = Variant::Type::NIL + 1; type < Variant::Type::VARIANT_MAX; type++) {
  1008. // List<MethodInfo> method_list;
  1009. // Variant::get_method_list_by_type(&method_list, Variant::Type(type));
  1010. // for (MethodInfo &function_data : method_list) {
  1011. // if (!all_functions.has(function_data.name)) {
  1012. // all_functions.insert(function_data.name);
  1013. // }
  1014. // }
  1015. //}
  1016. List<StringName> classes_list;
  1017. ClassDB::get_class_list(&classes_list);
  1018. for (StringName &name_of_class : classes_list) {
  1019. List<MethodInfo> method_list;
  1020. ClassDB::get_method_list(name_of_class, &method_list, true);
  1021. for (MethodInfo &function_data : method_list) {
  1022. if (!all_functions.has(function_data.name)) {
  1023. all_functions.insert(function_data.name);
  1024. }
  1025. }
  1026. }
  1027. int current_element = 0;
  1028. while (RenamesMap3To4::gdscript_function_renames[current_element][0] != nullptr) {
  1029. String name_3_x = RenamesMap3To4::gdscript_function_renames[current_element][0];
  1030. String name_4_0 = RenamesMap3To4::gdscript_function_renames[current_element][1];
  1031. if (!all_functions.has(name_4_0)) {
  1032. ERR_PRINT(vformat("Missing GDScript function in pair (%s - ===> %s <===)", name_3_x, name_4_0));
  1033. valid = false;
  1034. }
  1035. current_element++;
  1036. }
  1037. }
  1038. if (!valid) {
  1039. 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.");
  1040. }
  1041. valid = valid && test_single_array(RenamesMap3To4::enum_renames);
  1042. valid = valid && test_single_array(RenamesMap3To4::class_renames, true);
  1043. valid = valid && test_single_array(RenamesMap3To4::gdscript_function_renames, true);
  1044. valid = valid && test_single_array(RenamesMap3To4::csharp_function_renames, true);
  1045. valid = valid && test_single_array(RenamesMap3To4::gdscript_properties_renames, true);
  1046. valid = valid && test_single_array(RenamesMap3To4::csharp_properties_renames, true);
  1047. valid = valid && test_single_array(RenamesMap3To4::shaders_renames, true);
  1048. valid = valid && test_single_array(RenamesMap3To4::gdscript_signals_renames);
  1049. valid = valid && test_single_array(RenamesMap3To4::project_settings_renames);
  1050. valid = valid && test_single_array(RenamesMap3To4::project_godot_renames);
  1051. valid = valid && test_single_array(RenamesMap3To4::input_map_renames);
  1052. valid = valid && test_single_array(RenamesMap3To4::builtin_types_renames);
  1053. valid = valid && test_single_array(RenamesMap3To4::color_renames);
  1054. return valid;
  1055. }
  1056. // Validates the array to prevent cyclic renames, such as `Node` -> `Node2D`, then `Node2D` -> `2DNode`.
  1057. // Also checks if names contain leading or trailing spaces.
  1058. bool ProjectConverter3To4::test_single_array(const char *p_array[][2], bool p_ignore_4_0_name) {
  1059. bool valid = true;
  1060. Vector<String> names = Vector<String>();
  1061. for (unsigned int current_index = 0; p_array[current_index][0]; current_index++) {
  1062. String name_3_x = p_array[current_index][0];
  1063. String name_4_0 = p_array[current_index][1];
  1064. if (name_3_x != name_3_x.strip_edges()) {
  1065. ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));
  1066. valid = false;
  1067. }
  1068. if (names.has(name_3_x)) {
  1069. ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));
  1070. valid = false;
  1071. }
  1072. names.append(name_3_x);
  1073. if (name_4_0 != name_4_0.strip_edges()) {
  1074. ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));
  1075. valid = false;
  1076. }
  1077. if (names.has(name_4_0)) {
  1078. ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));
  1079. valid = false;
  1080. }
  1081. if (!p_ignore_4_0_name) {
  1082. names.append(name_4_0);
  1083. }
  1084. }
  1085. return valid;
  1086. };
  1087. // Returns arguments from given function execution, this cannot be really done as regex.
  1088. // `abc(d,e(f,g),h)` -> [d], [e(f,g)], [h]
  1089. Vector<String> ProjectConverter3To4::parse_arguments(const String &line) {
  1090. Vector<String> parts;
  1091. int string_size = line.length();
  1092. int start_part = 0; // Index of beginning of start part.
  1093. int parts_counter = 0;
  1094. char32_t previous_character = '\0';
  1095. bool is_inside_string = false; // If true, it ignores these 3 characters ( , ) inside string.
  1096. 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));
  1097. for (int current_index = 0; current_index < string_size; current_index++) {
  1098. char32_t character = line.get(current_index);
  1099. switch (character) {
  1100. case '(':
  1101. case '[':
  1102. case '{': {
  1103. parts_counter++;
  1104. if (parts_counter == 1 && !is_inside_string) {
  1105. start_part = current_index;
  1106. }
  1107. break;
  1108. };
  1109. case ')':
  1110. case '}': {
  1111. parts_counter--;
  1112. if (parts_counter == 0 && !is_inside_string) {
  1113. parts.append(line.substr(start_part + 1, current_index - start_part - 1));
  1114. start_part = current_index;
  1115. }
  1116. break;
  1117. };
  1118. case ']': {
  1119. parts_counter--;
  1120. if (parts_counter == 0 && !is_inside_string) {
  1121. parts.append(line.substr(start_part, current_index - start_part));
  1122. start_part = current_index;
  1123. }
  1124. break;
  1125. };
  1126. case ',': {
  1127. if (parts_counter == 1 && !is_inside_string) {
  1128. parts.append(line.substr(start_part + 1, current_index - start_part - 1));
  1129. start_part = current_index;
  1130. }
  1131. break;
  1132. };
  1133. case '"': {
  1134. if (previous_character != '\\')
  1135. is_inside_string = !is_inside_string;
  1136. }
  1137. }
  1138. previous_character = character;
  1139. }
  1140. Vector<String> clean_parts;
  1141. for (String &part : parts) {
  1142. part = part.strip_edges();
  1143. if (!part.is_empty()) {
  1144. clean_parts.append(part);
  1145. }
  1146. }
  1147. return clean_parts;
  1148. }
  1149. // Finds latest parenthesis owned by function.
  1150. // `function(abc(a,b),DD)):` finds this parenthess `function(abc(a,b),DD => ) <= ):`
  1151. int ProjectConverter3To4::get_end_parenthesis(const String &line) const {
  1152. int current_state = 0;
  1153. for (int current_index = 0; line.length() > current_index; current_index++) {
  1154. char32_t character = line.get(current_index);
  1155. if (character == '(') {
  1156. current_state++;
  1157. }
  1158. if (character == ')') {
  1159. current_state--;
  1160. if (current_state == 0) {
  1161. return current_index;
  1162. }
  1163. }
  1164. }
  1165. return -1;
  1166. }
  1167. // Merges multiple arguments into a single String.
  1168. // Needed when after processing e.g. 2 arguments, later arguments are not changed in any way.
  1169. String ProjectConverter3To4::connect_arguments(const Vector<String> &arguments, int from, int to) const {
  1170. if (to == -1) {
  1171. to = arguments.size();
  1172. }
  1173. String value;
  1174. if (arguments.size() > 0 && from != 0 && from < to) {
  1175. value = ", ";
  1176. }
  1177. for (int i = from; i < to; i++) {
  1178. value += arguments[i];
  1179. if (i != to - 1) {
  1180. value += ", ";
  1181. }
  1182. }
  1183. return value;
  1184. }
  1185. // Returns the indentation (spaces and tabs) at the start of the line e.g. `\t\tmove_this` returns `\t\t`.
  1186. String ProjectConverter3To4::get_starting_space(const String &line) const {
  1187. String empty_space;
  1188. int current_character = 0;
  1189. if (line.is_empty()) {
  1190. return empty_space;
  1191. }
  1192. if (line[0] == ' ') {
  1193. while (current_character < line.size()) {
  1194. if (line[current_character] == ' ') {
  1195. empty_space += ' ';
  1196. current_character++;
  1197. } else {
  1198. break;
  1199. }
  1200. }
  1201. }
  1202. if (line[0] == '\t') {
  1203. while (current_character < line.size()) {
  1204. if (line[current_character] == '\t') {
  1205. empty_space += '\t';
  1206. current_character++;
  1207. } else {
  1208. break;
  1209. }
  1210. }
  1211. }
  1212. return empty_space;
  1213. }
  1214. // Returns the object that’s executing the function in the line.
  1215. // e.g. Passing the line "var roman = kieliszek.funkcja()" to this function returns "kieliszek".
  1216. String ProjectConverter3To4::get_object_of_execution(const String &line) const {
  1217. int end = line.size() - 1; // Last one is \0
  1218. int variable_start = end - 1;
  1219. int start = end - 1;
  1220. bool is_possibly_nodepath = false;
  1221. bool is_valid_nodepath = false;
  1222. while (start >= 0) {
  1223. char32_t character = line[start];
  1224. bool is_variable_char = (character >= 'A' && character <= 'Z') || (character >= 'a' && character <= 'z') || character == '.' || character == '_';
  1225. bool is_nodepath_start = character == '$';
  1226. bool is_nodepath_sep = character == '/';
  1227. if (is_variable_char || is_nodepath_start || is_nodepath_sep) {
  1228. if (start == 0) {
  1229. break;
  1230. } else if (is_nodepath_sep) {
  1231. // Freeze variable_start, try to fetch more chars since this might be a Node path literal.
  1232. is_possibly_nodepath = true;
  1233. } else if (is_nodepath_start) {
  1234. // Found $, this is a Node path literal.
  1235. is_valid_nodepath = true;
  1236. break;
  1237. }
  1238. if (!is_possibly_nodepath) {
  1239. variable_start--;
  1240. }
  1241. start--;
  1242. continue;
  1243. } else {
  1244. // Abandon all hope, this is neither a variable nor a Node path literal.
  1245. variable_start++; // Found invalid character, needs to be ignored.
  1246. break;
  1247. }
  1248. }
  1249. if (is_valid_nodepath) {
  1250. variable_start = start;
  1251. }
  1252. return line.substr(variable_start, (end - variable_start));
  1253. }
  1254. void ProjectConverter3To4::rename_colors(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1255. for (SourceLine &source_line : source_lines) {
  1256. if (source_line.is_comment) {
  1257. continue;
  1258. }
  1259. String &line = source_line.line;
  1260. if (uint64_t(line.length()) <= maximum_line_length) {
  1261. if (line.contains("Color.")) {
  1262. for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {
  1263. line = reg_container.color_regexes[current_index]->sub(line, reg_container.color_renamed[current_index], true);
  1264. }
  1265. }
  1266. }
  1267. }
  1268. };
  1269. // Convert hexadecimal colors from ARGB to RGBA
  1270. void ProjectConverter3To4::convert_hexadecimal_colors(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1271. for (SourceLine &source_line : source_lines) {
  1272. if (source_line.is_comment) {
  1273. continue;
  1274. }
  1275. String &line = source_line.line;
  1276. if (uint64_t(line.length()) <= maximum_line_length) {
  1277. if (line.contains("Color(\"")) {
  1278. line = reg_container.color_hexadecimal_short_constructor.sub(line, "Color(\"#$2$1", true);
  1279. line = reg_container.color_hexadecimal_full_constructor.sub(line, "Color(\"#$2$1", true);
  1280. }
  1281. }
  1282. }
  1283. }
  1284. Vector<String> ProjectConverter3To4::check_for_rename_colors(Vector<String> &lines, const RegExContainer &reg_container) {
  1285. Vector<String> found_renames;
  1286. int current_line = 1;
  1287. for (String &line : lines) {
  1288. if (uint64_t(line.length()) <= maximum_line_length) {
  1289. if (line.contains("Color.")) {
  1290. for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {
  1291. TypedArray<RegExMatch> reg_match = reg_container.color_regexes[current_index]->search_all(line);
  1292. if (reg_match.size() > 0) {
  1293. found_renames.append(line_formatter(current_line, RenamesMap3To4::color_renames[current_index][0], RenamesMap3To4::color_renames[current_index][1], line));
  1294. }
  1295. }
  1296. }
  1297. }
  1298. current_line++;
  1299. }
  1300. return found_renames;
  1301. }
  1302. void ProjectConverter3To4::fix_tool_declaration(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1303. // In godot4, "tool" became "@tool" and must be located at the top of the file.
  1304. for (int i = 0; i < source_lines.size(); ++i) {
  1305. if (source_lines[i].line == "tool") {
  1306. source_lines.remove_at(i);
  1307. source_lines.insert(0, { "@tool", false });
  1308. return; // assuming there's at most 1 tool declaration.
  1309. }
  1310. }
  1311. }
  1312. void ProjectConverter3To4::fix_pause_mode(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1313. // In Godot 3, the pause_mode 2 equals the PAUSE_MODE_PROCESS value.
  1314. // In Godot 4, the pause_mode PAUSE_MODE_PROCESS was renamed to PROCESS_MODE_ALWAYS and equals the number 3.
  1315. // We therefore convert pause_mode = 2 to pause_mode = 3.
  1316. for (SourceLine &source_line : source_lines) {
  1317. String &line = source_line.line;
  1318. if (line == "pause_mode = 2") {
  1319. // Note: pause_mode is renamed to process_mode later on, so no need to do it here.
  1320. line = "pause_mode = 3";
  1321. }
  1322. }
  1323. }
  1324. void ProjectConverter3To4::rename_classes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  1325. for (SourceLine &source_line : source_lines) {
  1326. if (source_line.is_comment) {
  1327. continue;
  1328. }
  1329. String &line = source_line.line;
  1330. if (uint64_t(line.length()) <= maximum_line_length) {
  1331. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  1332. if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {
  1333. bool found_ignored_items = false;
  1334. // Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.
  1335. if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {
  1336. found_ignored_items = true;
  1337. line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);
  1338. line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);
  1339. line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);
  1340. }
  1341. // Causal renaming Spatial -> Node3D.
  1342. line = reg_container.class_regexes[current_index]->sub(line, RenamesMap3To4::class_renames[current_index][1], true);
  1343. // Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.
  1344. if (found_ignored_items) {
  1345. line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);
  1346. line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);
  1347. line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. };
  1354. Vector<String> ProjectConverter3To4::check_for_rename_classes(Vector<String> &lines, const RegExContainer &reg_container) {
  1355. Vector<String> found_renames;
  1356. int current_line = 1;
  1357. for (String &line : lines) {
  1358. if (uint64_t(line.length()) <= maximum_line_length) {
  1359. for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {
  1360. if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {
  1361. String old_line = line;
  1362. bool found_ignored_items = false;
  1363. // Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.
  1364. if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {
  1365. found_ignored_items = true;
  1366. line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);
  1367. line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);
  1368. line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);
  1369. }
  1370. // Causal renaming Spatial -> Node3D.
  1371. TypedArray<RegExMatch> reg_match = reg_container.class_regexes[current_index]->search_all(line);
  1372. if (reg_match.size() > 0) {
  1373. found_renames.append(line_formatter(current_line, RenamesMap3To4::class_renames[current_index][0], RenamesMap3To4::class_renames[current_index][1], old_line));
  1374. }
  1375. // Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.
  1376. if (found_ignored_items) {
  1377. line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);
  1378. line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);
  1379. line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);
  1380. }
  1381. }
  1382. }
  1383. }
  1384. current_line++;
  1385. }
  1386. return found_renames;
  1387. }
  1388. void ProjectConverter3To4::rename_gdscript_functions(Vector<SourceLine> &source_lines, const RegExContainer &reg_container, bool builtin) {
  1389. for (SourceLine &source_line : source_lines) {
  1390. if (source_line.is_comment) {
  1391. continue;
  1392. }
  1393. String &line = source_line.line;
  1394. if (uint64_t(line.length()) <= maximum_line_length) {
  1395. process_gdscript_line(line, reg_container, builtin);
  1396. }
  1397. }
  1398. };
  1399. Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector<String> &lines, const RegExContainer &reg_container, bool builtin) {
  1400. int current_line = 1;
  1401. Vector<String> found_renames;
  1402. for (String &line : lines) {
  1403. if (uint64_t(line.length()) <= maximum_line_length) {
  1404. String old_line = line;
  1405. process_gdscript_line(line, reg_container, builtin);
  1406. if (old_line != line) {
  1407. found_renames.append(simple_line_formatter(current_line, old_line, line));
  1408. }
  1409. }
  1410. }
  1411. return found_renames;
  1412. }
  1413. bool ProjectConverter3To4::contains_function_call(String &line, String function) const {
  1414. // We want to convert the function only if it is completely standalone.
  1415. // For example, when we search for "connect(", we don't want to accidentally convert "reconnect(".
  1416. if (!line.contains(function)) {
  1417. return false;
  1418. }
  1419. int index = line.find(function);
  1420. if (index == 0) {
  1421. return true;
  1422. }
  1423. char32_t previous_char = line.get(index - 1);
  1424. 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 != '@';
  1425. }
  1426. // TODO, this function should run only on all ".gd" files and also on lines in ".tscn" files which are parts of built-in Scripts.
  1427. void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContainer &reg_container, bool builtin) {
  1428. // In this and other functions, reg.sub() is used only after checking lines with str.contains().
  1429. // With longer lines, doing so can sometimes be significantly faster.
  1430. if ((line.contains(".lock") || line.contains(".unlock")) && !line.contains("mtx") && !line.contains("mutex") && !line.contains("Mutex")) {
  1431. 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);
  1432. 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);
  1433. }
  1434. // PackedStringArray(req_godot).join('.') -> '.'.join(PackedStringArray(req_godot)) PoolStringArray
  1435. if (line.contains(".join")) {
  1436. line = reg_container.reg_join.sub(line, "$2.join($1)", true);
  1437. }
  1438. // -- empty() -> is_empty() Pool*Array
  1439. if (line.contains("empty")) {
  1440. line = reg_container.reg_is_empty.sub(line, "is_empty(", true);
  1441. }
  1442. // -- \t.func() -> \tsuper.func() Object
  1443. if (line.contains("(") && line.contains(".")) {
  1444. 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"
  1445. }
  1446. // -- JSON.parse(a) -> JSON.new().parse(a) etc. JSON
  1447. if (line.contains("parse")) {
  1448. 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);
  1449. }
  1450. // -- to_json(a) -> JSON.new().stringify(a) Object
  1451. if (line.contains("to_json")) {
  1452. line = reg_container.reg_json_to.sub(line, "JSON.new().stringify", true);
  1453. }
  1454. // -- parse_json(a) -> JSON.get_data() etc. Object
  1455. if (line.contains("parse_json")) {
  1456. 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);
  1457. }
  1458. // -- JSON.print( -> JSON.stringify(
  1459. if (line.contains("JSON.print(")) {
  1460. line = reg_container.reg_json_print.sub(line, "JSON.stringify(", true);
  1461. }
  1462. // -- get_node(@ -> get_node( Node
  1463. if (line.contains("get_node")) {
  1464. line = line.replace("get_node(@", "get_node(");
  1465. }
  1466. if (line.contains("export")) {
  1467. // 1. export(float) var lifetime: float = 3.0 -> export var lifetime: float = 3.0
  1468. line = reg_container.reg_export_typed.sub(line, "export var $2: $1");
  1469. // 2. export(float) var lifetime := 3.0 -> export var lifetime := 3.0
  1470. line = reg_container.reg_export_inferred_type.sub(line, "export var $1 :=");
  1471. // 3. export(float) var lifetime = 3.0 -> export var lifetime: float = 3.0 GDScript
  1472. line = reg_container.reg_export_simple.sub(line, "export var $2: $1");
  1473. // 4. export(String, 'AnonymousPro', 'CourierPrime') var _font_name = 'AnonymousPro' -> export var _font_name = 'AnonymousPro' #(String, 'AnonymousPro', 'CourierPrime') GDScript
  1474. line = reg_container.reg_export_advanced.sub(line, "export var $2$3 # ($1)");
  1475. }
  1476. // Setget Setget
  1477. if (line.contains("setget")) {
  1478. line = reg_container.reg_setget_setget.sub(line, "var $1$2: get = $4, set = $3", true);
  1479. }
  1480. // Setget set
  1481. if (line.contains("setget")) {
  1482. line = reg_container.reg_setget_set.sub(line, "var $1$2: set = $3", true);
  1483. }
  1484. // Setget get
  1485. if (line.contains("setget")) {
  1486. line = reg_container.reg_setget_get.sub(line, "var $1$2: get = $3", true);
  1487. }
  1488. if (line.contains("window_resizable")) {
  1489. // OS.set_window_resizable(a) -> get_window().unresizable = not (a)
  1490. line = reg_container.reg_os_set_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);
  1491. // OS.window_resizable = a -> same
  1492. line = reg_container.reg_os_assign_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);
  1493. // OS.[is_]window_resizable() -> (not get_window().unresizable)
  1494. line = reg_container.reg_os_is_window_resizable.sub(line, "(not get_window().unresizable)", true);
  1495. }
  1496. if (line.contains("window_fullscreen")) {
  1497. // OS.window_fullscreen(a) -> get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (a) else Window.MODE_WINDOWED
  1498. line = reg_container.reg_os_set_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);
  1499. // window_fullscreen = a -> same
  1500. line = reg_container.reg_os_assign_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);
  1501. // OS.[is_]window_fullscreen() -> ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))
  1502. line = reg_container.reg_os_is_fullscreen.sub(line, "((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))", true);
  1503. }
  1504. if (line.contains("window_maximized")) {
  1505. // OS.window_maximized(a) -> get_window().mode = Window.MODE_MAXIMIZED if (a) else Window.MODE_WINDOWED
  1506. line = reg_container.reg_os_set_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1507. // window_maximized = a -> same
  1508. line = reg_container.reg_os_assign_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1509. // OS.[is_]window_maximized() -> (get_window().mode == Window.MODE_MAXIMIZED)
  1510. line = reg_container.reg_os_is_maximized.sub(line, "(get_window().mode == Window.MODE_MAXIMIZED)", true);
  1511. }
  1512. if (line.contains("window_minimized")) {
  1513. // OS.window_minimized(a) -> get_window().mode = Window.MODE_MINIMIZED if (a) else Window.MODE_WINDOWED
  1514. line = reg_container.reg_os_set_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1515. // window_minimized = a -> same
  1516. line = reg_container.reg_os_assign_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);
  1517. // OS.[is_]window_minimized() -> (get_window().mode == Window.MODE_MINIMIZED)
  1518. line = reg_container.reg_os_is_minimized.sub(line, "(get_window().mode == Window.MODE_MINIMIZED)", true);
  1519. }
  1520. if (line.contains("set_use_vsync")) {
  1521. // OS.set_use_vsync(a) -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)
  1522. line = reg_container.reg_os_set_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);
  1523. }
  1524. if (line.contains("vsync_enabled")) {
  1525. // vsync_enabled = a -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)
  1526. line = reg_container.reg_os_assign_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);
  1527. // OS.[is_]vsync_enabled() -> (DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)
  1528. line = reg_container.reg_os_is_vsync.sub(line, "(DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)", true);
  1529. }
  1530. if (line.contains("OS.screen_orientation")) { // keep "OS." at start
  1531. // OS.screen_orientation = a -> DisplayServer.screen_set_orientation(a)
  1532. line = reg_container.reg_os_assign_screen_orient.sub(line, "$1DisplayServer.screen_set_orientation($2)", true); // assignment
  1533. line = line.replace("OS.screen_orientation", "DisplayServer.screen_get_orientation()"); // value access
  1534. }
  1535. if (line.contains("_window_always_on_top")) {
  1536. // OS.set_window_always_on_top(a) -> get_window().always_on_top = (a)
  1537. line = reg_container.reg_os_set_always_on_top.sub(line, "get_window().always_on_top = ($1)", true);
  1538. // OS.is_window_always_on_top() -> get_window().always_on_top
  1539. line = reg_container.reg_os_is_always_on_top.sub(line, "get_window().always_on_top", true);
  1540. }
  1541. if (line.contains("et_borderless_window")) {
  1542. // OS.set_borderless_window(a) -> get_window().borderless = (a)
  1543. line = reg_container.reg_os_set_borderless.sub(line, "get_window().borderless = ($1)", true);
  1544. // OS.get_borderless_window() -> get_window().borderless
  1545. line = reg_container.reg_os_get_borderless.sub(line, "get_window().borderless", true);
  1546. }
  1547. // OS.SCREEN_ORIENTATION_* -> DisplayServer.SCREEN_*
  1548. if (line.contains("OS.SCREEN_ORIENTATION_")) {
  1549. line = reg_container.reg_os_screen_orient_enum.sub(line, "DisplayServer.SCREEN_$1", true);
  1550. }
  1551. // OS -> Window simple replacements with optional set/get.
  1552. if (line.contains("current_screen")) {
  1553. line = reg_container.reg_os_current_screen.sub(line, "get_window().$1current_screen", true);
  1554. }
  1555. if (line.contains("min_window_size")) {
  1556. line = reg_container.reg_os_min_window_size.sub(line, "get_window().$1min_size", true);
  1557. }
  1558. if (line.contains("max_window_size")) {
  1559. line = reg_container.reg_os_max_window_size.sub(line, "get_window().$1max_size", true);
  1560. }
  1561. if (line.contains("window_position")) {
  1562. line = reg_container.reg_os_window_position.sub(line, "get_window().$1position", true);
  1563. }
  1564. if (line.contains("window_size")) {
  1565. line = reg_container.reg_os_window_size.sub(line, "get_window().$1size", true);
  1566. }
  1567. if (line.contains("et_screen_orientation")) {
  1568. line = reg_container.reg_os_getset_screen_orient.sub(line, "DisplayServer.screen_$1et_orientation", true);
  1569. }
  1570. // Instantiate
  1571. if (contains_function_call(line, "instance")) {
  1572. line = reg_container.reg_instantiate.sub(line, ".instantiate($1)", true);
  1573. }
  1574. // -- r.move_and_slide( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody
  1575. if (contains_function_call(line, "move_and_slide(")) {
  1576. int start = line.find("move_and_slide(");
  1577. int end = get_end_parenthesis(line.substr(start)) + 1;
  1578. if (end > -1) {
  1579. String base_obj = get_object_of_execution(line.substr(0, start));
  1580. String starting_space = get_starting_space(line);
  1581. Vector<String> parts = parse_arguments(line.substr(start, end));
  1582. if (parts.size() >= 1) {
  1583. String line_new;
  1584. // motion_velocity
  1585. line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";
  1586. // up_direction
  1587. if (parts.size() >= 2) {
  1588. line_new += starting_space + base_obj + "set_up_direction(" + parts[1] + ")\n";
  1589. }
  1590. // stop_on_slope
  1591. if (parts.size() >= 3) {
  1592. line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[2] + ")\n";
  1593. }
  1594. // max_slides
  1595. if (parts.size() >= 4) {
  1596. line_new += starting_space + base_obj + "set_max_slides(" + parts[3] + ")\n";
  1597. }
  1598. // floor_max_angle
  1599. if (parts.size() >= 5) {
  1600. line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[4] + ")\n";
  1601. }
  1602. // infiinite_interia
  1603. if (parts.size() >= 6) {
  1604. line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[5] + "`\n";
  1605. }
  1606. line_new += starting_space + base_obj + "move_and_slide()";
  1607. if (!line.begins_with(starting_space + "move_and_slide")) {
  1608. line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);
  1609. } else {
  1610. line = line_new + line.substr(end + start);
  1611. }
  1612. }
  1613. }
  1614. }
  1615. // -- r.move_and_slide_with_snap( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody
  1616. if (contains_function_call(line, "move_and_slide_with_snap(")) {
  1617. int start = line.find("move_and_slide_with_snap(");
  1618. int end = get_end_parenthesis(line.substr(start)) + 1;
  1619. if (end > -1) {
  1620. String base_obj = get_object_of_execution(line.substr(0, start));
  1621. String starting_space = get_starting_space(line);
  1622. Vector<String> parts = parse_arguments(line.substr(start, end));
  1623. if (parts.size() >= 1) {
  1624. String line_new;
  1625. // motion_velocity
  1626. line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";
  1627. // snap
  1628. if (parts.size() >= 2) {
  1629. line_new += starting_space + "# TODOConverter3To4 looks that snap in Godot 4 is float, not vector like in Godot 3 - previous value `" + parts[1] + "`\n";
  1630. }
  1631. // up_direction
  1632. if (parts.size() >= 3) {
  1633. line_new += starting_space + base_obj + "set_up_direction(" + parts[2] + ")\n";
  1634. }
  1635. // stop_on_slope
  1636. if (parts.size() >= 4) {
  1637. line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[3] + ")\n";
  1638. }
  1639. // max_slides
  1640. if (parts.size() >= 5) {
  1641. line_new += starting_space + base_obj + "set_max_slides(" + parts[4] + ")\n";
  1642. }
  1643. // floor_max_angle
  1644. if (parts.size() >= 6) {
  1645. line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[5] + ")\n";
  1646. }
  1647. // infiinite_interia
  1648. if (parts.size() >= 7) {
  1649. line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[6] + "`\n";
  1650. }
  1651. line_new += starting_space + base_obj + "move_and_slide()";
  1652. if (!line.begins_with(starting_space + "move_and_slide_with_snap")) {
  1653. line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);
  1654. } else {
  1655. line = line_new + line.substr(end + start);
  1656. }
  1657. }
  1658. }
  1659. }
  1660. // -- sort_custom( a , b ) -> sort_custom(Callable( a , b )) Object
  1661. if (contains_function_call(line, "sort_custom(")) {
  1662. int start = line.find("sort_custom(");
  1663. int end = get_end_parenthesis(line.substr(start)) + 1;
  1664. if (end > -1) {
  1665. Vector<String> parts = parse_arguments(line.substr(start, end));
  1666. if (parts.size() == 2) {
  1667. line = line.substr(0, start) + "sort_custom(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1668. }
  1669. }
  1670. }
  1671. // -- list_dir_begin( ) -> list_dir_begin() Object
  1672. if (contains_function_call(line, "list_dir_begin(")) {
  1673. int start = line.find("list_dir_begin(");
  1674. int end = get_end_parenthesis(line.substr(start)) + 1;
  1675. if (end > -1) {
  1676. line = line.substr(0, start) + "list_dir_begin() " + line.substr(end + start) + "# TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547";
  1677. }
  1678. }
  1679. // -- draw_line(1,2,3,4,5) -> draw_line(1, 2, 3, 4) CanvasItem
  1680. if (contains_function_call(line, "draw_line(")) {
  1681. int start = line.find("draw_line(");
  1682. int end = get_end_parenthesis(line.substr(start)) + 1;
  1683. if (end > -1) {
  1684. Vector<String> parts = parse_arguments(line.substr(start, end));
  1685. if (parts.size() == 5) {
  1686. line = line.substr(0, start) + "draw_line(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ", " + parts[3] + ")" + line.substr(end + start);
  1687. }
  1688. }
  1689. }
  1690. // -- func c(var a, var b) -> func c(a, b)
  1691. if (line.contains("func ") && line.contains("var ")) {
  1692. int start = line.find("func ");
  1693. start = line.substr(start).find("(") + start;
  1694. int end = get_end_parenthesis(line.substr(start)) + 1;
  1695. if (end > -1) {
  1696. Vector<String> parts = parse_arguments(line.substr(start, end));
  1697. String start_string = line.substr(0, start) + "(";
  1698. for (int i = 0; i < parts.size(); i++) {
  1699. start_string += parts[i].strip_edges().trim_prefix("var ");
  1700. if (i != parts.size() - 1) {
  1701. start_string += ", ";
  1702. }
  1703. }
  1704. line = start_string + ")" + line.substr(end + start);
  1705. }
  1706. }
  1707. // -- yield(this, \"timeout\") -> await this.timeout GDScript
  1708. if (contains_function_call(line, "yield(")) {
  1709. int start = line.find("yield(");
  1710. int end = get_end_parenthesis(line.substr(start)) + 1;
  1711. if (end > -1) {
  1712. Vector<String> parts = parse_arguments(line.substr(start, end));
  1713. if (parts.size() == 2) {
  1714. if (builtin) {
  1715. line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\\\"", "").replace("\\'", "").replace(" ", "") + line.substr(end + start);
  1716. } else {
  1717. line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start);
  1718. }
  1719. }
  1720. }
  1721. }
  1722. // -- parse_json( AA ) -> TODO Object
  1723. if (contains_function_call(line, "parse_json(")) {
  1724. int start = line.find("parse_json(");
  1725. int end = get_end_parenthesis(line.substr(start)) + 1;
  1726. if (end > -1) {
  1727. Vector<String> parts = parse_arguments(line.substr(start, end));
  1728. line = line.substr(0, start) + "JSON.new().stringify(" + connect_arguments(parts, 0) + ")" + line.substr(end + start);
  1729. }
  1730. }
  1731. // -- .xform(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform
  1732. if (line.contains(".xform(")) {
  1733. int start = line.find(".xform(");
  1734. int end = get_end_parenthesis(line.substr(start)) + 1;
  1735. if (end > -1) {
  1736. Vector<String> parts = parse_arguments(line.substr(start, end));
  1737. if (parts.size() == 1) {
  1738. line = line.substr(0, start) + " * (" + parts[0] + ")" + line.substr(end + start);
  1739. }
  1740. }
  1741. }
  1742. // -- .xform_inv(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform
  1743. if (line.contains(".xform_inv(")) {
  1744. int start = line.find(".xform_inv(");
  1745. int end = get_end_parenthesis(line.substr(start)) + 1;
  1746. if (end > -1) {
  1747. String object_exec = get_object_of_execution(line.substr(0, start));
  1748. if (line.contains(object_exec + ".xform")) {
  1749. int start2 = line.find(object_exec + ".xform");
  1750. Vector<String> parts = parse_arguments(line.substr(start, end));
  1751. if (parts.size() == 1) {
  1752. line = line.substr(0, start2) + "(" + parts[0] + ") * " + object_exec + line.substr(end + start);
  1753. }
  1754. }
  1755. }
  1756. }
  1757. // -- "(connect(A,B,C,D,E) != OK):", "(connect(A, Callable(B, C).bind(D), E) Object
  1758. if (contains_function_call(line, "connect(")) {
  1759. int start = line.find("connect(");
  1760. int end = get_end_parenthesis(line.substr(start)) + 1;
  1761. if (end > -1) {
  1762. Vector<String> parts = parse_arguments(line.substr(start, end));
  1763. if (parts.size() == 3) {
  1764. line = line.substr(0, start) + "connect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1765. } else if (parts.size() >= 4) {
  1766. 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);
  1767. }
  1768. }
  1769. }
  1770. // -- disconnect(a,b,c) -> disconnect(a,Callable(b,c)) Object
  1771. if (contains_function_call(line, "disconnect(")) {
  1772. int start = line.find("disconnect(");
  1773. int end = get_end_parenthesis(line.substr(start)) + 1;
  1774. if (end > -1) {
  1775. Vector<String> parts = parse_arguments(line.substr(start, end));
  1776. if (parts.size() == 3) {
  1777. line = line.substr(0, start) + "disconnect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1778. }
  1779. }
  1780. }
  1781. // -- is_connected(a,b,c) -> is_connected(a,Callable(b,c)) Object
  1782. if (contains_function_call(line, "is_connected(")) {
  1783. int start = line.find("is_connected(");
  1784. int end = get_end_parenthesis(line.substr(start)) + 1;
  1785. if (end > -1) {
  1786. Vector<String> parts = parse_arguments(line.substr(start, end));
  1787. if (parts.size() == 3) {
  1788. line = line.substr(0, start) + "is_connected(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1789. }
  1790. }
  1791. }
  1792. // -- "(tween_method(A,B,C,D,E) != OK):", "(tween_method(Callable(A,B),C,D,E) Object
  1793. // -- "(tween_method(A,B,C,D,E,[F,G]) != OK):", "(tween_method(Callable(A,B).bind(F,G),C,D,E) Object
  1794. if (contains_function_call(line, "tween_method(")) {
  1795. int start = line.find("tween_method(");
  1796. int end = get_end_parenthesis(line.substr(start)) + 1;
  1797. if (end > -1) {
  1798. Vector<String> parts = parse_arguments(line.substr(start, end));
  1799. if (parts.size() == 5) {
  1800. line = line.substr(0, start) + "tween_method(Callable(" + parts[0] + ", " + parts[1] + "), " + parts[2] + ", " + parts[3] + ", " + parts[4] + ")" + line.substr(end + start);
  1801. } else if (parts.size() >= 6) {
  1802. 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);
  1803. }
  1804. }
  1805. }
  1806. // -- "(tween_callback(A,B,[C,D]) != OK):", "(connect(Callable(A,B).bind(C,D)) Object
  1807. if (contains_function_call(line, "tween_callback(")) {
  1808. int start = line.find("tween_callback(");
  1809. int end = get_end_parenthesis(line.substr(start)) + 1;
  1810. if (end > -1) {
  1811. Vector<String> parts = parse_arguments(line.substr(start, end));
  1812. if (parts.size() == 2) {
  1813. line = line.substr(0, start) + "tween_callback(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1814. } else if (parts.size() >= 3) {
  1815. 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);
  1816. }
  1817. }
  1818. }
  1819. // -- start(a,b) -> start(Callable(a, b)) Thread
  1820. // -- start(a,b,c,d) -> start(Callable(a, b).bind(c), d) Thread
  1821. if (contains_function_call(line, "start(")) {
  1822. int start = line.find("start(");
  1823. int end = get_end_parenthesis(line.substr(start)) + 1;
  1824. // Protection from 'func start'
  1825. if (!line.begins_with("func ")) {
  1826. if (end > -1) {
  1827. Vector<String> parts = parse_arguments(line.substr(start, end));
  1828. if (parts.size() == 2) {
  1829. line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);
  1830. } else if (parts.size() >= 3) {
  1831. line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);
  1832. }
  1833. }
  1834. }
  1835. }
  1836. // -- func _init(p_x:int).(p_x): -> func _init(p_x:int):\n\tsuper(p_x) Object # https://github.com/godotengine/godot/issues/70542
  1837. if (line.contains(" _init(") && line.rfind(":") > 0) {
  1838. // func _init(p_arg1).(super4, super5, super6)->void:
  1839. // ^--^indent ^super_start super_end^
  1840. int indent = line.count("\t", 0, line.find("func"));
  1841. int super_start = line.find(".(");
  1842. int super_end = line.rfind(")");
  1843. if (super_start > 0 && super_end > super_start) {
  1844. 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);
  1845. }
  1846. }
  1847. // create_from_image(aa, bb) -> create_from_image(aa) #, bb ImageTexture
  1848. if (contains_function_call(line, "create_from_image(")) {
  1849. int start = line.find("create_from_image(");
  1850. int end = get_end_parenthesis(line.substr(start)) + 1;
  1851. if (end > -1) {
  1852. Vector<String> parts = parse_arguments(line.substr(start, end));
  1853. if (parts.size() == 2) {
  1854. line = line.substr(0, start) + "create_from_image(" + parts[0] + ") " + "#," + parts[1] + line.substr(end + start);
  1855. }
  1856. }
  1857. }
  1858. // set_cell_item(a, b, c, d ,e) -> set_cell_item(Vector3(a, b, c), d ,e)
  1859. if (contains_function_call(line, "set_cell_item(")) {
  1860. int start = line.find("set_cell_item(");
  1861. int end = get_end_parenthesis(line.substr(start)) + 1;
  1862. if (end > -1) {
  1863. Vector<String> parts = parse_arguments(line.substr(start, end));
  1864. if (parts.size() > 2) {
  1865. line = line.substr(0, start) + "set_cell_item(Vector3(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3).lstrip(" ") + ")" + line.substr(end + start);
  1866. }
  1867. }
  1868. }
  1869. // get_cell_item(a, b, c) -> get_cell_item(Vector3i(a, b, c))
  1870. if (contains_function_call(line, "get_cell_item(")) {
  1871. int start = line.find("get_cell_item(");
  1872. int end = get_end_parenthesis(line.substr(start)) + 1;
  1873. if (end > -1) {
  1874. Vector<String> parts = parse_arguments(line.substr(start, end));
  1875. if (parts.size() == 3) {
  1876. line = line.substr(0, start) + "get_cell_item(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1877. }
  1878. }
  1879. }
  1880. // get_cell_item_orientation(a, b, c) -> get_cell_item_orientation(Vector3i(a, b, c))
  1881. if (contains_function_call(line, "get_cell_item_orientation(")) {
  1882. int start = line.find("get_cell_item_orientation(");
  1883. int end = get_end_parenthesis(line.substr(start)) + 1;
  1884. if (end > -1) {
  1885. Vector<String> parts = parse_arguments(line.substr(start, end));
  1886. if (parts.size() == 3) {
  1887. line = line.substr(0, start) + "get_cell_item_orientation(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1888. }
  1889. }
  1890. }
  1891. // apply_impulse(A, B) -> apply_impulse(B, A)
  1892. if (contains_function_call(line, "apply_impulse(")) {
  1893. int start = line.find("apply_impulse(");
  1894. int end = get_end_parenthesis(line.substr(start)) + 1;
  1895. if (end > -1) {
  1896. Vector<String> parts = parse_arguments(line.substr(start, end));
  1897. if (parts.size() == 2) {
  1898. line = line.substr(0, start) + "apply_impulse(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);
  1899. }
  1900. }
  1901. }
  1902. // apply_force(A, B) -> apply_force(B, A)
  1903. if (contains_function_call(line, "apply_force(")) {
  1904. int start = line.find("apply_force(");
  1905. int end = get_end_parenthesis(line.substr(start)) + 1;
  1906. if (end > -1) {
  1907. Vector<String> parts = parse_arguments(line.substr(start, end));
  1908. if (parts.size() == 2) {
  1909. line = line.substr(0, start) + "apply_force(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);
  1910. }
  1911. }
  1912. }
  1913. // map_to_world(a, b, c) -> map_to_local(Vector3i(a, b, c))
  1914. if (contains_function_call(line, "map_to_world(")) {
  1915. int start = line.find("map_to_world(");
  1916. int end = get_end_parenthesis(line.substr(start)) + 1;
  1917. if (end > -1) {
  1918. Vector<String> parts = parse_arguments(line.substr(start, end));
  1919. if (parts.size() == 3) {
  1920. line = line.substr(0, start) + "map_to_local(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  1921. } else if (parts.size() == 1) {
  1922. line = line.substr(0, start) + "map_to_local(" + parts[0] + ")" + line.substr(end + start);
  1923. }
  1924. }
  1925. }
  1926. // set_rotating(true) -> set_ignore_rotation(false)
  1927. if (contains_function_call(line, "set_rotating(")) {
  1928. int start = line.find("set_rotating(");
  1929. int end = get_end_parenthesis(line.substr(start)) + 1;
  1930. if (end > -1) {
  1931. Vector<String> parts = parse_arguments(line.substr(start, end));
  1932. if (parts.size() == 1) {
  1933. String opposite = parts[0] == "true" ? "false" : "true";
  1934. line = line.substr(0, start) + "set_ignore_rotation(" + opposite + ")";
  1935. }
  1936. }
  1937. }
  1938. // OS.get_window_safe_area() -> DisplayServer.get_display_safe_area()
  1939. if (line.contains("OS.get_window_safe_area(")) {
  1940. int start = line.find("OS.get_window_safe_area(");
  1941. int end = get_end_parenthesis(line.substr(start)) + 1;
  1942. if (end > -1) {
  1943. Vector<String> parts = parse_arguments(line.substr(start, end));
  1944. if (parts.size() == 0) {
  1945. line = line.substr(0, start) + "DisplayServer.get_display_safe_area()" + line.substr(end + start);
  1946. }
  1947. }
  1948. }
  1949. // draw_rect(a,b,c,d,e) -> draw_rect(a,b,c,d)#e) TODOConverter3To4 Antialiasing argument is missing
  1950. if (contains_function_call(line, "draw_rect(")) {
  1951. int start = line.find("draw_rect(");
  1952. int end = get_end_parenthesis(line.substr(start)) + 1;
  1953. if (end > -1) {
  1954. Vector<String> parts = parse_arguments(line.substr(start, end));
  1955. if (parts.size() == 5) {
  1956. 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";
  1957. }
  1958. }
  1959. }
  1960. // get_focus_owner() -> get_viewport().gui_get_focus_owner()
  1961. if (contains_function_call(line, "get_focus_owner()")) {
  1962. line = line.replace("get_focus_owner()", "get_viewport().gui_get_focus_owner()");
  1963. }
  1964. // button.pressed = 1 -> button.button_pressed = 1
  1965. if (line.contains(".pressed")) {
  1966. int start = line.find(".pressed");
  1967. bool foundNextEqual = false;
  1968. String line_to_check = line.substr(start + String(".pressed").length());
  1969. for (int current_index = 0; line_to_check.length() > current_index; current_index++) {
  1970. char32_t chr = line_to_check.get(current_index);
  1971. if (chr == '\t' || chr == ' ') {
  1972. continue;
  1973. } else if (chr == '=') {
  1974. foundNextEqual = true;
  1975. } else {
  1976. break;
  1977. }
  1978. }
  1979. if (foundNextEqual) {
  1980. line = line.substr(0, start) + ".button_pressed" + line.substr(start + String(".pressed").length());
  1981. }
  1982. }
  1983. // rotating = true -> ignore_rotation = false # reversed "rotating" for Camera2D
  1984. if (contains_function_call(line, "rotating")) {
  1985. String function_name = "rotating";
  1986. int start = line.find(function_name);
  1987. bool foundNextEqual = false;
  1988. String line_to_check = line.substr(start + function_name.length());
  1989. String assigned_value;
  1990. for (int current_index = 0; line_to_check.length() > current_index; current_index++) {
  1991. char32_t chr = line_to_check.get(current_index);
  1992. if (chr == '\t' || chr == ' ') {
  1993. continue;
  1994. } else if (chr == '=') {
  1995. foundNextEqual = true;
  1996. assigned_value = line.substr(start + function_name.length() + current_index + 1).strip_edges();
  1997. assigned_value = assigned_value == "true" ? "false" : "true";
  1998. } else {
  1999. break;
  2000. }
  2001. }
  2002. if (foundNextEqual) {
  2003. line = line.substr(0, start) + "ignore_rotation = " + assigned_value + " # reversed \"rotating\" for Camera2D";
  2004. }
  2005. }
  2006. // OS -> Time functions
  2007. if (line.contains("OS.get_ticks_msec")) {
  2008. line = line.replace("OS.get_ticks_msec", "Time.get_ticks_msec");
  2009. }
  2010. if (line.contains("OS.get_ticks_usec")) {
  2011. line = line.replace("OS.get_ticks_usec", "Time.get_ticks_usec");
  2012. }
  2013. if (line.contains("OS.get_unix_time")) {
  2014. line = line.replace("OS.get_unix_time", "Time.get_unix_time_from_system");
  2015. }
  2016. if (line.contains("OS.get_datetime")) {
  2017. line = line.replace("OS.get_datetime", "Time.get_datetime_dict_from_system");
  2018. }
  2019. // OS -> DisplayServer
  2020. if (line.contains("OS.get_display_cutouts")) {
  2021. line = line.replace("OS.get_display_cutouts", "DisplayServer.get_display_cutouts");
  2022. }
  2023. if (line.contains("OS.get_screen_count")) {
  2024. line = line.replace("OS.get_screen_count", "DisplayServer.get_screen_count");
  2025. }
  2026. if (line.contains("OS.get_screen_dpi")) {
  2027. line = line.replace("OS.get_screen_dpi", "DisplayServer.screen_get_dpi");
  2028. }
  2029. if (line.contains("OS.get_screen_max_scale")) {
  2030. line = line.replace("OS.get_screen_max_scale", "DisplayServer.screen_get_max_scale");
  2031. }
  2032. if (line.contains("OS.get_screen_position")) {
  2033. line = line.replace("OS.get_screen_position", "DisplayServer.screen_get_position");
  2034. }
  2035. if (line.contains("OS.get_screen_refresh_rate")) {
  2036. line = line.replace("OS.get_screen_refresh_rate", "DisplayServer.screen_get_refresh_rate");
  2037. }
  2038. if (line.contains("OS.get_screen_scale")) {
  2039. line = line.replace("OS.get_screen_scale", "DisplayServer.screen_get_scale");
  2040. }
  2041. if (line.contains("OS.get_screen_size")) {
  2042. line = line.replace("OS.get_screen_size", "DisplayServer.screen_get_size");
  2043. }
  2044. if (line.contains("OS.set_icon")) {
  2045. line = line.replace("OS.set_icon", "DisplayServer.set_icon");
  2046. }
  2047. if (line.contains("OS.set_native_icon")) {
  2048. line = line.replace("OS.set_native_icon", "DisplayServer.set_native_icon");
  2049. }
  2050. // OS -> Window
  2051. if (line.contains("OS.window_borderless")) {
  2052. line = line.replace("OS.window_borderless", "get_window().borderless");
  2053. }
  2054. if (line.contains("OS.get_real_window_size")) {
  2055. line = line.replace("OS.get_real_window_size", "get_window().get_size_with_decorations");
  2056. }
  2057. if (line.contains("OS.is_window_focused")) {
  2058. line = line.replace("OS.is_window_focused", "get_window().has_focus");
  2059. }
  2060. if (line.contains("OS.move_window_to_foreground")) {
  2061. line = line.replace("OS.move_window_to_foreground", "get_window().move_to_foreground");
  2062. }
  2063. if (line.contains("OS.request_attention")) {
  2064. line = line.replace("OS.request_attention", "get_window().request_attention");
  2065. }
  2066. if (line.contains("OS.set_window_title")) {
  2067. line = line.replace("OS.set_window_title", "get_window().set_title");
  2068. }
  2069. // get_tree().set_input_as_handled() -> get_viewport().set_input_as_handled()
  2070. if (line.contains("get_tree().set_input_as_handled()")) {
  2071. line = line.replace("get_tree().set_input_as_handled()", "get_viewport().set_input_as_handled()");
  2072. }
  2073. // Fix the simple case of using _unhandled_key_input
  2074. // func _unhandled_key_input(event: InputEventKey) -> _unhandled_key_input(event: InputEvent)
  2075. if (line.contains("_unhandled_key_input(event: InputEventKey)")) {
  2076. line = line.replace("_unhandled_key_input(event: InputEventKey)", "_unhandled_key_input(event: InputEvent)");
  2077. }
  2078. if (line.contains("Engine.editor_hint")) {
  2079. line = line.replace("Engine.editor_hint", "Engine.is_editor_hint()");
  2080. }
  2081. }
  2082. void ProjectConverter3To4::process_csharp_line(String &line, const RegExContainer &reg_container) {
  2083. line = line.replace("OS.GetWindowSafeArea()", "DisplayServer.ScreenGetUsableRect()");
  2084. // GetTree().SetInputAsHandled() -> GetViewport().SetInputAsHandled()
  2085. if (line.contains("GetTree().SetInputAsHandled()")) {
  2086. line = line.replace("GetTree().SetInputAsHandled()", "GetViewport().SetInputAsHandled()");
  2087. }
  2088. // Fix the simple case of using _UnhandledKeyInput
  2089. // func _UnhandledKeyInput(InputEventKey @event) -> _UnhandledKeyInput(InputEvent @event)
  2090. if (line.contains("_UnhandledKeyInput(InputEventKey @event)")) {
  2091. line = line.replace("_UnhandledKeyInput(InputEventKey @event)", "_UnhandledKeyInput(InputEvent @event)");
  2092. }
  2093. // -- Connect(,,,things) -> Connect(,Callable(,),things) Object
  2094. if (line.contains("Connect(")) {
  2095. int start = line.find("Connect(");
  2096. // Protection from disconnect
  2097. if (start == 0 || line.get(start - 1) != 's') {
  2098. int end = get_end_parenthesis(line.substr(start)) + 1;
  2099. if (end > -1) {
  2100. Vector<String> parts = parse_arguments(line.substr(start, end));
  2101. if (parts.size() >= 3) {
  2102. line = line.substr(0, start) + "Connect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);
  2103. }
  2104. }
  2105. }
  2106. }
  2107. // -- Disconnect(a,b,c) -> Disconnect(a,Callable(b,c)) Object
  2108. if (line.contains("Disconnect(")) {
  2109. int start = line.find("Disconnect(");
  2110. int end = get_end_parenthesis(line.substr(start)) + 1;
  2111. if (end > -1) {
  2112. Vector<String> parts = parse_arguments(line.substr(start, end));
  2113. if (parts.size() == 3) {
  2114. line = line.substr(0, start) + "Disconnect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  2115. }
  2116. }
  2117. }
  2118. // -- IsConnected(a,b,c) -> IsConnected(a,Callable(b,c)) Object
  2119. if (line.contains("IsConnected(")) {
  2120. int start = line.find("IsConnected(");
  2121. int end = get_end_parenthesis(line.substr(start)) + 1;
  2122. if (end > -1) {
  2123. Vector<String> parts = parse_arguments(line.substr(start, end));
  2124. if (parts.size() == 3) {
  2125. line = line.substr(0, start) + "IsConnected(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);
  2126. }
  2127. }
  2128. }
  2129. }
  2130. void ProjectConverter3To4::rename_csharp_functions(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2131. for (SourceLine &source_line : source_lines) {
  2132. if (source_line.is_comment) {
  2133. continue;
  2134. }
  2135. String &line = source_line.line;
  2136. if (uint64_t(line.length()) <= maximum_line_length) {
  2137. process_csharp_line(line, reg_container);
  2138. }
  2139. }
  2140. };
  2141. Vector<String> ProjectConverter3To4::check_for_rename_csharp_functions(Vector<String> &lines, const RegExContainer &reg_container) {
  2142. int current_line = 1;
  2143. Vector<String> found_renames;
  2144. for (String &line : lines) {
  2145. if (uint64_t(line.length()) <= maximum_line_length) {
  2146. String old_line = line;
  2147. process_csharp_line(line, reg_container);
  2148. if (old_line != line) {
  2149. found_renames.append(simple_line_formatter(current_line, old_line, line));
  2150. }
  2151. }
  2152. }
  2153. return found_renames;
  2154. }
  2155. void ProjectConverter3To4::rename_csharp_attributes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2156. 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";
  2157. for (SourceLine &source_line : source_lines) {
  2158. if (source_line.is_comment) {
  2159. continue;
  2160. }
  2161. String &line = source_line.line;
  2162. if (uint64_t(line.length()) <= maximum_line_length) {
  2163. line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);
  2164. line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);
  2165. line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);
  2166. line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);
  2167. line = reg_container.keyword_csharp_master.sub(line, error_message + "[RPC]", true);
  2168. line = reg_container.keyword_csharp_mastersync.sub(line, error_message + "[RPC(CallLocal = true)]", true);
  2169. }
  2170. }
  2171. }
  2172. Vector<String> ProjectConverter3To4::check_for_rename_csharp_attributes(Vector<String> &lines, const RegExContainer &reg_container) {
  2173. int current_line = 1;
  2174. Vector<String> found_renames;
  2175. for (String &line : lines) {
  2176. if (uint64_t(line.length()) <= maximum_line_length) {
  2177. String old;
  2178. old = line;
  2179. line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);
  2180. if (old != line) {
  2181. found_renames.append(line_formatter(current_line, "[Remote]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", line));
  2182. }
  2183. old = line;
  2184. line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);
  2185. if (old != line) {
  2186. found_renames.append(line_formatter(current_line, "[RemoteSync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", line));
  2187. }
  2188. old = line;
  2189. line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);
  2190. if (old != line) {
  2191. found_renames.append(line_formatter(current_line, "[Puppet]", "[RPC]", line));
  2192. }
  2193. old = line;
  2194. line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);
  2195. if (old != line) {
  2196. found_renames.append(line_formatter(current_line, "[PuppetSync]", "[RPC(CallLocal = true)]", line));
  2197. }
  2198. old = line;
  2199. line = reg_container.keyword_csharp_master.sub(line, "[RPC]", true);
  2200. if (old != line) {
  2201. found_renames.append(line_formatter(current_line, "[Master]", "[RPC]", line));
  2202. }
  2203. old = line;
  2204. line = reg_container.keyword_csharp_mastersync.sub(line, "[RPC(CallLocal = true)]", true);
  2205. if (old != line) {
  2206. found_renames.append(line_formatter(current_line, "[MasterSync]", "[RPC(CallLocal = true)]", line));
  2207. }
  2208. }
  2209. current_line++;
  2210. }
  2211. return found_renames;
  2212. }
  2213. _FORCE_INLINE_ static String builtin_escape(const String &p_str, bool p_builtin) {
  2214. if (p_builtin) {
  2215. return p_str.replace("\"", "\\\"");
  2216. } else {
  2217. return p_str;
  2218. }
  2219. }
  2220. void ProjectConverter3To4::rename_gdscript_keywords(Vector<SourceLine> &source_lines, const RegExContainer &reg_container, bool builtin) {
  2221. 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";
  2222. for (SourceLine &source_line : source_lines) {
  2223. if (source_line.is_comment) {
  2224. continue;
  2225. }
  2226. String &line = source_line.line;
  2227. if (uint64_t(line.length()) <= maximum_line_length) {
  2228. if (line.contains("export")) {
  2229. line = reg_container.keyword_gdscript_export_single.sub(line, "@export", true);
  2230. }
  2231. if (line.contains("export")) {
  2232. line = reg_container.keyword_gdscript_export_mutli.sub(line, "$1@export", true);
  2233. }
  2234. if (line.contains("onready")) {
  2235. line = reg_container.keyword_gdscript_onready.sub(line, "@onready", true);
  2236. }
  2237. if (line.contains("remote")) {
  2238. line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);
  2239. }
  2240. if (line.contains("remote")) {
  2241. line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);
  2242. }
  2243. if (line.contains("sync")) {
  2244. line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);
  2245. }
  2246. if (line.contains("slave")) {
  2247. line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);
  2248. }
  2249. if (line.contains("puppet")) {
  2250. line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);
  2251. }
  2252. if (line.contains("puppet")) {
  2253. line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2254. }
  2255. if (line.contains("master")) {
  2256. line = reg_container.keyword_gdscript_master.sub(line, error_message + "@rpc func", true);
  2257. }
  2258. if (line.contains("master")) {
  2259. line = reg_container.keyword_gdscript_mastersync.sub(line, error_message + builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2260. }
  2261. }
  2262. }
  2263. }
  2264. Vector<String> ProjectConverter3To4::check_for_rename_gdscript_keywords(Vector<String> &lines, const RegExContainer &reg_container, bool builtin) {
  2265. Vector<String> found_renames;
  2266. int current_line = 1;
  2267. for (String &line : lines) {
  2268. if (uint64_t(line.length()) <= maximum_line_length) {
  2269. String old;
  2270. if (line.contains("tool")) {
  2271. old = line;
  2272. line = reg_container.keyword_gdscript_tool.sub(line, "@tool", true);
  2273. if (old != line) {
  2274. found_renames.append(line_formatter(current_line, "tool", "@tool", line));
  2275. }
  2276. }
  2277. if (line.contains("export")) {
  2278. old = line;
  2279. line = reg_container.keyword_gdscript_export_single.sub(line, "$1@export", true);
  2280. if (old != line) {
  2281. found_renames.append(line_formatter(current_line, "export", "@export", line));
  2282. }
  2283. }
  2284. if (line.contains("export")) {
  2285. old = line;
  2286. line = reg_container.keyword_gdscript_export_mutli.sub(line, "@export", true);
  2287. if (old != line) {
  2288. found_renames.append(line_formatter(current_line, "export", "@export", line));
  2289. }
  2290. }
  2291. if (line.contains("onready")) {
  2292. old = line;
  2293. line = reg_container.keyword_gdscript_tool.sub(line, "@onready", true);
  2294. if (old != line) {
  2295. found_renames.append(line_formatter(current_line, "onready", "@onready", line));
  2296. }
  2297. }
  2298. if (line.contains("remote")) {
  2299. old = line;
  2300. line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);
  2301. if (old != line) {
  2302. found_renames.append(line_formatter(current_line, "remote func", builtin_escape("@rpc(\"any_peer\") func", builtin), line));
  2303. }
  2304. }
  2305. if (line.contains("remote")) {
  2306. old = line;
  2307. line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);
  2308. if (old != line) {
  2309. found_renames.append(line_formatter(current_line, "remotesync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));
  2310. }
  2311. }
  2312. if (line.contains("sync")) {
  2313. old = line;
  2314. line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);
  2315. if (old != line) {
  2316. found_renames.append(line_formatter(current_line, "sync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));
  2317. }
  2318. }
  2319. if (line.contains("slave")) {
  2320. old = line;
  2321. line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);
  2322. if (old != line) {
  2323. found_renames.append(line_formatter(current_line, "slave func", "@rpc func", line));
  2324. }
  2325. }
  2326. if (line.contains("puppet")) {
  2327. old = line;
  2328. line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);
  2329. if (old != line) {
  2330. found_renames.append(line_formatter(current_line, "puppet func", "@rpc func", line));
  2331. }
  2332. }
  2333. if (line.contains("puppet")) {
  2334. old = line;
  2335. line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2336. if (old != line) {
  2337. found_renames.append(line_formatter(current_line, "puppetsync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));
  2338. }
  2339. }
  2340. if (line.contains("master")) {
  2341. old = line;
  2342. line = reg_container.keyword_gdscript_master.sub(line, "@rpc func", true);
  2343. if (old != line) {
  2344. found_renames.append(line_formatter(current_line, "master func", "@rpc func", line));
  2345. }
  2346. }
  2347. if (line.contains("master")) {
  2348. old = line;
  2349. line = reg_container.keyword_gdscript_master.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);
  2350. if (old != line) {
  2351. found_renames.append(line_formatter(current_line, "mastersync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));
  2352. }
  2353. }
  2354. }
  2355. current_line++;
  2356. }
  2357. return found_renames;
  2358. }
  2359. void ProjectConverter3To4::rename_input_map_scancode(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2360. // The old Special Key, now colliding with CMD_OR_CTRL.
  2361. const int old_spkey = (1 << 24);
  2362. for (SourceLine &source_line : source_lines) {
  2363. if (source_line.is_comment) {
  2364. continue;
  2365. }
  2366. String &line = source_line.line;
  2367. if (uint64_t(line.length()) <= maximum_line_length) {
  2368. TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
  2369. for (int i = 0; i < reg_match.size(); ++i) {
  2370. Ref<RegExMatch> match = reg_match[i];
  2371. PackedStringArray strings = match->get_strings();
  2372. int key = strings[3].to_int();
  2373. if (key & old_spkey) {
  2374. // Create new key, clearing old Special Key and setting new one.
  2375. key = (key & ~old_spkey) | (int)Key::SPECIAL;
  2376. line = line.replace(strings[0], String(",\"") + strings[1] + "scancode\":" + String::num_int64(key));
  2377. }
  2378. }
  2379. }
  2380. }
  2381. }
  2382. void ProjectConverter3To4::rename_joypad_buttons_and_axes(Vector<SourceLine> &source_lines, const RegExContainer &reg_container) {
  2383. for (SourceLine &source_line : source_lines) {
  2384. if (source_line.is_comment) {
  2385. continue;
  2386. }
  2387. String &line = source_line.line;
  2388. if (uint64_t(line.length()) <= maximum_line_length) {
  2389. // Remap button indexes.
  2390. TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);
  2391. for (int i = 0; i < reg_match.size(); ++i) {
  2392. Ref<RegExMatch> match = reg_match[i];
  2393. PackedStringArray strings = match->get_strings();
  2394. String button_index_entry = strings[0];
  2395. int button_index_value = strings[1].to_int();
  2396. if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.
  2397. line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");
  2398. line = line.replace(button_index_entry, ",\"axis\":4,\"axis_value\":1.0");
  2399. } else if (button_index_value == 7) {
  2400. line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");
  2401. line = line.replace(button_index_entry, ",\"axis\":5,\"axis_value\":1.0");
  2402. } else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.
  2403. String pressure_and_pressed_properties = strings[2];
  2404. line = line.replace(button_index_entry, ",\"button_index\":" + String::num_int64(reg_container.joypad_button_mappings[button_index_value]) + "," + pressure_and_pressed_properties);
  2405. }
  2406. }
  2407. // Remap axes. Only L2 and R2 need remapping.
  2408. reg_match = reg_container.joypad_axis.search_all(line);
  2409. for (int i = 0; i < reg_match.size(); ++i) {
  2410. Ref<RegExMatch> match = reg_match[i];
  2411. PackedStringArray strings = match->get_strings();
  2412. String axis_entry = strings[0];
  2413. int axis_value = strings[1].to_int();
  2414. if (axis_value == 6) {
  2415. line = line.replace(axis_entry, ",\"axis\":4");
  2416. } else if (axis_value == 7) {
  2417. line = line.replace(axis_entry, ",\"axis\":5");
  2418. }
  2419. }
  2420. }
  2421. }
  2422. }
  2423. Vector<String> ProjectConverter3To4::check_for_rename_joypad_buttons_and_axes(Vector<String> &lines, const RegExContainer &reg_container) {
  2424. Vector<String> found_renames;
  2425. int current_line = 1;
  2426. for (String &line : lines) {
  2427. if (uint64_t(line.length()) <= maximum_line_length) {
  2428. // Remap button indexes.
  2429. TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);
  2430. for (int i = 0; i < reg_match.size(); ++i) {
  2431. Ref<RegExMatch> match = reg_match[i];
  2432. PackedStringArray strings = match->get_strings();
  2433. String button_index_entry = strings[0];
  2434. int button_index_value = strings[1].to_int();
  2435. if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.
  2436. found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));
  2437. found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":4", line));
  2438. } else if (button_index_value == 7) {
  2439. found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));
  2440. found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":5", line));
  2441. } else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.
  2442. 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));
  2443. }
  2444. }
  2445. // Remap axes. Only L2 and R2 need remapping.
  2446. reg_match = reg_container.joypad_axis.search_all(line);
  2447. for (int i = 0; i < reg_match.size(); ++i) {
  2448. Ref<RegExMatch> match = reg_match[i];
  2449. PackedStringArray strings = match->get_strings();
  2450. String axis_entry = strings[0];
  2451. int axis_value = strings[1].to_int();
  2452. if (axis_value == 6) {
  2453. found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":4", line));
  2454. } else if (axis_value == 7) {
  2455. found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":5", line));
  2456. }
  2457. }
  2458. current_line++;
  2459. }
  2460. }
  2461. return found_renames;
  2462. }
  2463. Vector<String> ProjectConverter3To4::check_for_rename_input_map_scancode(Vector<String> &lines, const RegExContainer &reg_container) {
  2464. Vector<String> found_renames;
  2465. // The old Special Key, now colliding with CMD_OR_CTRL.
  2466. const int old_spkey = (1 << 24);
  2467. int current_line = 1;
  2468. for (String &line : lines) {
  2469. if (uint64_t(line.length()) <= maximum_line_length) {
  2470. TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
  2471. for (int i = 0; i < reg_match.size(); ++i) {
  2472. Ref<RegExMatch> match = reg_match[i];
  2473. PackedStringArray strings = match->get_strings();
  2474. int key = strings[3].to_int();
  2475. if (key & old_spkey) {
  2476. // Create new key, clearing old Special Key and setting new one.
  2477. key = (key & ~old_spkey) | (int)Key::SPECIAL;
  2478. found_renames.append(line_formatter(current_line, strings[3], String::num_int64(key), line));
  2479. }
  2480. }
  2481. }
  2482. current_line++;
  2483. }
  2484. return found_renames;
  2485. }
  2486. void ProjectConverter3To4::custom_rename(Vector<SourceLine> &source_lines, String from, String to) {
  2487. RegEx reg = RegEx(String("\\b") + from + "\\b");
  2488. CRASH_COND(!reg.is_valid());
  2489. for (SourceLine &source_line : source_lines) {
  2490. if (source_line.is_comment) {
  2491. continue;
  2492. }
  2493. String &line = source_line.line;
  2494. if (uint64_t(line.length()) <= maximum_line_length) {
  2495. line = reg.sub(line, to, true);
  2496. }
  2497. }
  2498. };
  2499. Vector<String> ProjectConverter3To4::check_for_custom_rename(Vector<String> &lines, String from, String to) {
  2500. Vector<String> found_renames;
  2501. RegEx reg = RegEx(String("\\b") + from + "\\b");
  2502. CRASH_COND(!reg.is_valid());
  2503. int current_line = 1;
  2504. for (String &line : lines) {
  2505. if (uint64_t(line.length()) <= maximum_line_length) {
  2506. TypedArray<RegExMatch> reg_match = reg.search_all(line);
  2507. if (reg_match.size() > 0) {
  2508. found_renames.append(line_formatter(current_line, from.replace("\\.", "."), to, line)); // Without replacing it will print "\.shader" instead ".shader".
  2509. }
  2510. }
  2511. current_line++;
  2512. }
  2513. return found_renames;
  2514. }
  2515. void ProjectConverter3To4::rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<SourceLine> &source_lines) {
  2516. for (SourceLine &source_line : source_lines) {
  2517. if (source_line.is_comment) {
  2518. continue;
  2519. }
  2520. String &line = source_line.line;
  2521. if (uint64_t(line.length()) <= maximum_line_length) {
  2522. for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {
  2523. if (line.contains(array[current_index][0])) {
  2524. line = cached_regexes[current_index]->sub(line, array[current_index][1], true);
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. Vector<String> ProjectConverter3To4::check_for_rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<String> &lines) {
  2531. Vector<String> found_renames;
  2532. int current_line = 1;
  2533. for (String &line : lines) {
  2534. if (uint64_t(line.length()) <= maximum_line_length) {
  2535. for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {
  2536. if (line.contains(array[current_index][0])) {
  2537. TypedArray<RegExMatch> reg_match = cached_regexes[current_index]->search_all(line);
  2538. if (reg_match.size() > 0) {
  2539. found_renames.append(line_formatter(current_line, array[current_index][0], array[current_index][1], line));
  2540. }
  2541. }
  2542. }
  2543. }
  2544. current_line++;
  2545. }
  2546. return found_renames;
  2547. }
  2548. // Prints full info about renamed things e.g.:
  2549. // Line (67) remove -> remove_at - LINE """ doubler._blacklist.remove(0) """
  2550. String ProjectConverter3To4::line_formatter(int current_line, String from, String to, String line) {
  2551. if (from.size() > 200) {
  2552. from = from.substr(0, 197) + "...";
  2553. }
  2554. if (to.size() > 200) {
  2555. to = to.substr(0, 197) + "...";
  2556. }
  2557. if (line.size() > 400) {
  2558. line = line.substr(0, 397) + "...";
  2559. }
  2560. from = from.strip_escapes();
  2561. to = to.strip_escapes();
  2562. line = line.replace("\r", "").replace("\n", "").strip_edges();
  2563. return vformat("Line(%d), %s -> %s - LINE \"\"\" %s \"\"\"", current_line, from, to, line);
  2564. }
  2565. // Prints only full lines e.g.:
  2566. // Line (1) - FULL LINES - """yield(get_tree().create_timer(3), 'timeout')""" =====> """ await get_tree().create_timer(3).timeout """
  2567. String ProjectConverter3To4::simple_line_formatter(int current_line, String old_line, String new_line) {
  2568. if (old_line.size() > 1000) {
  2569. old_line = old_line.substr(0, 997) + "...";
  2570. }
  2571. if (new_line.size() > 1000) {
  2572. new_line = new_line.substr(0, 997) + "...";
  2573. }
  2574. old_line = old_line.replace("\r", "").replace("\n", "").strip_edges();
  2575. new_line = new_line.replace("\r", "").replace("\n", "").strip_edges();
  2576. return vformat("Line (%d) - FULL LINES - \"\"\" %s \"\"\" =====> \"\"\" %s \"\"\"", current_line, old_line, new_line);
  2577. }
  2578. // Collects string from vector strings
  2579. String ProjectConverter3To4::collect_string_from_vector(Vector<SourceLine> &vector) {
  2580. String string = "";
  2581. for (int i = 0; i < vector.size(); i++) {
  2582. string += vector[i].line;
  2583. if (i != vector.size() - 1) {
  2584. string += "\n";
  2585. }
  2586. }
  2587. return string;
  2588. }
  2589. #endif // MODULE_REGEX_ENABLED
  2590. #endif // DISABLE_DEPRECATED