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