Path: blob/master/editor/project_upgrade/project_converter_3_to_4.cpp
9896 views
/**************************************************************************/1/* project_converter_3_to_4.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "project_converter_3_to_4.h"3132#ifndef DISABLE_DEPRECATED3334#include "core/error/error_macros.h"35#include "core/io/dir_access.h"36#include "core/io/file_access.h"37#include "core/object/ref_counted.h"38#include "core/os/time.h"39#include "core/templates/list.h"40#include "editor/project_upgrade/renames_map_3_to_4.h"4142#include "modules/regex/regex.h"4344// Find "OS.set_property(x)", capturing x into $1.45static String make_regex_gds_os_property_set(const String &name_set) {46return String("\\bOS\\.") + name_set + "\\s*\\((.*)\\)";47}48// Find "OS.property = x", capturing x into $1 or $2.49static String make_regex_gds_os_property_assign(const String &name) {50return String("\\bOS\\.") + name + "\\s*=\\s*([^#]+)";51}52// Find "OS.property" OR "OS.get_property()" / "OS.is_property()".53static String make_regex_gds_os_property_get(const String &name, const String &get) {54return String("\\bOS\\.(") + get + "_)?" + name + "(\\s*\\(\\s*\\))?";55}5657class ProjectConverter3To4::RegExContainer {58public:59// Custom GDScript.60RegEx reg_is_empty = RegEx("\\bempty\\(");61RegEx reg_super = RegEx("([\t ])\\.([a-zA-Z_])");62RegEx reg_json_to = RegEx("\\bto_json\\b");63RegEx reg_json_parse = RegEx("([\t ]{0,})([^\n]+)parse_json\\(([^\n]+)");64RegEx reg_json_non_new = RegEx("([\t ]{0,})([^\n]+)JSON\\.parse\\(([^\n]+)");65RegEx reg_json_print = RegEx("\\bJSON\\b\\.print\\(");66RegEx reg_export_simple = RegEx("export[ ]*\\(([a-zA-Z0-9_]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)");67RegEx reg_export_typed = RegEx("export[ ]*\\(([a-zA-Z0-9_]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)[ ]*:[ ]*[a-zA-Z0-9_]+");68RegEx reg_export_inferred_type = RegEx("export[ ]*\\([a-zA-Z0-9_]+\\)[ ]*var[ ]+([a-zA-Z0-9_]+)[ ]*:[ ]*=");69RegEx reg_export_advanced = RegEx("export[ ]*\\(([^)^\n]+)\\)[ ]*var[ ]+([a-zA-Z0-9_]+)([^\n]+)");70RegEx reg_setget_setget = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+([a-zA-Z0-9_]+)[ \t]*,[ \t]*([a-zA-Z0-9_]+)");71RegEx reg_setget_set = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+([a-zA-Z0-9_]+)[ \t]*[,]*[^\n]*$");72RegEx reg_setget_get = RegEx("var[ ]+([a-zA-Z0-9_]+)([^\n]+?)[ \t]*setget[ \t]+,[ \t]*([a-zA-Z0-9_]+)[ \t]*$");73RegEx reg_join = RegEx("([\\(\\)a-zA-Z0-9_]+)\\.join\\(([^\n^\\)]+)\\)");74RegEx reg_image_lock = RegEx("([a-zA-Z0-9_\\.]+)\\.lock\\(\\)");75RegEx reg_image_unlock = RegEx("([a-zA-Z0-9_\\.]+)\\.unlock\\(\\)");76RegEx reg_instantiate = RegEx("\\.instance\\(([^\\)]*)\\)");77// Simple OS properties with getters/setters.78RegEx reg_os_current_screen = RegEx("\\bOS\\.((set_|get_)?)current_screen\\b");79RegEx reg_os_min_window_size = RegEx("\\bOS\\.((set_|get_)?)min_window_size\\b");80RegEx reg_os_max_window_size = RegEx("\\bOS\\.((set_|get_)?)max_window_size\\b");81RegEx reg_os_window_position = RegEx("\\bOS\\.((set_|get_)?)window_position\\b");82RegEx reg_os_window_size = RegEx("\\bOS\\.((set_|get_)?)window_size\\b");83RegEx reg_os_getset_screen_orient = RegEx("\\bOS\\.(s|g)et_screen_orientation\\b");84// OS property getters/setters for non trivial replacements.85RegEx reg_os_set_window_resizable = RegEx(make_regex_gds_os_property_set("set_window_resizable"));86RegEx reg_os_assign_window_resizable = RegEx(make_regex_gds_os_property_assign("window_resizable"));87RegEx reg_os_is_window_resizable = RegEx(make_regex_gds_os_property_get("window_resizable", "is"));88RegEx reg_os_set_fullscreen = RegEx(make_regex_gds_os_property_set("set_window_fullscreen"));89RegEx reg_os_assign_fullscreen = RegEx(make_regex_gds_os_property_assign("window_fullscreen"));90RegEx reg_os_is_fullscreen = RegEx(make_regex_gds_os_property_get("window_fullscreen", "is"));91RegEx reg_os_set_maximized = RegEx(make_regex_gds_os_property_set("set_window_maximized"));92RegEx reg_os_assign_maximized = RegEx(make_regex_gds_os_property_assign("window_maximized"));93RegEx reg_os_is_maximized = RegEx(make_regex_gds_os_property_get("window_maximized", "is"));94RegEx reg_os_set_minimized = RegEx(make_regex_gds_os_property_set("set_window_minimized"));95RegEx reg_os_assign_minimized = RegEx(make_regex_gds_os_property_assign("window_minimized"));96RegEx reg_os_is_minimized = RegEx(make_regex_gds_os_property_get("window_minimized", "is"));97RegEx reg_os_set_vsync = RegEx(make_regex_gds_os_property_set("set_use_vsync"));98RegEx reg_os_assign_vsync = RegEx(make_regex_gds_os_property_assign("vsync_enabled"));99RegEx reg_os_is_vsync = RegEx(make_regex_gds_os_property_get("vsync_enabled", "is"));100// OS properties specific cases & specific replacements.101RegEx reg_os_assign_screen_orient = RegEx("^(\\s*)OS\\.screen_orientation\\s*=\\s*([^#]+)"); // $1 - indent, $2 - value102RegEx reg_os_set_always_on_top = RegEx(make_regex_gds_os_property_set("set_window_always_on_top"));103RegEx reg_os_is_always_on_top = RegEx("\\bOS\\.is_window_always_on_top\\s*\\(.*\\)");104RegEx reg_os_set_borderless = RegEx(make_regex_gds_os_property_set("set_borderless_window"));105RegEx reg_os_get_borderless = RegEx("\\bOS\\.get_borderless_window\\s*\\(\\s*\\)");106RegEx reg_os_screen_orient_enum = RegEx("\\bOS\\.SCREEN_ORIENTATION_(\\w+)\\b"); // $1 - constant suffix107108// GDScript keywords.109RegEx keyword_gdscript_tool = RegEx("^tool");110RegEx keyword_gdscript_export_single = RegEx("^export");111RegEx keyword_gdscript_export_multi = RegEx("([\t]+)export\\b");112RegEx keyword_gdscript_onready = RegEx("^onready");113RegEx keyword_gdscript_remote = RegEx("^remote func");114RegEx keyword_gdscript_remotesync = RegEx("^remotesync func");115RegEx keyword_gdscript_sync = RegEx("^sync func");116RegEx keyword_gdscript_slave = RegEx("^slave func");117RegEx keyword_gdscript_puppet = RegEx("^puppet func");118RegEx keyword_gdscript_puppetsync = RegEx("^puppetsync func");119RegEx keyword_gdscript_master = RegEx("^master func");120RegEx keyword_gdscript_mastersync = RegEx("^mastersync func");121122RegEx gdscript_comment = RegEx("^\\s*#");123RegEx csharp_comment = RegEx("^\\s*\\/\\/");124125// CSharp keywords.126RegEx keyword_csharp_remote = RegEx("\\[Remote(Attribute)?(\\(\\))?\\]");127RegEx keyword_csharp_remotesync = RegEx("\\[(Remote)?Sync(Attribute)?(\\(\\))?\\]");128RegEx keyword_csharp_puppet = RegEx("\\[(Puppet|Slave)(Attribute)?(\\(\\))?\\]");129RegEx keyword_csharp_puppetsync = RegEx("\\[PuppetSync(Attribute)?(\\(\\))?\\]");130RegEx keyword_csharp_master = RegEx("\\[Master(Attribute)?(\\(\\))?\\]");131RegEx keyword_csharp_mastersync = RegEx("\\[MasterSync(Attribute)?(\\(\\))?\\]");132133// Colors.134LocalVector<RegEx *> color_regexes;135LocalVector<String> color_renamed;136137RegEx color_hexadecimal_short_constructor = RegEx("Color\\(\"#?([a-fA-F0-9]{1})([a-fA-F0-9]{3})\\b");138RegEx color_hexadecimal_full_constructor = RegEx("Color\\(\"#?([a-fA-F0-9]{2})([a-fA-F0-9]{6})\\b");139140// Classes.141LocalVector<RegEx *> class_tscn_regexes;142LocalVector<RegEx *> class_gd_regexes;143LocalVector<RegEx *> class_shader_regexes;144145// Keycode.146RegEx input_map_keycode = RegEx("\\b,\"((physical_)?)scancode\":(\\d+)\\b");147148// Button index and joypad axis.149RegEx joypad_button_index = RegEx("\\b,\"button_index\":(\\d+),(\"pressure\":\\d+\\.\\d+,\"pressed\":(false|true))\\b");150RegEx joypad_axis = RegEx("\\b,\"axis\":(\\d+)\\b");151152// Index represents Godot 3's value, entry represents Godot 4 value equivalency.153// i.e: Button4(L1 - Godot3) -> joypad_button_mappings[4]=9 -> Button9(L1 - Godot4).154int 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 };155// Entries for L2 and R2 are -1 since they match to joypad axes and no longer to joypad buttons in Godot 4.156157LocalVector<RegEx *> class_regexes;158159RegEx class_temp_tscn = RegEx("\\bTEMP_RENAMED_CLASS.tscn\\b");160RegEx class_temp_gd = RegEx("\\bTEMP_RENAMED_CLASS.gd\\b");161RegEx class_temp_shader = RegEx("\\bTEMP_RENAMED_CLASS.shader\\b");162163LocalVector<String> class_temp_tscn_renames;164LocalVector<String> class_temp_gd_renames;165LocalVector<String> class_temp_shader_renames;166167// Common.168LocalVector<RegEx *> enum_regexes;169LocalVector<RegEx *> gdscript_function_regexes;170LocalVector<RegEx *> project_settings_regexes;171LocalVector<RegEx *> project_godot_regexes;172LocalVector<RegEx *> input_map_regexes;173LocalVector<RegEx *> gdscript_properties_regexes;174LocalVector<RegEx *> gdscript_signals_regexes;175LocalVector<RegEx *> shaders_regexes;176LocalVector<RegEx *> builtin_types_regexes;177LocalVector<RegEx *> theme_override_regexes;178LocalVector<RegEx *> csharp_function_regexes;179LocalVector<RegEx *> csharp_properties_regexes;180LocalVector<RegEx *> csharp_signal_regexes;181182RegExContainer() {183// Common.184{185// Enum.186for (unsigned int current_index = 0; RenamesMap3To4::enum_renames[current_index][0]; current_index++) {187enum_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::enum_renames[current_index][0] + "\\b")));188}189// GDScript functions.190for (unsigned int current_index = 0; RenamesMap3To4::gdscript_function_renames[current_index][0]; current_index++) {191gdscript_function_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_function_renames[current_index][0] + "\\b")));192}193// Project Settings in scripts.194for (unsigned int current_index = 0; RenamesMap3To4::project_settings_renames[current_index][0]; current_index++) {195project_settings_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::project_settings_renames[current_index][0] + "\\b")));196}197// Project Settings in project.godot.198for (unsigned int current_index = 0; RenamesMap3To4::project_godot_renames[current_index][0]; current_index++) {199project_godot_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::project_godot_renames[current_index][0] + "\\b")));200}201// Input Map.202for (unsigned int current_index = 0; RenamesMap3To4::input_map_renames[current_index][0]; current_index++) {203input_map_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::input_map_renames[current_index][0] + "\\b")));204}205// GDScript properties.206for (unsigned int current_index = 0; RenamesMap3To4::gdscript_properties_renames[current_index][0]; current_index++) {207gdscript_properties_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_properties_renames[current_index][0] + "\\b")));208}209// GDScript Signals.210for (unsigned int current_index = 0; RenamesMap3To4::gdscript_signals_renames[current_index][0]; current_index++) {211gdscript_signals_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::gdscript_signals_renames[current_index][0] + "\\b")));212}213// Shaders.214for (unsigned int current_index = 0; RenamesMap3To4::shaders_renames[current_index][0]; current_index++) {215shaders_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::shaders_renames[current_index][0] + "\\b")));216}217// Builtin types.218for (unsigned int current_index = 0; RenamesMap3To4::builtin_types_renames[current_index][0]; current_index++) {219builtin_types_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::builtin_types_renames[current_index][0] + "\\b")));220}221// Theme overrides.222for (unsigned int current_index = 0; RenamesMap3To4::theme_override_renames[current_index][0]; current_index++) {223theme_override_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::theme_override_renames[current_index][0] + "\\b")));224}225// CSharp function renames.226for (unsigned int current_index = 0; RenamesMap3To4::csharp_function_renames[current_index][0]; current_index++) {227csharp_function_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_function_renames[current_index][0] + "\\b")));228}229// CSharp properties renames.230for (unsigned int current_index = 0; RenamesMap3To4::csharp_properties_renames[current_index][0]; current_index++) {231csharp_properties_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_properties_renames[current_index][0] + "\\b")));232}233// CSharp signals renames.234for (unsigned int current_index = 0; RenamesMap3To4::csharp_signals_renames[current_index][0]; current_index++) {235csharp_signal_regexes.push_back(memnew(RegEx(String("\\b") + RenamesMap3To4::csharp_signals_renames[current_index][0] + "\\b")));236}237}238239// Colors.240{241for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {242color_regexes.push_back(memnew(RegEx(String("\\bColor.") + RenamesMap3To4::color_renames[current_index][0] + "\\b")));243color_renamed.push_back(String("Color.") + RenamesMap3To4::color_renames[current_index][1]);244}245}246// Classes.247{248for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {249const String class_name = RenamesMap3To4::class_renames[current_index][0];250class_tscn_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".tscn\\b")));251class_gd_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".gd\\b")));252class_shader_regexes.push_back(memnew(RegEx(String("\\b") + class_name + ".shader\\b")));253254class_regexes.push_back(memnew(RegEx(String("\\b") + class_name + "\\b")));255256class_temp_tscn_renames.push_back(class_name + ".tscn");257class_temp_gd_renames.push_back(class_name + ".gd");258class_temp_shader_renames.push_back(class_name + ".shader");259}260}261}262~RegExContainer() {263for (RegEx *regex : color_regexes) {264memdelete(regex);265}266for (unsigned int i = 0; i < class_tscn_regexes.size(); i++) {267memdelete(class_tscn_regexes[i]);268memdelete(class_gd_regexes[i]);269memdelete(class_shader_regexes[i]);270memdelete(class_regexes[i]);271}272for (RegEx *regex : enum_regexes) {273memdelete(regex);274}275for (RegEx *regex : gdscript_function_regexes) {276memdelete(regex);277}278for (RegEx *regex : project_settings_regexes) {279memdelete(regex);280}281for (RegEx *regex : project_godot_regexes) {282memdelete(regex);283}284for (RegEx *regex : input_map_regexes) {285memdelete(regex);286}287for (RegEx *regex : gdscript_properties_regexes) {288memdelete(regex);289}290for (RegEx *regex : gdscript_signals_regexes) {291memdelete(regex);292}293for (RegEx *regex : shaders_regexes) {294memdelete(regex);295}296for (RegEx *regex : builtin_types_regexes) {297memdelete(regex);298}299for (RegEx *regex : theme_override_regexes) {300memdelete(regex);301}302for (RegEx *regex : csharp_function_regexes) {303memdelete(regex);304}305for (RegEx *regex : csharp_properties_regexes) {306memdelete(regex);307}308for (RegEx *regex : csharp_signal_regexes) {309memdelete(regex);310}311}312};313314ProjectConverter3To4::ProjectConverter3To4(int p_maximum_file_size_kb, int p_maximum_line_length) {315maximum_file_size = p_maximum_file_size_kb * 1024;316maximum_line_length = p_maximum_line_length;317}318319// Function responsible for converting project.320bool ProjectConverter3To4::convert() {321print_line("Starting conversion.");322uint64_t conversion_start_time = Time::get_singleton()->get_ticks_msec();323324RegExContainer reg_container = RegExContainer();325326int cached_maximum_line_length = maximum_line_length;327maximum_line_length = 10000; // Use only for tests bigger value, to not break them.328329ERR_FAIL_COND_V_MSG(!test_array_names(), false, "Cannot start converting due to problems with data in arrays.");330ERR_FAIL_COND_V_MSG(!test_conversion(reg_container), false, "Aborting conversion due to validation tests failing");331332maximum_line_length = cached_maximum_line_length;333334// Checking if folder contains valid Godot 3 project.335// Project should not be converted more than once.336{337String converter_text = "; Project was converted by built-in tool to Godot 4";338339ERR_FAIL_COND_V_MSG(!FileAccess::exists("project.godot"), false, "Current working directory doesn't contain a \"project.godot\" file for a Godot 3 project.");340341Error err = OK;342String project_godot_content = FileAccess::get_file_as_string("project.godot", &err);343344ERR_FAIL_COND_V_MSG(err != OK, false, "Unable to read \"project.godot\".");345ERR_FAIL_COND_V_MSG(project_godot_content.contains(converter_text), false, "Project was already converted with this tool.");346347Ref<FileAccess> file = FileAccess::open("project.godot", FileAccess::WRITE);348ERR_FAIL_COND_V_MSG(file.is_null(), false, "Unable to open \"project.godot\".");349350file->store_string(converter_text + "\n" + project_godot_content);351}352353Vector<String> collected_files = check_for_files();354355uint32_t converted_files = 0;356357// Check file by file.358for (int i = 0; i < collected_files.size(); i++) {359String file_name = collected_files[i];360Vector<SourceLine> source_lines;361uint32_t ignored_lines = 0;362{363Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::READ);364ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to read content of \"%s\".", file_name));365while (!file->eof_reached()) {366String line = file->get_line();367368SourceLine source_line;369source_line.line = line;370source_line.is_comment = reg_container.gdscript_comment.search_all(line).size() > 0 || reg_container.csharp_comment.search_all(line).size() > 0;371source_lines.append(source_line);372}373}374String file_content_before = collect_string_from_vector(source_lines);375uint64_t hash_before = file_content_before.hash();376uint64_t file_size = file_content_before.size();377print_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));378379Vector<String> reason;380bool is_ignored = false;381uint64_t start_time = Time::get_singleton()->get_ticks_msec();382383if (file_name.ends_with(".shader")) {384DirAccess::remove_file_or_error(file_name.trim_prefix("res://"));385file_name = file_name.replace(".shader", ".gdshader");386}387388if (file_size < uint64_t(maximum_file_size)) {389// ".tscn" must work exactly the same as ".gd" files because they may contain built-in Scripts.390if (file_name.ends_with(".gd")) {391fix_tool_declaration(source_lines, reg_container);392393rename_classes(source_lines, reg_container); // Using only specialized function.394395rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, source_lines);396rename_colors(source_lines, reg_container); // Require to additional rename.397398rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, source_lines);399rename_gdscript_functions(source_lines, reg_container, false); // Require to additional rename.400401rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, source_lines);402rename_gdscript_keywords(source_lines, reg_container, false);403rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, source_lines);404rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);405rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);406rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);407rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);408409custom_rename(source_lines, "\\.shader", ".gdshader");410411convert_hexadecimal_colors(source_lines, reg_container);412} else if (file_name.ends_with(".tscn")) {413fix_pause_mode(source_lines, reg_container);414415rename_classes(source_lines, reg_container); // Using only specialized function.416417rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, source_lines);418rename_colors(source_lines, reg_container); // Require to do additional renames.419420rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, source_lines);421rename_gdscript_functions(source_lines, reg_container, true); // Require to do additional renames.422423rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, source_lines);424rename_gdscript_keywords(source_lines, reg_container, true);425rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, source_lines);426rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, source_lines);427rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);428rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);429rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, source_lines);430431custom_rename(source_lines, "\\.shader", ".gdshader");432433convert_hexadecimal_colors(source_lines, reg_container);434} else if (file_name.ends_with(".cs")) { // TODO, C# should use different methods.435rename_classes(source_lines, reg_container); // Using only specialized function.436rename_common(RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, source_lines);437rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);438rename_common(RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, source_lines);439rename_common(RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, source_lines);440rename_csharp_functions(source_lines, reg_container);441rename_csharp_attributes(source_lines, reg_container);442custom_rename(source_lines, "public class ", "public partial class ");443convert_hexadecimal_colors(source_lines, reg_container);444} else if (file_name.ends_with(".gdshader") || file_name.ends_with(".shader")) {445rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);446} else if (file_name.ends_with("tres")) {447rename_classes(source_lines, reg_container); // Using only specialized function.448449rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, source_lines);450rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);451452custom_rename(source_lines, "\\.shader", ".gdshader");453} else if (file_name.ends_with("project.godot")) {454rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, source_lines);455rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, source_lines);456rename_input_map_scancode(source_lines, reg_container);457rename_joypad_buttons_and_axes(source_lines, reg_container);458rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, source_lines);459custom_rename(source_lines, "config_version=4", "config_version=5");460} else if (file_name.ends_with(".csproj")) {461// TODO462} else if (file_name.ends_with(".import")) {463for (SourceLine &source_line : source_lines) {464String &line = source_line.line;465if (line.contains("nodes/root_type=\"Spatial\"")) {466line = "nodes/root_type=\"Node3D\"";467} else if (line == "importer=\"ogg_vorbis\"") {468line = "importer=\"oggvorbisstr\"";469}470}471} else {472ERR_PRINT(file_name + " is not supported!");473continue;474}475476for (SourceLine &source_line : source_lines) {477if (source_line.is_comment) {478continue;479}480481String &line = source_line.line;482if (uint64_t(line.length()) > maximum_line_length) {483ignored_lines += 1;484}485}486} else {487reason.append(vformat(" ERROR: File has exceeded the maximum size allowed - %d KB", maximum_file_size / 1024));488is_ignored = true;489}490491uint64_t end_time = Time::get_singleton()->get_ticks_msec();492if (is_ignored) {493String end_message = vformat(" Checking file took %d ms.", end_time - start_time);494print_line(end_message);495} else {496String file_content_after = collect_string_from_vector(source_lines);497uint64_t hash_after = file_content_after.hash64();498// Don't need to save file without any changes.499// Save if this is a shader, because it was renamed.500if (hash_before != hash_after || file_name.ends_with(".gdshader")) {501converted_files++;502503Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::WRITE);504ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to apply changes to \"%s\", no writing access.", file_name));505file->store_string(file_content_after);506reason.append(vformat(" File was changed, conversion took %d ms.", end_time - start_time));507} else {508reason.append(vformat(" File was left unchanged, checking took %d ms.", end_time - start_time));509}510if (ignored_lines != 0) {511reason.append(vformat(" Ignored %d lines, because their length exceeds maximum allowed characters - %d.", ignored_lines, maximum_line_length));512}513}514for (int k = 0; k < reason.size(); k++) {515print_line(reason[k]);516}517}518print_line(vformat("Conversion ended - all files(%d), converted files: (%d), not converted files: (%d).", collected_files.size(), converted_files, collected_files.size() - converted_files));519uint64_t conversion_end_time = Time::get_singleton()->get_ticks_msec();520print_line(vformat("Conversion of all files took %10.3f seconds.", (conversion_end_time - conversion_start_time) / 1000.0));521return true;522}523524// Function responsible for validating project conversion.525bool ProjectConverter3To4::validate_conversion() {526print_line("Starting checking if project conversion can be done.");527uint64_t conversion_start_time = Time::get_singleton()->get_ticks_msec();528529RegExContainer reg_container = RegExContainer();530531int cached_maximum_line_length = maximum_line_length;532maximum_line_length = 10000; // To avoid breaking the tests, only use this for the their larger value.533534ERR_FAIL_COND_V_MSG(!test_array_names(), false, "Cannot start converting due to problems with data in arrays.");535ERR_FAIL_COND_V_MSG(!test_conversion(reg_container), false, "Aborting conversion due to validation tests failing");536537maximum_line_length = cached_maximum_line_length;538539// Checking if folder contains valid Godot 3 project.540// Project should not be converted more than once.541{542String conventer_text = "; Project was converted by built-in tool to Godot 4";543544ERR_FAIL_COND_V_MSG(!FileAccess::exists("project.godot"), false, "Current directory doesn't contain any Godot 3 project");545546Error err = OK;547String project_godot_content = FileAccess::get_file_as_string("project.godot", &err);548549ERR_FAIL_COND_V_MSG(err != OK, false, "Failed to read content of \"project.godot\" file.");550ERR_FAIL_COND_V_MSG(project_godot_content.contains(conventer_text), false, "Project already was converted with this tool.");551}552553Vector<String> collected_files = check_for_files();554555uint32_t converted_files = 0;556557// Check file by file.558for (int i = 0; i < collected_files.size(); i++) {559const String &file_name = collected_files[i];560Vector<String> lines;561uint32_t ignored_lines = 0;562uint64_t file_size = 0;563{564Ref<FileAccess> file = FileAccess::open(file_name, FileAccess::READ);565ERR_CONTINUE_MSG(file.is_null(), vformat("Unable to read content of \"%s\".", file_name));566while (!file->eof_reached()) {567String line = file->get_line();568file_size += line.size();569lines.append(line);570}571}572print_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));573574Vector<String> changed_elements;575Vector<String> reason;576bool is_ignored = false;577uint64_t start_time = Time::get_singleton()->get_ticks_msec();578579if (file_name.ends_with(".shader")) {580reason.append("\tFile extension will be renamed from \"shader\" to \"gdshader\".");581}582583if (file_size < uint64_t(maximum_file_size)) {584if (file_name.ends_with(".gd")) {585changed_elements.append_array(check_for_rename_classes(lines, reg_container));586587changed_elements.append_array(check_for_rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, lines));588changed_elements.append_array(check_for_rename_colors(lines, reg_container));589590changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, lines));591changed_elements.append_array(check_for_rename_gdscript_functions(lines, reg_container, false));592593changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, lines));594changed_elements.append_array(check_for_rename_gdscript_keywords(lines, reg_container, false));595changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, lines));596changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));597changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));598changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));599changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));600601changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));602} else if (file_name.ends_with(".tscn")) {603changed_elements.append_array(check_for_rename_classes(lines, reg_container));604605changed_elements.append_array(check_for_rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, lines));606changed_elements.append_array(check_for_rename_colors(lines, reg_container));607608changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, lines));609changed_elements.append_array(check_for_rename_gdscript_functions(lines, reg_container, true));610611changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_settings_renames, reg_container.project_settings_regexes, lines));612changed_elements.append_array(check_for_rename_gdscript_keywords(lines, reg_container, true));613changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, lines));614changed_elements.append_array(check_for_rename_common(RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, lines));615changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));616changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));617changed_elements.append_array(check_for_rename_common(RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, lines));618619changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));620} else if (file_name.ends_with(".cs")) {621changed_elements.append_array(check_for_rename_classes(lines, reg_container));622changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, lines));623changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));624changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, lines));625changed_elements.append_array(check_for_rename_common(RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, lines));626changed_elements.append_array(check_for_rename_csharp_functions(lines, reg_container));627changed_elements.append_array(check_for_rename_csharp_attributes(lines, reg_container));628changed_elements.append_array(check_for_custom_rename(lines, "public class ", "public partial class "));629} else if (file_name.ends_with(".gdshader") || file_name.ends_with(".shader")) {630changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));631} else if (file_name.ends_with("tres")) {632changed_elements.append_array(check_for_rename_classes(lines, reg_container));633634changed_elements.append_array(check_for_rename_common(RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, lines));635changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));636637changed_elements.append_array(check_for_custom_rename(lines, "\\.shader", ".gdshader"));638} else if (file_name.ends_with("project.godot")) {639changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, lines));640changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));641changed_elements.append_array(check_for_rename_input_map_scancode(lines, reg_container));642changed_elements.append_array(check_for_rename_joypad_buttons_and_axes(lines, reg_container));643changed_elements.append_array(check_for_rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, lines));644} else if (file_name.ends_with(".csproj")) {645// TODO646} else {647ERR_PRINT(vformat("\"%s\", is not supported!", file_name));648continue;649}650651for (String &line : lines) {652if (uint64_t(line.length()) > maximum_line_length) {653ignored_lines += 1;654}655}656} else {657reason.append(vformat("\tERROR: File has exceeded the maximum size allowed - %d KB.", maximum_file_size / 1024));658is_ignored = true;659}660661uint64_t end_time = Time::get_singleton()->get_ticks_msec();662String end_message = vformat(" Checking file took %10.3f ms.", (end_time - start_time) / 1000.0);663if (ignored_lines != 0) {664end_message += vformat(" Ignored %d lines, because their length exceeds maximum allowed characters - %d.", ignored_lines, maximum_line_length);665}666print_line(end_message);667668for (int k = 0; k < reason.size(); k++) {669print_line(reason[k]);670}671672if (changed_elements.size() > 0 && !is_ignored) {673converted_files++;674675for (int k = 0; k < changed_elements.size(); k++) {676print_line(String("\t\t") + changed_elements[k]);677}678}679}680681print_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));682uint64_t conversion_end_time = Time::get_singleton()->get_ticks_msec();683print_line(vformat("Conversion of all files took %10.3f seconds.", (conversion_end_time - conversion_start_time) / 1000.0));684return true;685}686687// Collect files which will be checked, excluding ".txt", ".mp4", ".wav" etc. files.688Vector<String> ProjectConverter3To4::check_for_files() {689Vector<String> collected_files = Vector<String>();690691Vector<String> directories_to_check = Vector<String>();692directories_to_check.push_back("res://");693694while (!directories_to_check.is_empty()) {695String path = directories_to_check.get(directories_to_check.size() - 1); // Is there any pop_back function?696directories_to_check.resize(directories_to_check.size() - 1); // Remove last element697698Ref<DirAccess> dir = DirAccess::open(path);699if (dir.is_valid()) {700dir->set_include_hidden(true);701dir->list_dir_begin();702String current_dir = dir->get_current_dir();703String file_name = dir->_get_next();704705while (file_name != "") {706if (file_name == ".git" || file_name == ".godot") {707file_name = dir->_get_next();708continue;709}710if (dir->current_is_dir()) {711directories_to_check.append(current_dir.path_join(file_name) + "/");712} else {713bool proper_extension = false;714if (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")) {715proper_extension = true;716}717718if (proper_extension) {719collected_files.append(current_dir.path_join(file_name));720}721}722file_name = dir->_get_next();723}724} else {725print_verbose("Failed to open " + path);726}727}728return collected_files;729}730731Vector<SourceLine> ProjectConverter3To4::split_lines(const String &text) {732Vector<String> lines = text.split("\n");733Vector<SourceLine> source_lines;734for (String &line : lines) {735SourceLine source_line;736source_line.line = line;737source_line.is_comment = false;738739source_lines.append(source_line);740}741return source_lines;742}743744// Test expected results of gdscript745bool 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) {746Vector<SourceLine> got = split_lines(name);747748(this->*func)(got, reg_container, builtin_script);749String got_str = collect_string_from_vector(got);750ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));751752return true;753}754755bool ProjectConverter3To4::test_conversion_with_regex(const String &name, const String &expected, void (ProjectConverter3To4::*func)(Vector<SourceLine> &, const RegExContainer &), const String &what, const RegExContainer ®_container) {756Vector<SourceLine> got = split_lines(name);757758(this->*func)(got, reg_container);759String got_str = collect_string_from_vector(got);760ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));761762return true;763}764765bool ProjectConverter3To4::test_conversion_basic(const String &name, const String &expected, const char *array[][2], LocalVector<RegEx *> ®ex_cache, const String &what) {766Vector<SourceLine> got = split_lines(name);767768rename_common(array, regex_cache, got);769String got_str = collect_string_from_vector(got);770ERR_FAIL_COND_V_MSG(expected != got_str, false, vformat("Failed to convert %s \"%s\" to \"%s\", got instead \"%s\"", what, name, expected, got_str));771772return true;773}774775// Validate if conversions are proper.776bool ProjectConverter3To4::test_conversion(RegExContainer ®_container) {777bool valid = true;778779valid = valid && test_conversion_with_regex("tool", "@tool", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);780valid = valid && test_conversion_with_regex("\n tool", "\n tool", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);781valid = valid && test_conversion_with_regex("\n\ntool", "@tool\n\n", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container);782783valid = valid && test_conversion_with_regex("pause_mode = 2", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);784valid = valid && test_conversion_with_regex("pause_mode = 1", "pause_mode = 1", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);785valid = valid && test_conversion_with_regex("pause_mode = 3", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);786valid = valid && test_conversion_with_regex("somepause_mode = 2", "somepause_mode = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);787valid = valid && test_conversion_with_regex("pause_mode_ext = 2", "pause_mode_ext = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container);788789valid = valid && test_conversion_basic("TYPE_REAL", "TYPE_FLOAT", RenamesMap3To4::enum_renames, reg_container.enum_regexes, "enum");790791valid = valid && test_conversion_basic("can_instance", "can_instantiate", RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, "gdscript function");792793valid = valid && test_conversion_basic("CanInstance", "CanInstantiate", RenamesMap3To4::csharp_function_renames, reg_container.csharp_function_regexes, "csharp function");794795valid = valid && test_conversion_basic("translation", "position", RenamesMap3To4::gdscript_properties_renames, reg_container.gdscript_properties_regexes, "gdscript property");796797valid = valid && test_conversion_basic("Translation", "Position", RenamesMap3To4::csharp_properties_renames, reg_container.csharp_properties_regexes, "csharp property");798799valid = valid && test_conversion_basic("NORMALMAP", "NORMAL_MAP", RenamesMap3To4::shaders_renames, reg_container.shaders_regexes, "shader");800801valid = valid && test_conversion_basic("text_entered", "text_submitted", RenamesMap3To4::gdscript_signals_renames, reg_container.gdscript_signals_regexes, "gdscript signal");802803valid = valid && test_conversion_basic("TextEntered", "TextSubmitted", RenamesMap3To4::csharp_signals_renames, reg_container.csharp_signal_regexes, "csharp signal");804805valid = 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");806807valid = 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");808809valid = valid && test_conversion_basic("Transform", "Transform3D", RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, "builtin type");810811valid = valid && test_conversion_basic("custom_constants/margin_right", "theme_override_constants/margin_right", RenamesMap3To4::theme_override_renames, reg_container.theme_override_regexes, "theme overrides");812813// Custom Renames.814815valid = 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);816valid = 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);817valid = 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);818819valid = valid && test_conversion_with_regex("[Remote]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);820valid = valid && test_conversion_with_regex("[RemoteSync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);821valid = valid && test_conversion_with_regex("[Sync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);822valid = valid && test_conversion_with_regex("[Slave]", "[RPC]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);823valid = valid && test_conversion_with_regex("[Puppet]", "[RPC]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);824valid = valid && test_conversion_with_regex("[PuppetSync]", "[RPC(CallLocal = true)]", &ProjectConverter3To4::rename_csharp_attributes, "custom rename csharp", reg_container);825valid = 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);826valid = 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);827828valid = 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);829valid = 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);830valid = 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);831valid = 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);832833valid = 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);834valid = 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);835valid = 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);836valid = 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);837838valid = 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);839valid = 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);840valid = 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);841valid = 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);842843valid = 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);844valid = 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);845valid = 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);846valid = 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);847848valid = 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);849valid = 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);850valid = 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);851valid = 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);852853valid = 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);854valid = 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);855valid = 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);856valid = 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);857858valid = 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);859valid = 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);860861valid = 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);862valid = 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);863864valid = 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);865valid = 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);866valid = 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);867valid = 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);868869valid = 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);870871valid = 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);872valid = 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);873valid = 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);874875valid = valid && test_conversion_gdscript_builtin("sort_custom( a , b )", "sort_custom(Callable(a, b))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);876877valid = valid && test_conversion_gdscript_builtin("func c(var a, var b)", "func c(a, b)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);878879valid = 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);880881valid = 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);882valid = 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);883valid = 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);884valid = valid && test_conversion_gdscript_builtin("\tmtx.lock()", "\tmtx.lock()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);885valid = valid && test_conversion_gdscript_builtin("\tmutex.unlock()", "\tmutex.unlock()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);886887valid = valid && test_conversion_with_regex("extends CSGBox", "extends CSGBox3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);888valid = valid && test_conversion_with_regex("CSGBox", "CSGBox3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);889valid = valid && test_conversion_with_regex("Spatial", "Node3D", &ProjectConverter3To4::rename_classes, "classes", reg_container);890valid = valid && test_conversion_with_regex("Spatial.tscn", "Spatial.tscn", &ProjectConverter3To4::rename_classes, "classes", reg_container);891valid = valid && test_conversion_with_regex("Spatial.gd", "Spatial.gd", &ProjectConverter3To4::rename_classes, "classes", reg_container);892valid = valid && test_conversion_with_regex("Spatial.shader", "Spatial.shader", &ProjectConverter3To4::rename_classes, "classes", reg_container);893valid = valid && test_conversion_with_regex("Spatial.other", "Node3D.other", &ProjectConverter3To4::rename_classes, "classes", reg_container);894895valid = valid && test_conversion_gdscript_builtin("\nonready", "\n@onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);896valid = valid && test_conversion_gdscript_builtin("onready", "@onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);897valid = valid && test_conversion_gdscript_builtin(" onready", " onready", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);898valid = valid && test_conversion_gdscript_builtin("\nexport", "\n@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);899valid = valid && test_conversion_gdscript_builtin("\texport", "\t@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);900valid = valid && test_conversion_gdscript_builtin("\texport_dialog", "\texport_dialog", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);901valid = valid && test_conversion_gdscript_builtin("export", "@export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);902valid = valid && test_conversion_gdscript_builtin(" export", " export", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);903valid = valid && test_conversion_gdscript_builtin("\n\nremote func", "\n\n@rpc(\"any_peer\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);904valid = valid && test_conversion_gdscript_builtin("\n\nremote func", "\n\n@rpc(\\\"any_peer\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);905valid = 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);906valid = 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);907valid = 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);908valid = 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);909valid = valid && test_conversion_gdscript_builtin("\n\nslave func", "\n\n@rpc func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);910valid = valid && test_conversion_gdscript_builtin("\n\npuppet func", "\n\n@rpc func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);911valid = valid && test_conversion_gdscript_builtin("\n\npuppetsync func", "\n\n@rpc(\"call_local\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, false);912valid = valid && test_conversion_gdscript_builtin("\n\npuppetsync func", "\n\n@rpc(\\\"call_local\\\") func", &ProjectConverter3To4::rename_gdscript_keywords, "gdscript keyword", reg_container, true);913valid = 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);914valid = 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);915916valid = 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);917valid = 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);918valid = 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);919valid = 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);920921valid = valid && test_conversion_gdscript_builtin("get_node(@", "get_node(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);922923valid = valid && test_conversion_gdscript_builtin("yield(this, \"timeout\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);924valid = valid && test_conversion_gdscript_builtin("yield(this, \\\"timeout\\\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, true);925926valid = 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);927valid = 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);928929valid = 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);930valid = valid && test_conversion_gdscript_builtin("export (int)var spaces=1", "export var spaces: int=1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);931valid = 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 workaround932valid = valid && test_conversion_gdscript_builtin("export(PackedScene) var mob_scene", "export var mob_scene: PackedScene", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);933valid = 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);934valid = 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);935valid = valid && test_conversion_gdscript_builtin("export var lifetime := 3.0", "export var lifetime := 3.0", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);936valid = 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);937938valid = 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);939940valid = valid && test_conversion_gdscript_builtin("to_json( AA ) szon", "JSON.new().stringify( AA ) szon", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);941valid = valid && test_conversion_gdscript_builtin("s to_json", "s JSON.new().stringify", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);942valid = valid && test_conversion_gdscript_builtin("AF to_json2", "AF to_json2", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);943valid = 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);944945valid = valid && test_conversion_gdscript_builtin("empty()", "is_empty()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);946valid = valid && test_conversion_gdscript_builtin(".empty", ".empty", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);947948valid = valid && test_conversion_gdscript_builtin(").roman(", ").roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);949valid = valid && test_conversion_gdscript_builtin("\t.roman(", "\tsuper.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);950valid = valid && test_conversion_gdscript_builtin(" .roman(", " super.roman(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);951valid = valid && test_conversion_gdscript_builtin(".1", ".1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);952valid = valid && test_conversion_gdscript_builtin(" .1", " .1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);953valid = valid && test_conversion_gdscript_builtin("'.'", "'.'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);954valid = valid && test_conversion_gdscript_builtin("'.a'", "'.a'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);955valid = valid && test_conversion_gdscript_builtin("\t._input(_event)", "\tsuper._input(_event)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);956957valid = 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);958valid = 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);959valid = 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);960valid = 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);961valid = 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);962valid = 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);963964valid = valid && test_conversion_gdscript_builtin(".connect(A,B,C)", ".connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);965valid = 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);966valid = valid && test_conversion_gdscript_builtin("\tconnect(A,B,C)", "\tconnect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);967valid = valid && test_conversion_gdscript_builtin(" connect(A,B,C)", " connect(A, Callable(B, C))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);968valid = valid && test_conversion_gdscript_builtin("_connect(A,B,C)", "_connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);969valid = valid && test_conversion_gdscript_builtin("do_connect(A,B,C)", "do_connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);970valid = valid && test_conversion_gdscript_builtin("$connect(A,B,C)", "$connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);971valid = valid && test_conversion_gdscript_builtin("@connect(A,B,C)", "@connect(A,B,C)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);972973valid = valid && test_conversion_gdscript_builtin("(start(A,B) != OK):", "(start(Callable(A, B)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);974valid = valid && test_conversion_gdscript_builtin("func start(A,B):", "func start(A,B):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);975valid = 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);976valid = 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);977valid = 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);978valid = 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);979980valid = 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);981valid = 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);982valid = 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);983valid = 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);984985valid = valid && test_conversion_gdscript_builtin("func _init(", "func _init(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);986valid = 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);987valid = 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);988valid = 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);989valid = 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);990valid = valid && test_conversion_gdscript_builtin("q_PackedDataContainer._iter_init(variable1)", "q_PackedDataContainer._iter_init(variable1)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);991992valid = valid && test_conversion_gdscript_builtin("create_from_image(aa, bb)", "create_from_image(aa) #,bb", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);993valid = 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);994995valid = 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);996valid = valid && test_conversion_gdscript_builtin("set_cell_item(a, b)", "set_cell_item(a, b)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);997valid = 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);998valid = 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);999valid = 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);10001001valid = valid && test_conversion_gdscript_builtin("PackedStringArray(req_godot).join('.')", "'.'.join(PackedStringArray(req_godot))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1002valid = valid && test_conversion_gdscript_builtin("=PackedStringArray(req_godot).join('.')", "='.'.join(PackedStringArray(req_godot))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);10031004valid = valid && test_conversion_gdscript_builtin("apply_force(position, impulse)", "apply_force(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1005valid = valid && test_conversion_gdscript_builtin("apply_impulse(position, impulse)", "apply_impulse(impulse, position)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1006valid = 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);1007valid = valid && test_conversion_gdscript_builtin("get_focus_owner()", "get_viewport().gui_get_focus_owner()", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1008valid = valid && test_conversion_gdscript_builtin("button.pressed = 1", "button.button_pressed = 1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1009valid = valid && test_conversion_gdscript_builtin("button.pressed=1", "button.button_pressed=1", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);1010valid = valid && test_conversion_gdscript_builtin("button.pressed SF", "button.pressed SF", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);10111012valid = valid && test_conversion_with_regex("Color(\"#f47d\")", "Color(\"#47df\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);1013valid = valid && test_conversion_with_regex("Color(\"#ff478cbf\")", "Color(\"#478cbfff\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);1014valid = valid && test_conversion_with_regex("Color(\"#de32bf\")", "Color(\"#de32bf\")", &ProjectConverter3To4::convert_hexadecimal_colors, "color literals", reg_container);1015valid = valid && test_conversion_with_regex("AAA Color.white AF", "AAA Color.WHITE AF", &ProjectConverter3To4::rename_colors, "color constants", reg_container);10161017// Note: Do not change to *scancode*, it is applied before that conversion.1018valid = 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);1019valid = 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);10201021valid = 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);1022valid = valid && test_conversion_with_regex("\"device\":0,\"axis\":6,", "\"device\":0,\"axis\":4,", &ProjectConverter3To4::rename_joypad_buttons_and_axes, "custom rename", reg_container);1023valid = 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);10241025// Custom rule conversion1026{1027String from = "instance";1028String to = "instantiate";1029String name = "AA.instance()";10301031Vector<SourceLine> got = split_lines(name);10321033String expected = "AA.instantiate()";1034custom_rename(got, from, to);1035String got_str = collect_string_from_vector(got);1036if (got_str != expected) {1037ERR_PRINT(vformat("Failed to convert custom rename \"%s\" to \"%s\", got \"%s\", instead.", name, expected, got_str));1038}1039valid = valid && (got_str == expected);1040}10411042// get_object_of_execution1043{1044String base = "var roman = kieliszek.";1045String expected = "kieliszek.";1046String got = get_object_of_execution(base);1047if (got != expected) {1048ERR_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()));1049}1050valid = valid && (got == expected);1051}1052{1053String base = "r.";1054String expected = "r.";1055String got = get_object_of_execution(base);1056if (got != expected) {1057ERR_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()));1058}1059valid = valid && (got == expected);1060}1061{1062String base = "mortadela(";1063String expected = "";1064String got = get_object_of_execution(base);1065if (got != expected) {1066ERR_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()));1067}1068valid = valid && (got == expected);1069}1070{1071String base = "var node = $world/ukraine/lviv.";1072String expected = "$world/ukraine/lviv.";1073String got = get_object_of_execution(base);1074if (got != expected) {1075ERR_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()));1076}1077valid = valid && (got == expected);1078}10791080// get_starting_space1081{1082String base = "\t\t\t var roman = kieliszek.";1083String expected = "\t\t\t";1084String got = get_starting_space(base);1085if (got != expected) {1086ERR_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()));1087}1088valid = valid && (got == expected);1089}10901091// Parse Arguments1092{1093String line = "( )";1094Vector<String> got_vector = parse_arguments(line);1095String got = "";1096String expected = "";1097for (String &part : got_vector) {1098got += part + "|||";1099}1100if (got != expected) {1101ERR_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()));1102}1103valid = valid && (got == expected);1104}1105{1106String line = "(a , b , c)";1107Vector<String> got_vector = parse_arguments(line);1108String got = "";1109String expected = "a|||b|||c|||";1110for (String &part : got_vector) {1111got += part + "|||";1112}1113if (got != expected) {1114ERR_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()));1115}1116valid = valid && (got == expected);1117}1118{1119String line = "(a , \"b,\" , c)";1120Vector<String> got_vector = parse_arguments(line);1121String got = "";1122String expected = "a|||\"b,\"|||c|||";1123for (String &part : got_vector) {1124got += part + "|||";1125}1126if (got != expected) {1127ERR_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()));1128}1129valid = valid && (got == expected);1130}1131{1132String line = "(a , \"(,),,,,\" , c)";1133Vector<String> got_vector = parse_arguments(line);1134String got = "";1135String expected = "a|||\"(,),,,,\"|||c|||";1136for (String &part : got_vector) {1137got += part + "|||";1138}1139if (got != expected) {1140ERR_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()));1141}1142valid = valid && (got == expected);1143}11441145return valid;1146}11471148// Validate in all arrays if names don't do cyclic renames "Node" -> "Node2D" | "Node2D" -> "2DNode"1149bool ProjectConverter3To4::test_array_names() {1150bool valid = true;1151Vector<String> names = Vector<String>();11521153// Validate if all classes are valid.1154{1155for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {1156const String old_class = RenamesMap3To4::class_renames[current_index][0];1157const String new_class = RenamesMap3To4::class_renames[current_index][1];11581159// Light2D, Texture, Viewport are special classes(probably virtual ones).1160if (ClassDB::class_exists(StringName(old_class)) && old_class != "Light2D" && old_class != "Texture" && old_class != "Viewport") {1161ERR_PRINT(vformat("Class \"%s\" exists in Godot 4, so it cannot be renamed to something else.", old_class));1162valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.1163}11641165// Callable is special class, to which normal classes may be renamed.1166if (!ClassDB::class_exists(StringName(new_class)) && new_class != "Callable") {1167ERR_PRINT(vformat("Class \"%s\" does not exist in Godot 4, so it cannot be used in the conversion.", new_class));1168valid = false; // This probably should be only a warning, but not 100% sure - this would need to be added to CI.1169}1170}1171}11721173{1174HashSet<String> all_functions;11751176// List of excluded functions from builtin types and global namespace, because currently it is not possible to get list of functions from them.1177// This will be available when https://github.com/godotengine/godot/pull/49053 or similar will be included into Godot.1178static 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 };1179for (int current_index = 0; builtin_types_excluded_functions[current_index]; current_index++) {1180all_functions.insert(builtin_types_excluded_functions[current_index]);1181}11821183//for (int type = Variant::Type::NIL + 1; type < Variant::Type::VARIANT_MAX; type++) {1184// List<MethodInfo> method_list;1185// Variant::get_method_list_by_type(&method_list, Variant::Type(type));1186// for (MethodInfo &function_data : method_list) {1187// if (!all_functions.has(function_data.name)) {1188// all_functions.insert(function_data.name);1189// }1190// }1191//}11921193List<StringName> classes_list;1194ClassDB::get_class_list(&classes_list);1195for (StringName &name_of_class : classes_list) {1196List<MethodInfo> method_list;1197ClassDB::get_method_list(name_of_class, &method_list, true);1198for (MethodInfo &function_data : method_list) {1199if (!all_functions.has(function_data.name)) {1200all_functions.insert(function_data.name);1201}1202}1203}12041205int current_element = 0;1206while (RenamesMap3To4::gdscript_function_renames[current_element][0] != nullptr) {1207String name_3_x = RenamesMap3To4::gdscript_function_renames[current_element][0];1208String name_4_0 = RenamesMap3To4::gdscript_function_renames[current_element][1];1209if (!all_functions.has(name_4_0)) {1210ERR_PRINT(vformat("Missing GDScript function in pair (%s - ===> %s <===)", name_3_x, name_4_0));1211valid = false;1212}1213current_element++;1214}1215}1216if (!valid) {1217ERR_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.");1218}12191220valid = valid && test_single_array(RenamesMap3To4::enum_renames);1221valid = valid && test_single_array(RenamesMap3To4::class_renames, true);1222valid = valid && test_single_array(RenamesMap3To4::gdscript_function_renames, true);1223valid = valid && test_single_array(RenamesMap3To4::csharp_function_renames, true);1224valid = valid && test_single_array(RenamesMap3To4::gdscript_properties_renames, true);1225valid = valid && test_single_array(RenamesMap3To4::csharp_properties_renames, true);1226valid = valid && test_single_array(RenamesMap3To4::shaders_renames, true);1227valid = valid && test_single_array(RenamesMap3To4::gdscript_signals_renames);1228valid = valid && test_single_array(RenamesMap3To4::project_settings_renames);1229valid = valid && test_single_array(RenamesMap3To4::project_godot_renames);1230valid = valid && test_single_array(RenamesMap3To4::input_map_renames);1231valid = valid && test_single_array(RenamesMap3To4::builtin_types_renames);1232valid = valid && test_single_array(RenamesMap3To4::color_renames);12331234return valid;1235}12361237// Validates the array to prevent cyclic renames, such as `Node` -> `Node2D`, then `Node2D` -> `2DNode`.1238// Also checks if names contain leading or trailing spaces.1239bool ProjectConverter3To4::test_single_array(const char *p_array[][2], bool p_ignore_4_0_name) {1240bool valid = true;1241Vector<String> names = Vector<String>();12421243for (unsigned int current_index = 0; p_array[current_index][0]; current_index++) {1244String name_3_x = p_array[current_index][0];1245String name_4_0 = p_array[current_index][1];1246if (name_3_x != name_3_x.strip_edges()) {1247ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));1248valid = false;1249}1250if (names.has(name_3_x)) {1251ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));1252valid = false;1253}1254names.append(name_3_x);12551256if (name_4_0 != name_4_0.strip_edges()) {1257ERR_PRINT(vformat("Invalid Entry \"%s\" contains leading or trailing spaces.", name_3_x));1258valid = false;1259}1260if (names.has(name_4_0)) {1261ERR_PRINT(vformat("Found duplicated entry, pair ( -> %s , %s)", name_3_x, name_4_0));1262valid = false;1263}1264if (!p_ignore_4_0_name) {1265names.append(name_4_0);1266}1267}1268return valid;1269}12701271// Returns arguments from given function execution, this cannot be really done as regex.1272// `abc(d,e(f,g),h)` -> [d], [e(f,g)], [h]1273Vector<String> ProjectConverter3To4::parse_arguments(const String &line) {1274Vector<String> parts;1275int string_size = line.length();1276int start_part = 0; // Index of beginning of start part.1277int parts_counter = 0;1278char32_t previous_character = '\0';1279bool is_inside_string = false; // If true, it ignores these 3 characters ( , ) inside string.12801281ERR_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));12821283for (int current_index = 0; current_index < string_size; current_index++) {1284char32_t character = line.get(current_index);1285switch (character) {1286case '(':1287case '[':1288case '{': {1289parts_counter++;1290if (parts_counter == 1 && !is_inside_string) {1291start_part = current_index;1292}1293break;1294};1295case ')':1296case '}': {1297parts_counter--;1298if (parts_counter == 0 && !is_inside_string) {1299parts.append(line.substr(start_part + 1, current_index - start_part - 1));1300start_part = current_index;1301}1302break;1303};1304case ']': {1305parts_counter--;1306if (parts_counter == 0 && !is_inside_string) {1307parts.append(line.substr(start_part, current_index - start_part));1308start_part = current_index;1309}1310break;1311};1312case ',': {1313if (parts_counter == 1 && !is_inside_string) {1314parts.append(line.substr(start_part + 1, current_index - start_part - 1));1315start_part = current_index;1316}1317break;1318};1319case '"': {1320if (previous_character != '\\') {1321is_inside_string = !is_inside_string;1322}1323}1324}1325previous_character = character;1326}13271328Vector<String> clean_parts;1329for (String &part : parts) {1330part = part.strip_edges();1331if (!part.is_empty()) {1332clean_parts.append(part);1333}1334}13351336return clean_parts;1337}13381339// Finds latest parenthesis owned by function.1340// `function(abc(a,b),DD)):` finds this parenthess `function(abc(a,b),DD => ) <= ):`1341int ProjectConverter3To4::get_end_parenthesis(const String &line) const {1342int current_state = 0;1343for (int current_index = 0; line.length() > current_index; current_index++) {1344char32_t character = line.get(current_index);1345if (character == '(') {1346current_state++;1347}1348if (character == ')') {1349current_state--;1350if (current_state == 0) {1351return current_index;1352}1353}1354}1355return -1;1356}13571358// Merges multiple arguments into a single String.1359// Needed when after processing e.g. 2 arguments, later arguments are not changed in any way.1360String ProjectConverter3To4::connect_arguments(const Vector<String> &arguments, int from, int to) const {1361if (to == -1) {1362to = arguments.size();1363}13641365String value;1366if (arguments.size() > 0 && from != 0 && from < to) {1367value = ", ";1368}13691370for (int i = from; i < to; i++) {1371value += arguments[i];1372if (i != to - 1) {1373value += ", ";1374}1375}1376return value;1377}13781379// Returns the indentation (spaces and tabs) at the start of the line e.g. `\t\tmove_this` returns `\t\t`.1380String ProjectConverter3To4::get_starting_space(const String &line) const {1381String empty_space;1382int current_character = 0;13831384if (line.is_empty()) {1385return empty_space;1386}13871388if (line[0] == ' ') {1389while (current_character < line.size()) {1390if (line[current_character] == ' ') {1391empty_space += ' ';1392current_character++;1393} else {1394break;1395}1396}1397}1398if (line[0] == '\t') {1399while (current_character < line.size()) {1400if (line[current_character] == '\t') {1401empty_space += '\t';1402current_character++;1403} else {1404break;1405}1406}1407}1408return empty_space;1409}14101411// Returns the object that’s executing the function in the line.1412// e.g. Passing the line "var roman = kieliszek.funkcja()" to this function returns "kieliszek".1413String ProjectConverter3To4::get_object_of_execution(const String &line) const {1414int end = line.size() - 1; // Last one is \01415int variable_start = end - 1;1416int start = end - 1;14171418bool is_possibly_nodepath = false;1419bool is_valid_nodepath = false;14201421while (start >= 0) {1422char32_t character = line[start];1423bool is_variable_char = (character >= 'A' && character <= 'Z') || (character >= 'a' && character <= 'z') || character == '.' || character == '_';1424bool is_nodepath_start = character == '$';1425bool is_nodepath_sep = character == '/';1426if (is_variable_char || is_nodepath_start || is_nodepath_sep) {1427if (start == 0) {1428break;1429} else if (is_nodepath_sep) {1430// Freeze variable_start, try to fetch more chars since this might be a Node path literal.1431is_possibly_nodepath = true;1432} else if (is_nodepath_start) {1433// Found $, this is a Node path literal.1434is_valid_nodepath = true;1435break;1436}1437if (!is_possibly_nodepath) {1438variable_start--;1439}1440start--;1441continue;1442} else {1443// Abandon all hope, this is neither a variable nor a Node path literal.1444variable_start++; // Found invalid character, needs to be ignored.1445break;1446}1447}1448if (is_valid_nodepath) {1449variable_start = start;1450}1451return line.substr(variable_start, (end - variable_start));1452}14531454void ProjectConverter3To4::rename_colors(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {1455for (SourceLine &source_line : source_lines) {1456if (source_line.is_comment) {1457continue;1458}14591460String &line = source_line.line;1461if (uint64_t(line.length()) <= maximum_line_length) {1462if (line.contains("Color.")) {1463for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {1464line = reg_container.color_regexes[current_index]->sub(line, reg_container.color_renamed[current_index], true);1465}1466}1467}1468}1469}14701471// Convert hexadecimal colors from ARGB to RGBA1472void ProjectConverter3To4::convert_hexadecimal_colors(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {1473for (SourceLine &source_line : source_lines) {1474if (source_line.is_comment) {1475continue;1476}14771478String &line = source_line.line;1479if (uint64_t(line.length()) <= maximum_line_length) {1480if (line.contains("Color(\"")) {1481line = reg_container.color_hexadecimal_short_constructor.sub(line, "Color(\"#$2$1", true);1482line = reg_container.color_hexadecimal_full_constructor.sub(line, "Color(\"#$2$1", true);1483}1484}1485}1486}14871488Vector<String> ProjectConverter3To4::check_for_rename_colors(Vector<String> &lines, const RegExContainer ®_container) {1489Vector<String> found_renames;14901491int current_line = 1;1492for (String &line : lines) {1493if (uint64_t(line.length()) <= maximum_line_length) {1494if (line.contains("Color.")) {1495for (unsigned int current_index = 0; RenamesMap3To4::color_renames[current_index][0]; current_index++) {1496TypedArray<RegExMatch> reg_match = reg_container.color_regexes[current_index]->search_all(line);1497if (reg_match.size() > 0) {1498found_renames.append(line_formatter(current_line, RenamesMap3To4::color_renames[current_index][0], RenamesMap3To4::color_renames[current_index][1], line));1499}1500}1501}1502}1503current_line++;1504}15051506return found_renames;1507}15081509void ProjectConverter3To4::fix_tool_declaration(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {1510// In godot4, "tool" became "@tool" and must be located at the top of the file.1511for (int i = 0; i < source_lines.size(); ++i) {1512if (source_lines[i].line == "tool") {1513source_lines.remove_at(i);1514source_lines.insert(0, { "@tool", false });1515return; // assuming there's at most 1 tool declaration.1516}1517}1518}15191520void ProjectConverter3To4::fix_pause_mode(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {1521// In Godot 3, the pause_mode 2 equals the PAUSE_MODE_PROCESS value.1522// In Godot 4, the pause_mode PAUSE_MODE_PROCESS was renamed to PROCESS_MODE_ALWAYS and equals the number 3.1523// We therefore convert pause_mode = 2 to pause_mode = 3.1524for (SourceLine &source_line : source_lines) {1525String &line = source_line.line;15261527if (line == "pause_mode = 2") {1528// Note: pause_mode is renamed to process_mode later on, so no need to do it here.1529line = "pause_mode = 3";1530}1531}1532}15331534void ProjectConverter3To4::rename_classes(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {1535for (SourceLine &source_line : source_lines) {1536if (source_line.is_comment) {1537continue;1538}15391540String &line = source_line.line;1541if (uint64_t(line.length()) <= maximum_line_length) {1542for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {1543if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {1544bool found_ignored_items = false;1545// Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.1546if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {1547found_ignored_items = true;1548line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);1549line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);1550line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);1551}15521553// Causal renaming Spatial -> Node3D.1554line = reg_container.class_regexes[current_index]->sub(line, RenamesMap3To4::class_renames[current_index][1], true);15551556// Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.1557if (found_ignored_items) {1558line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);1559line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);1560line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);1561}1562}1563}1564}1565}1566}15671568Vector<String> ProjectConverter3To4::check_for_rename_classes(Vector<String> &lines, const RegExContainer ®_container) {1569Vector<String> found_renames;15701571int current_line = 1;15721573for (String &line : lines) {1574if (uint64_t(line.length()) <= maximum_line_length) {1575for (unsigned int current_index = 0; RenamesMap3To4::class_renames[current_index][0]; current_index++) {1576if (line.contains(RenamesMap3To4::class_renames[current_index][0])) {1577String old_line = line;1578bool found_ignored_items = false;1579// Renaming Spatial.tscn to TEMP_RENAMED_CLASS.tscn.1580if (line.contains(String(RenamesMap3To4::class_renames[current_index][0]) + ".")) {1581found_ignored_items = true;1582line = reg_container.class_tscn_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.tscn", true);1583line = reg_container.class_gd_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.gd", true);1584line = reg_container.class_shader_regexes[current_index]->sub(line, "TEMP_RENAMED_CLASS.shader", true);1585}15861587// Causal renaming Spatial -> Node3D.1588TypedArray<RegExMatch> reg_match = reg_container.class_regexes[current_index]->search_all(line);1589if (reg_match.size() > 0) {1590found_renames.append(line_formatter(current_line, RenamesMap3To4::class_renames[current_index][0], RenamesMap3To4::class_renames[current_index][1], old_line));1591}15921593// Restore Spatial.tscn from TEMP_RENAMED_CLASS.tscn.1594if (found_ignored_items) {1595line = reg_container.class_temp_tscn.sub(line, reg_container.class_temp_tscn_renames[current_index], true);1596line = reg_container.class_temp_gd.sub(line, reg_container.class_temp_gd_renames[current_index], true);1597line = reg_container.class_temp_shader.sub(line, reg_container.class_temp_shader_renames[current_index], true);1598}1599}1600}1601}1602current_line++;1603}1604return found_renames;1605}16061607void ProjectConverter3To4::rename_gdscript_functions(Vector<SourceLine> &source_lines, const RegExContainer ®_container, bool builtin) {1608for (SourceLine &source_line : source_lines) {1609if (source_line.is_comment) {1610continue;1611}16121613String &line = source_line.line;1614if (uint64_t(line.length()) <= maximum_line_length) {1615process_gdscript_line(line, reg_container, builtin);1616}1617}1618}16191620Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector<String> &lines, const RegExContainer ®_container, bool builtin) {1621int current_line = 1;16221623Vector<String> found_renames;16241625for (String &line : lines) {1626if (uint64_t(line.length()) <= maximum_line_length) {1627String old_line = line;1628process_gdscript_line(line, reg_container, builtin);1629if (old_line != line) {1630found_renames.append(simple_line_formatter(current_line, old_line, line));1631}1632}1633}16341635return found_renames;1636}16371638bool ProjectConverter3To4::contains_function_call(const String &line, const String &function) const {1639// We want to convert the function only if it is completely standalone.1640// For example, when we search for "connect(", we don't want to accidentally convert "reconnect(".1641if (!line.contains(function)) {1642return false;1643}16441645int index = line.find(function);1646if (index == 0) {1647return true;1648}16491650char32_t previous_char = line.get(index - 1);1651return (previous_char < '0' || previous_char > '9') && (previous_char < 'a' || previous_char > 'z') && (previous_char < 'A' || previous_char > 'Z') && previous_char != '_' && previous_char != '$' && previous_char != '@';1652}16531654// TODO, this function should run only on all ".gd" files and also on lines in ".tscn" files which are parts of built-in Scripts.1655void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContainer ®_container, bool builtin) {1656// In this and other functions, reg.sub() is used only after checking lines with str.contains().1657// With longer lines, doing so can sometimes be significantly faster.16581659if ((line.contains(".lock") || line.contains(".unlock")) && !line.contains("mtx") && !line.contains("mutex") && !line.contains("Mutex")) {1660line = 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);1661line = 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);1662}16631664// PackedStringArray(req_godot).join('.') -> '.'.join(PackedStringArray(req_godot)) PoolStringArray1665if (line.contains(".join")) {1666line = reg_container.reg_join.sub(line, "$2.join($1)", true);1667}16681669// -- empty() -> is_empty() Pool*Array1670if (line.contains("empty")) {1671line = reg_container.reg_is_empty.sub(line, "is_empty(", true);1672}16731674// -- \t.func() -> \tsuper.func() Object1675if (line.contains_char('(') && line.contains_char('.')) {1676line = 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"1677}16781679// -- JSON.parse(a) -> JSON.new().parse(a) etc. JSON1680if (line.contains("parse")) {1681line = 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);1682}16831684// -- to_json(a) -> JSON.new().stringify(a) Object1685if (line.contains("to_json")) {1686line = reg_container.reg_json_to.sub(line, "JSON.new().stringify", true);1687}1688// -- parse_json(a) -> JSON.get_data() etc. Object1689if (line.contains("parse_json")) {1690line = 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);1691}1692// -- JSON.print( -> JSON.stringify(1693if (line.contains("JSON.print(")) {1694line = reg_container.reg_json_print.sub(line, "JSON.stringify(", true);1695}16961697// -- get_node(@ -> get_node( Node1698if (line.contains("get_node")) {1699line = line.replace("get_node(@", "get_node(");1700}17011702if (line.contains("export")) {1703// 1. export(float) var lifetime: float = 3.0 -> export var lifetime: float = 3.01704line = reg_container.reg_export_typed.sub(line, "export var $2: $1");1705// 2. export(float) var lifetime := 3.0 -> export var lifetime := 3.01706line = reg_container.reg_export_inferred_type.sub(line, "export var $1 :=");1707// 3. export(float) var lifetime = 3.0 -> export var lifetime: float = 3.0 GDScript1708line = reg_container.reg_export_simple.sub(line, "export var $2: $1");1709// 4. export(String, 'AnonymousPro', 'CourierPrime') var _font_name = 'AnonymousPro' -> export var _font_name = 'AnonymousPro' #(String, 'AnonymousPro', 'CourierPrime') GDScript1710line = reg_container.reg_export_advanced.sub(line, "export var $2$3 # ($1)");1711}17121713// Setget Setget1714if (line.contains("setget")) {1715line = reg_container.reg_setget_setget.sub(line, "var $1$2: get = $4, set = $3", true);1716}17171718// Setget set1719if (line.contains("setget")) {1720line = reg_container.reg_setget_set.sub(line, "var $1$2: set = $3", true);1721}17221723// Setget get1724if (line.contains("setget")) {1725line = reg_container.reg_setget_get.sub(line, "var $1$2: get = $3", true);1726}17271728if (line.contains("window_resizable")) {1729// OS.set_window_resizable(a) -> get_window().unresizable = not (a)1730line = reg_container.reg_os_set_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);1731// OS.window_resizable = a -> same1732line = reg_container.reg_os_assign_window_resizable.sub(line, "get_window().unresizable = not ($1)", true);1733// OS.[is_]window_resizable() -> (not get_window().unresizable)1734line = reg_container.reg_os_is_window_resizable.sub(line, "(not get_window().unresizable)", true);1735}17361737if (line.contains("window_fullscreen")) {1738// OS.window_fullscreen(a) -> get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if (a) else Window.MODE_WINDOWED1739line = reg_container.reg_os_set_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);1740// window_fullscreen = a -> same1741line = reg_container.reg_os_assign_fullscreen.sub(line, "get_window().mode = Window.MODE_EXCLUSIVE_FULLSCREEN if ($1) else Window.MODE_WINDOWED", true);1742// OS.[is_]window_fullscreen() -> ((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))1743line = reg_container.reg_os_is_fullscreen.sub(line, "((get_window().mode == Window.MODE_EXCLUSIVE_FULLSCREEN) or (get_window().mode == Window.MODE_FULLSCREEN))", true);1744}17451746if (line.contains("window_maximized")) {1747// OS.window_maximized(a) -> get_window().mode = Window.MODE_MAXIMIZED if (a) else Window.MODE_WINDOWED1748line = reg_container.reg_os_set_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);1749// window_maximized = a -> same1750line = reg_container.reg_os_assign_maximized.sub(line, "get_window().mode = Window.MODE_MAXIMIZED if ($1) else Window.MODE_WINDOWED", true);1751// OS.[is_]window_maximized() -> (get_window().mode == Window.MODE_MAXIMIZED)1752line = reg_container.reg_os_is_maximized.sub(line, "(get_window().mode == Window.MODE_MAXIMIZED)", true);1753}17541755if (line.contains("window_minimized")) {1756// OS.window_minimized(a) -> get_window().mode = Window.MODE_MINIMIZED if (a) else Window.MODE_WINDOWED1757line = reg_container.reg_os_set_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);1758// window_minimized = a -> same1759line = reg_container.reg_os_assign_minimized.sub(line, "get_window().mode = Window.MODE_MINIMIZED if ($1) else Window.MODE_WINDOWED", true);1760// OS.[is_]window_minimized() -> (get_window().mode == Window.MODE_MINIMIZED)1761line = reg_container.reg_os_is_minimized.sub(line, "(get_window().mode == Window.MODE_MINIMIZED)", true);1762}17631764if (line.contains("set_use_vsync")) {1765// OS.set_use_vsync(a) -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)1766line = reg_container.reg_os_set_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);1767}1768if (line.contains("vsync_enabled")) {1769// vsync_enabled = a -> get_window().window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if (a) else DisplayServer.VSYNC_DISABLED)1770line = reg_container.reg_os_assign_vsync.sub(line, "DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if ($1) else DisplayServer.VSYNC_DISABLED)", true);1771// OS.[is_]vsync_enabled() -> (DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)1772line = reg_container.reg_os_is_vsync.sub(line, "(DisplayServer.window_get_vsync_mode() != DisplayServer.VSYNC_DISABLED)", true);1773}17741775if (line.contains("OS.screen_orientation")) { // keep "OS." at start1776// OS.screen_orientation = a -> DisplayServer.screen_set_orientation(a)1777line = reg_container.reg_os_assign_screen_orient.sub(line, "$1DisplayServer.screen_set_orientation($2)", true); // assignment1778line = line.replace("OS.screen_orientation", "DisplayServer.screen_get_orientation()"); // value access1779}17801781if (line.contains("_window_always_on_top")) {1782// OS.set_window_always_on_top(a) -> get_window().always_on_top = (a)1783line = reg_container.reg_os_set_always_on_top.sub(line, "get_window().always_on_top = ($1)", true);1784// OS.is_window_always_on_top() -> get_window().always_on_top1785line = reg_container.reg_os_is_always_on_top.sub(line, "get_window().always_on_top", true);1786}17871788if (line.contains("et_borderless_window")) {1789// OS.set_borderless_window(a) -> get_window().borderless = (a)1790line = reg_container.reg_os_set_borderless.sub(line, "get_window().borderless = ($1)", true);1791// OS.get_borderless_window() -> get_window().borderless1792line = reg_container.reg_os_get_borderless.sub(line, "get_window().borderless", true);1793}17941795// OS.SCREEN_ORIENTATION_* -> DisplayServer.SCREEN_*1796if (line.contains("OS.SCREEN_ORIENTATION_")) {1797line = reg_container.reg_os_screen_orient_enum.sub(line, "DisplayServer.SCREEN_$1", true);1798}17991800// OS -> Window simple replacements with optional set/get.1801if (line.contains("current_screen")) {1802line = reg_container.reg_os_current_screen.sub(line, "get_window().$1current_screen", true);1803}1804if (line.contains("min_window_size")) {1805line = reg_container.reg_os_min_window_size.sub(line, "get_window().$1min_size", true);1806}1807if (line.contains("max_window_size")) {1808line = reg_container.reg_os_max_window_size.sub(line, "get_window().$1max_size", true);1809}1810if (line.contains("window_position")) {1811line = reg_container.reg_os_window_position.sub(line, "get_window().$1position", true);1812}1813if (line.contains("window_size")) {1814line = reg_container.reg_os_window_size.sub(line, "get_window().$1size", true);1815}1816if (line.contains("et_screen_orientation")) {1817line = reg_container.reg_os_getset_screen_orient.sub(line, "DisplayServer.screen_$1et_orientation", true);1818}18191820// Instantiate1821if (contains_function_call(line, "instance")) {1822line = reg_container.reg_instantiate.sub(line, ".instantiate($1)", true);1823}18241825// -- r.move_and_slide( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody1826if (contains_function_call(line, "move_and_slide(")) {1827int start = line.find("move_and_slide(");1828int end = get_end_parenthesis(line.substr(start)) + 1;1829if (end > -1) {1830String base_obj = get_object_of_execution(line.substr(0, start));1831String starting_space = get_starting_space(line);18321833Vector<String> parts = parse_arguments(line.substr(start, end));1834if (parts.size() >= 1) {1835String line_new;18361837// motion_velocity1838line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";18391840// up_direction1841if (parts.size() >= 2) {1842line_new += starting_space + base_obj + "set_up_direction(" + parts[1] + ")\n";1843}18441845// stop_on_slope1846if (parts.size() >= 3) {1847line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[2] + ")\n";1848}18491850// max_slides1851if (parts.size() >= 4) {1852line_new += starting_space + base_obj + "set_max_slides(" + parts[3] + ")\n";1853}18541855// floor_max_angle1856if (parts.size() >= 5) {1857line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[4] + ")\n";1858}18591860// infiinite_interia1861if (parts.size() >= 6) {1862line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[5] + "`\n";1863}18641865line_new += starting_space + base_obj + "move_and_slide()";18661867if (!line.begins_with(starting_space + "move_and_slide")) {1868line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);1869} else {1870line = line_new + line.substr(end + start);1871}1872}1873}1874}18751876// -- r.move_and_slide_with_snap( a, b, c, d, e ) -> r.set_velocity(a) ... r.move_and_slide() KinematicBody1877if (contains_function_call(line, "move_and_slide_with_snap(")) {1878int start = line.find("move_and_slide_with_snap(");1879int end = get_end_parenthesis(line.substr(start)) + 1;1880if (end > -1) {1881String base_obj = get_object_of_execution(line.substr(0, start));1882String starting_space = get_starting_space(line);18831884Vector<String> parts = parse_arguments(line.substr(start, end));1885if (parts.size() >= 1) {1886String line_new;18871888// motion_velocity1889line_new += starting_space + base_obj + "set_velocity(" + parts[0] + ")\n";18901891// snap1892if (parts.size() >= 2) {1893line_new += starting_space + "# TODOConverter3To4 looks that snap in Godot 4 is float, not vector like in Godot 3 - previous value `" + parts[1] + "`\n";1894}18951896// up_direction1897if (parts.size() >= 3) {1898line_new += starting_space + base_obj + "set_up_direction(" + parts[2] + ")\n";1899}19001901// stop_on_slope1902if (parts.size() >= 4) {1903line_new += starting_space + base_obj + "set_floor_stop_on_slope_enabled(" + parts[3] + ")\n";1904}19051906// max_slides1907if (parts.size() >= 5) {1908line_new += starting_space + base_obj + "set_max_slides(" + parts[4] + ")\n";1909}19101911// floor_max_angle1912if (parts.size() >= 6) {1913line_new += starting_space + base_obj + "set_floor_max_angle(" + parts[5] + ")\n";1914}19151916// infiinite_interia1917if (parts.size() >= 7) {1918line_new += starting_space + "# TODOConverter3To4 infinite_inertia were removed in Godot 4 - previous value `" + parts[6] + "`\n";1919}19201921line_new += starting_space + base_obj + "move_and_slide()";19221923if (!line.begins_with(starting_space + "move_and_slide_with_snap")) {1924line = line_new + "\n" + line.substr(0, start) + "velocity" + line.substr(end + start);1925} else {1926line = line_new + line.substr(end + start);1927}1928}1929}1930}19311932// -- sort_custom( a , b ) -> sort_custom(Callable( a , b )) Object1933if (contains_function_call(line, "sort_custom(")) {1934int start = line.find("sort_custom(");1935int end = get_end_parenthesis(line.substr(start)) + 1;1936if (end > -1) {1937Vector<String> parts = parse_arguments(line.substr(start, end));1938if (parts.size() == 2) {1939line = line.substr(0, start) + "sort_custom(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);1940}1941}1942}19431944// -- list_dir_begin( ) -> list_dir_begin() Object1945if (contains_function_call(line, "list_dir_begin(")) {1946int start = line.find("list_dir_begin(");1947int end = get_end_parenthesis(line.substr(start)) + 1;1948if (end > -1) {1949line = line.substr(0, start) + "list_dir_begin() " + line.substr(end + start) + "# TODOConverter3To4 fill missing arguments https://github.com/godotengine/godot/pull/40547";1950}1951}19521953// -- draw_line(1,2,3,4,5) -> draw_line(1, 2, 3, 4) CanvasItem1954if (contains_function_call(line, "draw_line(")) {1955int start = line.find("draw_line(");1956int end = get_end_parenthesis(line.substr(start)) + 1;1957if (end > -1) {1958Vector<String> parts = parse_arguments(line.substr(start, end));1959if (parts.size() == 5) {1960line = line.substr(0, start) + "draw_line(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ", " + parts[3] + ")" + line.substr(end + start);1961}1962}1963}19641965// -- func c(var a, var b) -> func c(a, b)1966if (line.contains("func ") && line.contains("var ")) {1967int start = line.find("func ");1968start = line.substr(start).find_char('(') + start;1969int end = get_end_parenthesis(line.substr(start)) + 1;1970if (end > -1) {1971Vector<String> parts = parse_arguments(line.substr(start, end));19721973String start_string = line.substr(0, start) + "(";1974for (int i = 0; i < parts.size(); i++) {1975start_string += parts[i].strip_edges().trim_prefix("var ");1976if (i != parts.size() - 1) {1977start_string += ", ";1978}1979}1980line = start_string + ")" + line.substr(end + start);1981}1982}19831984// -- yield(this, \"timeout\") -> await this.timeout GDScript1985if (contains_function_call(line, "yield(")) {1986int start = line.find("yield(");1987int end = get_end_parenthesis(line.substr(start)) + 1;1988if (end > -1) {1989Vector<String> parts = parse_arguments(line.substr(start, end));1990if (parts.size() == 2) {1991if (builtin) {1992line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\\\"", "").replace("\\'", "").remove_char(' ') + line.substr(end + start);1993} else {1994line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].remove_chars("\"' ") + line.substr(end + start);1995}1996}1997}1998}19992000// -- parse_json( AA ) -> TODO Object2001if (contains_function_call(line, "parse_json(")) {2002int start = line.find("parse_json(");2003int end = get_end_parenthesis(line.substr(start)) + 1;2004if (end > -1) {2005Vector<String> parts = parse_arguments(line.substr(start, end));2006line = line.substr(0, start) + "JSON.new().stringify(" + connect_arguments(parts, 0) + ")" + line.substr(end + start);2007}2008}20092010// -- .xform(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform2011if (line.contains(".xform(")) {2012int start = line.find(".xform(");2013int end = get_end_parenthesis(line.substr(start)) + 1;2014if (end > -1) {2015Vector<String> parts = parse_arguments(line.substr(start, end));2016if (parts.size() == 1) {2017line = line.substr(0, start) + " * (" + parts[0] + ")" + line.substr(end + start);2018}2019}2020}20212022// -- .xform_inv(Vector3(a,b,c)) -> * Vector3(a,b,c) Transform2023if (line.contains(".xform_inv(")) {2024int start = line.find(".xform_inv(");2025int end = get_end_parenthesis(line.substr(start)) + 1;2026if (end > -1) {2027String object_exec = get_object_of_execution(line.substr(0, start));2028if (line.contains(object_exec + ".xform")) {2029int start2 = line.find(object_exec + ".xform");2030Vector<String> parts = parse_arguments(line.substr(start, end));2031if (parts.size() == 1) {2032line = line.substr(0, start2) + "(" + parts[0] + ") * " + object_exec + line.substr(end + start);2033}2034}2035}2036}20372038// -- "(connect(A,B,C,D,E) != OK):", "(connect(A, Callable(B, C).bind(D), E) Object2039if (contains_function_call(line, "connect(")) {2040int start = line.find("connect(");2041int end = get_end_parenthesis(line.substr(start)) + 1;2042if (end > -1) {2043Vector<String> parts = parse_arguments(line.substr(start, end));2044if (parts.size() == 3) {2045line = line.substr(0, start) + "connect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2046} else if (parts.size() >= 4) {2047line = 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);2048}2049}2050}2051// -- disconnect(a,b,c) -> disconnect(a,Callable(b,c)) Object2052if (contains_function_call(line, "disconnect(")) {2053int start = line.find("disconnect(");2054int end = get_end_parenthesis(line.substr(start)) + 1;2055if (end > -1) {2056Vector<String> parts = parse_arguments(line.substr(start, end));2057if (parts.size() == 3) {2058line = line.substr(0, start) + "disconnect(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2059}2060}2061}2062// -- is_connected(a,b,c) -> is_connected(a,Callable(b,c)) Object2063if (contains_function_call(line, "is_connected(")) {2064int start = line.find("is_connected(");2065int end = get_end_parenthesis(line.substr(start)) + 1;2066if (end > -1) {2067Vector<String> parts = parse_arguments(line.substr(start, end));2068if (parts.size() == 3) {2069line = line.substr(0, start) + "is_connected(" + parts[0] + ", Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2070}2071}2072}2073// -- "(tween_method(A,B,C,D,E) != OK):", "(tween_method(Callable(A,B),C,D,E) Object2074// -- "(tween_method(A,B,C,D,E,[F,G]) != OK):", "(tween_method(Callable(A,B).bind(F,G),C,D,E) Object2075if (contains_function_call(line, "tween_method(")) {2076int start = line.find("tween_method(");2077int end = get_end_parenthesis(line.substr(start)) + 1;2078if (end > -1) {2079Vector<String> parts = parse_arguments(line.substr(start, end));2080if (parts.size() == 5) {2081line = line.substr(0, start) + "tween_method(Callable(" + parts[0] + ", " + parts[1] + "), " + parts[2] + ", " + parts[3] + ", " + parts[4] + ")" + line.substr(end + start);2082} else if (parts.size() >= 6) {2083line = 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);2084}2085}2086}2087// -- "(tween_callback(A,B,[C,D]) != OK):", "(connect(Callable(A,B).bind(C,D)) Object2088if (contains_function_call(line, "tween_callback(")) {2089int start = line.find("tween_callback(");2090int end = get_end_parenthesis(line.substr(start)) + 1;2091if (end > -1) {2092Vector<String> parts = parse_arguments(line.substr(start, end));2093if (parts.size() == 2) {2094line = line.substr(0, start) + "tween_callback(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);2095} else if (parts.size() >= 3) {2096line = line.substr(0, start) + "tween_callback(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + connect_arguments(parts, 2).substr(1).lstrip(" [").rstrip("] ") + "))" + line.substr(end + start);2097}2098}2099}2100// -- start(a,b) -> start(Callable(a, b)) Thread2101// -- start(a,b,c,d) -> start(Callable(a, b).bind(c), d) Thread2102if (contains_function_call(line, "start(")) {2103int start = line.find("start(");2104int end = get_end_parenthesis(line.substr(start)) + 1;2105// Protection from 'func start'2106if (!line.begins_with("func ")) {2107if (end > -1) {2108Vector<String> parts = parse_arguments(line.substr(start, end));2109if (parts.size() == 2) {2110line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + "))" + line.substr(end + start);2111} else if (parts.size() >= 3) {2112line = line.substr(0, start) + "start(Callable(" + parts[0] + ", " + parts[1] + ").bind(" + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);2113}2114}2115}2116}2117// -- func _init(p_x:int).(p_x): -> func _init(p_x:int):\n\tsuper(p_x) Object # https://github.com/godotengine/godot/issues/705422118if (line.contains(" _init(") && line.rfind_char(':') > 0) {2119// func _init(p_arg1).(super4, super5, super6)->void:2120// ^--^indent ^super_start super_end^2121int indent = line.count("\t", 0, line.find("func"));2122int super_start = line.find(".(");2123int super_end = line.rfind_char(')');2124if (super_start > 0 && super_end > super_start) {2125line = 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);2126}2127}21282129// create_from_image(aa, bb) -> create_from_image(aa) #, bb ImageTexture2130if (contains_function_call(line, "create_from_image(")) {2131int start = line.find("create_from_image(");2132int end = get_end_parenthesis(line.substr(start)) + 1;2133if (end > -1) {2134Vector<String> parts = parse_arguments(line.substr(start, end));2135if (parts.size() == 2) {2136line = line.substr(0, start) + "create_from_image(" + parts[0] + ") " + "#," + parts[1] + line.substr(end + start);2137}2138}2139}2140// set_cell_item(a, b, c, d ,e) -> set_cell_item(Vector3(a, b, c), d ,e)2141if (contains_function_call(line, "set_cell_item(")) {2142int start = line.find("set_cell_item(");2143int end = get_end_parenthesis(line.substr(start)) + 1;2144if (end > -1) {2145Vector<String> parts = parse_arguments(line.substr(start, end));2146if (parts.size() > 2) {2147line = line.substr(0, start) + "set_cell_item(Vector3(" + parts[0] + ", " + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3).lstrip(" ") + ")" + line.substr(end + start);2148}2149}2150}2151// get_cell_item(a, b, c) -> get_cell_item(Vector3i(a, b, c))2152if (contains_function_call(line, "get_cell_item(")) {2153int start = line.find("get_cell_item(");2154int end = get_end_parenthesis(line.substr(start)) + 1;2155if (end > -1) {2156Vector<String> parts = parse_arguments(line.substr(start, end));2157if (parts.size() == 3) {2158line = line.substr(0, start) + "get_cell_item(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2159}2160}2161}2162// get_cell_item_orientation(a, b, c) -> get_cell_item_orientation(Vector3i(a, b, c))2163if (contains_function_call(line, "get_cell_item_orientation(")) {2164int start = line.find("get_cell_item_orientation(");2165int end = get_end_parenthesis(line.substr(start)) + 1;2166if (end > -1) {2167Vector<String> parts = parse_arguments(line.substr(start, end));2168if (parts.size() == 3) {2169line = line.substr(0, start) + "get_cell_item_orientation(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2170}2171}2172}2173// apply_impulse(A, B) -> apply_impulse(B, A)2174if (contains_function_call(line, "apply_impulse(")) {2175int start = line.find("apply_impulse(");2176int end = get_end_parenthesis(line.substr(start)) + 1;2177if (end > -1) {2178Vector<String> parts = parse_arguments(line.substr(start, end));2179if (parts.size() == 2) {2180line = line.substr(0, start) + "apply_impulse(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);2181}2182}2183}2184// apply_force(A, B) -> apply_force(B, A)2185if (contains_function_call(line, "apply_force(")) {2186int start = line.find("apply_force(");2187int end = get_end_parenthesis(line.substr(start)) + 1;2188if (end > -1) {2189Vector<String> parts = parse_arguments(line.substr(start, end));2190if (parts.size() == 2) {2191line = line.substr(0, start) + "apply_force(" + parts[1] + ", " + parts[0] + ")" + line.substr(end + start);2192}2193}2194}2195// map_to_world(a, b, c) -> map_to_local(Vector3i(a, b, c))2196if (contains_function_call(line, "map_to_world(")) {2197int start = line.find("map_to_world(");2198int end = get_end_parenthesis(line.substr(start)) + 1;2199if (end > -1) {2200Vector<String> parts = parse_arguments(line.substr(start, end));2201if (parts.size() == 3) {2202line = line.substr(0, start) + "map_to_local(Vector3i(" + parts[0] + ", " + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2203} else if (parts.size() == 1) {2204line = line.substr(0, start) + "map_to_local(" + parts[0] + ")" + line.substr(end + start);2205}2206}2207}22082209// set_rotating(true) -> set_ignore_rotation(false)2210if (contains_function_call(line, "set_rotating(")) {2211int start = line.find("set_rotating(");2212int end = get_end_parenthesis(line.substr(start)) + 1;2213if (end > -1) {2214Vector<String> parts = parse_arguments(line.substr(start, end));2215if (parts.size() == 1) {2216String opposite = parts[0] == "true" ? "false" : "true";2217line = line.substr(0, start) + "set_ignore_rotation(" + opposite + ")";2218}2219}2220}22212222// OS.get_window_safe_area() -> DisplayServer.get_display_safe_area()2223if (line.contains("OS.get_window_safe_area(")) {2224int start = line.find("OS.get_window_safe_area(");2225int end = get_end_parenthesis(line.substr(start)) + 1;2226if (end > -1) {2227Vector<String> parts = parse_arguments(line.substr(start, end));2228if (parts.is_empty()) {2229line = line.substr(0, start) + "DisplayServer.get_display_safe_area()" + line.substr(end + start);2230}2231}2232}2233// draw_rect(a,b,c,d,e) -> draw_rect(a,b,c,d)#e) TODOConverter3To4 Antialiasing argument is missing2234if (contains_function_call(line, "draw_rect(")) {2235int start = line.find("draw_rect(");2236int end = get_end_parenthesis(line.substr(start)) + 1;2237if (end > -1) {2238Vector<String> parts = parse_arguments(line.substr(start, end));2239if (parts.size() == 5) {2240line = 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";2241}2242}2243}2244// get_focus_owner() -> get_viewport().gui_get_focus_owner()2245if (contains_function_call(line, "get_focus_owner()")) {2246line = line.replace("get_focus_owner()", "get_viewport().gui_get_focus_owner()");2247}22482249// button.pressed = 1 -> button.button_pressed = 12250if (line.contains(".pressed")) {2251int start = line.find(".pressed");2252bool foundNextEqual = false;2253String line_to_check = line.substr(start + String(".pressed").length());2254for (int current_index = 0; line_to_check.length() > current_index; current_index++) {2255char32_t chr = line_to_check.get(current_index);2256if (chr == '\t' || chr == ' ') {2257continue;2258} else if (chr == '=') {2259foundNextEqual = true;2260} else {2261break;2262}2263}2264if (foundNextEqual) {2265line = line.substr(0, start) + ".button_pressed" + line.substr(start + String(".pressed").length());2266}2267}22682269// rotating = true -> ignore_rotation = false # reversed "rotating" for Camera2D2270if (contains_function_call(line, "rotating")) {2271String function_name = "rotating";2272int start = line.find(function_name);2273bool foundNextEqual = false;2274String line_to_check = line.substr(start + function_name.length());2275String assigned_value;2276for (int current_index = 0; line_to_check.length() > current_index; current_index++) {2277char32_t chr = line_to_check.get(current_index);2278if (chr == '\t' || chr == ' ') {2279continue;2280} else if (chr == '=') {2281foundNextEqual = true;2282assigned_value = line.substr(start + function_name.length() + current_index + 1).strip_edges();2283assigned_value = assigned_value == "true" ? "false" : "true";2284} else {2285break;2286}2287}2288if (foundNextEqual) {2289line = line.substr(0, start) + "ignore_rotation = " + assigned_value + " # reversed \"rotating\" for Camera2D";2290}2291}22922293// OS -> Time functions2294if (line.contains("OS.get_ticks_msec")) {2295line = line.replace("OS.get_ticks_msec", "Time.get_ticks_msec");2296}2297if (line.contains("OS.get_ticks_usec")) {2298line = line.replace("OS.get_ticks_usec", "Time.get_ticks_usec");2299}2300if (line.contains("OS.get_unix_time")) {2301line = line.replace("OS.get_unix_time", "Time.get_unix_time_from_system");2302}2303if (line.contains("OS.get_datetime")) {2304line = line.replace("OS.get_datetime", "Time.get_datetime_dict_from_system");2305}23062307// OS -> DisplayServer2308if (line.contains("OS.get_display_cutouts")) {2309line = line.replace("OS.get_display_cutouts", "DisplayServer.get_display_cutouts");2310}2311if (line.contains("OS.get_screen_count")) {2312line = line.replace("OS.get_screen_count", "DisplayServer.get_screen_count");2313}2314if (line.contains("OS.get_screen_dpi")) {2315line = line.replace("OS.get_screen_dpi", "DisplayServer.screen_get_dpi");2316}2317if (line.contains("OS.get_screen_max_scale")) {2318line = line.replace("OS.get_screen_max_scale", "DisplayServer.screen_get_max_scale");2319}2320if (line.contains("OS.get_screen_position")) {2321line = line.replace("OS.get_screen_position", "DisplayServer.screen_get_position");2322}2323if (line.contains("OS.get_screen_refresh_rate")) {2324line = line.replace("OS.get_screen_refresh_rate", "DisplayServer.screen_get_refresh_rate");2325}2326if (line.contains("OS.get_screen_scale")) {2327line = line.replace("OS.get_screen_scale", "DisplayServer.screen_get_scale");2328}2329if (line.contains("OS.get_screen_size")) {2330line = line.replace("OS.get_screen_size", "DisplayServer.screen_get_size");2331}2332if (line.contains("OS.set_icon")) {2333line = line.replace("OS.set_icon", "DisplayServer.set_icon");2334}2335if (line.contains("OS.set_native_icon")) {2336line = line.replace("OS.set_native_icon", "DisplayServer.set_native_icon");2337}23382339// OS -> Window2340if (line.contains("OS.window_borderless")) {2341line = line.replace("OS.window_borderless", "get_window().borderless");2342}2343if (line.contains("OS.get_real_window_size")) {2344line = line.replace("OS.get_real_window_size", "get_window().get_size_with_decorations");2345}2346if (line.contains("OS.is_window_focused")) {2347line = line.replace("OS.is_window_focused", "get_window().has_focus");2348}2349if (line.contains("OS.move_window_to_foreground")) {2350line = line.replace("OS.move_window_to_foreground", "get_window().grab_focus");2351}2352if (line.contains("OS.request_attention")) {2353line = line.replace("OS.request_attention", "get_window().request_attention");2354}2355if (line.contains("OS.set_window_title")) {2356line = line.replace("OS.set_window_title", "get_window().set_title");2357}23582359// get_tree().set_input_as_handled() -> get_viewport().set_input_as_handled()2360if (line.contains("get_tree().set_input_as_handled()")) {2361line = line.replace("get_tree().set_input_as_handled()", "get_viewport().set_input_as_handled()");2362}23632364// Fix the simple case of using _unhandled_key_input2365// func _unhandled_key_input(event: InputEventKey) -> _unhandled_key_input(event: InputEvent)2366if (line.contains("_unhandled_key_input(event: InputEventKey)")) {2367line = line.replace("_unhandled_key_input(event: InputEventKey)", "_unhandled_key_input(event: InputEvent)");2368}23692370if (line.contains("Engine.editor_hint")) {2371line = line.replace("Engine.editor_hint", "Engine.is_editor_hint()");2372}2373}23742375void ProjectConverter3To4::process_csharp_line(String &line, const RegExContainer ®_container) {2376line = line.replace("OS.GetWindowSafeArea()", "DisplayServer.ScreenGetUsableRect()");23772378// GetTree().SetInputAsHandled() -> GetViewport().SetInputAsHandled()2379if (line.contains("GetTree().SetInputAsHandled()")) {2380line = line.replace("GetTree().SetInputAsHandled()", "GetViewport().SetInputAsHandled()");2381}23822383// Fix the simple case of using _UnhandledKeyInput2384// func _UnhandledKeyInput(InputEventKey @event) -> _UnhandledKeyInput(InputEvent @event)2385if (line.contains("_UnhandledKeyInput(InputEventKey @event)")) {2386line = line.replace("_UnhandledKeyInput(InputEventKey @event)", "_UnhandledKeyInput(InputEvent @event)");2387}23882389// -- Connect(,,,things) -> Connect(,Callable(,),things) Object2390if (line.contains("Connect(")) {2391int start = line.find("Connect(");2392// Protection from disconnect2393if (start == 0 || line.get(start - 1) != 's') {2394int end = get_end_parenthesis(line.substr(start)) + 1;2395if (end > -1) {2396Vector<String> parts = parse_arguments(line.substr(start, end));2397if (parts.size() >= 3) {2398line = line.substr(0, start) + "Connect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start);2399}2400}2401}2402}2403// -- Disconnect(a,b,c) -> Disconnect(a,Callable(b,c)) Object2404if (line.contains("Disconnect(")) {2405int start = line.find("Disconnect(");2406int end = get_end_parenthesis(line.substr(start)) + 1;2407if (end > -1) {2408Vector<String> parts = parse_arguments(line.substr(start, end));2409if (parts.size() == 3) {2410line = line.substr(0, start) + "Disconnect(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2411}2412}2413}2414// -- IsConnected(a,b,c) -> IsConnected(a,Callable(b,c)) Object2415if (line.contains("IsConnected(")) {2416int start = line.find("IsConnected(");2417int end = get_end_parenthesis(line.substr(start)) + 1;2418if (end > -1) {2419Vector<String> parts = parse_arguments(line.substr(start, end));2420if (parts.size() == 3) {2421line = line.substr(0, start) + "IsConnected(" + parts[0] + ", new Callable(" + parts[1] + ", " + parts[2] + "))" + line.substr(end + start);2422}2423}2424}2425}24262427void ProjectConverter3To4::rename_csharp_functions(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {2428for (SourceLine &source_line : source_lines) {2429if (source_line.is_comment) {2430continue;2431}24322433String &line = source_line.line;2434if (uint64_t(line.length()) <= maximum_line_length) {2435process_csharp_line(line, reg_container);2436}2437}2438}24392440Vector<String> ProjectConverter3To4::check_for_rename_csharp_functions(Vector<String> &lines, const RegExContainer ®_container) {2441int current_line = 1;24422443Vector<String> found_renames;24442445for (String &line : lines) {2446if (uint64_t(line.length()) <= maximum_line_length) {2447String old_line = line;2448process_csharp_line(line, reg_container);2449if (old_line != line) {2450found_renames.append(simple_line_formatter(current_line, old_line, line));2451}2452}2453}24542455return found_renames;2456}24572458void ProjectConverter3To4::rename_csharp_attributes(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {2459static 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";24602461for (SourceLine &source_line : source_lines) {2462if (source_line.is_comment) {2463continue;2464}24652466String &line = source_line.line;2467if (uint64_t(line.length()) <= maximum_line_length) {2468line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);2469line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);2470line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);2471line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);2472line = reg_container.keyword_csharp_master.sub(line, error_message + "[RPC]", true);2473line = reg_container.keyword_csharp_mastersync.sub(line, error_message + "[RPC(CallLocal = true)]", true);2474}2475}2476}24772478Vector<String> ProjectConverter3To4::check_for_rename_csharp_attributes(Vector<String> &lines, const RegExContainer ®_container) {2479int current_line = 1;24802481Vector<String> found_renames;24822483for (String &line : lines) {2484if (uint64_t(line.length()) <= maximum_line_length) {2485String old;2486old = line;2487line = reg_container.keyword_csharp_remote.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", true);2488if (old != line) {2489found_renames.append(line_formatter(current_line, "[Remote]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer)]", line));2490}24912492old = line;2493line = reg_container.keyword_csharp_remotesync.sub(line, "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", true);2494if (old != line) {2495found_renames.append(line_formatter(current_line, "[RemoteSync]", "[RPC(MultiplayerAPI.RPCMode.AnyPeer, CallLocal = true)]", line));2496}24972498old = line;2499line = reg_container.keyword_csharp_puppet.sub(line, "[RPC]", true);2500if (old != line) {2501found_renames.append(line_formatter(current_line, "[Puppet]", "[RPC]", line));2502}25032504old = line;2505line = reg_container.keyword_csharp_puppetsync.sub(line, "[RPC(CallLocal = true)]", true);2506if (old != line) {2507found_renames.append(line_formatter(current_line, "[PuppetSync]", "[RPC(CallLocal = true)]", line));2508}25092510old = line;2511line = reg_container.keyword_csharp_master.sub(line, "[RPC]", true);2512if (old != line) {2513found_renames.append(line_formatter(current_line, "[Master]", "[RPC]", line));2514}25152516old = line;2517line = reg_container.keyword_csharp_mastersync.sub(line, "[RPC(CallLocal = true)]", true);2518if (old != line) {2519found_renames.append(line_formatter(current_line, "[MasterSync]", "[RPC(CallLocal = true)]", line));2520}2521}2522current_line++;2523}25242525return found_renames;2526}25272528_FORCE_INLINE_ static String builtin_escape(const String &p_str, bool p_builtin) {2529if (p_builtin) {2530return p_str.replace("\"", "\\\"");2531} else {2532return p_str;2533}2534}25352536void ProjectConverter3To4::rename_gdscript_keywords(Vector<SourceLine> &source_lines, const RegExContainer ®_container, bool builtin) {2537static 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";25382539for (SourceLine &source_line : source_lines) {2540if (source_line.is_comment) {2541continue;2542}25432544String &line = source_line.line;2545if (uint64_t(line.length()) <= maximum_line_length) {2546if (line.contains("export")) {2547line = reg_container.keyword_gdscript_export_single.sub(line, "@export", true);2548}2549if (line.contains("export")) {2550line = reg_container.keyword_gdscript_export_multi.sub(line, "$1@export", true);2551}2552if (line.contains("onready")) {2553line = reg_container.keyword_gdscript_onready.sub(line, "@onready", true);2554}2555if (line.contains("remote")) {2556line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);2557}2558if (line.contains("remote")) {2559line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);2560}2561if (line.contains("sync")) {2562line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\") func", builtin), true);2563}2564if (line.contains("slave")) {2565line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);2566}2567if (line.contains("puppet")) {2568line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);2569}2570if (line.contains("puppet")) {2571line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);2572}2573if (line.contains("master")) {2574line = reg_container.keyword_gdscript_master.sub(line, error_message + "@rpc func", true);2575}2576if (line.contains("master")) {2577line = reg_container.keyword_gdscript_mastersync.sub(line, error_message + builtin_escape("@rpc(\"call_local\") func", builtin), true);2578}2579}2580}2581}25822583Vector<String> ProjectConverter3To4::check_for_rename_gdscript_keywords(Vector<String> &lines, const RegExContainer ®_container, bool builtin) {2584Vector<String> found_renames;25852586int current_line = 1;2587for (String &line : lines) {2588if (uint64_t(line.length()) <= maximum_line_length) {2589String old;25902591if (line.contains("tool")) {2592old = line;2593line = reg_container.keyword_gdscript_tool.sub(line, "@tool", true);2594if (old != line) {2595found_renames.append(line_formatter(current_line, "tool", "@tool", line));2596}2597}25982599if (line.contains("export")) {2600old = line;2601line = reg_container.keyword_gdscript_export_single.sub(line, "$1@export", true);2602if (old != line) {2603found_renames.append(line_formatter(current_line, "export", "@export", line));2604}2605}26062607if (line.contains("export")) {2608old = line;2609line = reg_container.keyword_gdscript_export_multi.sub(line, "@export", true);2610if (old != line) {2611found_renames.append(line_formatter(current_line, "export", "@export", line));2612}2613}26142615if (line.contains("onready")) {2616old = line;2617line = reg_container.keyword_gdscript_tool.sub(line, "@onready", true);2618if (old != line) {2619found_renames.append(line_formatter(current_line, "onready", "@onready", line));2620}2621}26222623if (line.contains("remote")) {2624old = line;2625line = reg_container.keyword_gdscript_remote.sub(line, builtin_escape("@rpc(\"any_peer\") func", builtin), true);2626if (old != line) {2627found_renames.append(line_formatter(current_line, "remote func", builtin_escape("@rpc(\"any_peer\") func", builtin), line));2628}2629}26302631if (line.contains("remote")) {2632old = line;2633line = reg_container.keyword_gdscript_remotesync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);2634if (old != line) {2635found_renames.append(line_formatter(current_line, "remotesync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));2636}2637}26382639if (line.contains("sync")) {2640old = line;2641line = reg_container.keyword_gdscript_sync.sub(line, builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), true);2642if (old != line) {2643found_renames.append(line_formatter(current_line, "sync func", builtin_escape("@rpc(\"any_peer\", \"call_local\")) func", builtin), line));2644}2645}26462647if (line.contains("slave")) {2648old = line;2649line = reg_container.keyword_gdscript_slave.sub(line, "@rpc func", true);2650if (old != line) {2651found_renames.append(line_formatter(current_line, "slave func", "@rpc func", line));2652}2653}26542655if (line.contains("puppet")) {2656old = line;2657line = reg_container.keyword_gdscript_puppet.sub(line, "@rpc func", true);2658if (old != line) {2659found_renames.append(line_formatter(current_line, "puppet func", "@rpc func", line));2660}2661}26622663if (line.contains("puppet")) {2664old = line;2665line = reg_container.keyword_gdscript_puppetsync.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);2666if (old != line) {2667found_renames.append(line_formatter(current_line, "puppetsync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));2668}2669}26702671if (line.contains("master")) {2672old = line;2673line = reg_container.keyword_gdscript_master.sub(line, "@rpc func", true);2674if (old != line) {2675found_renames.append(line_formatter(current_line, "master func", "@rpc func", line));2676}2677}26782679if (line.contains("master")) {2680old = line;2681line = reg_container.keyword_gdscript_master.sub(line, builtin_escape("@rpc(\"call_local\") func", builtin), true);2682if (old != line) {2683found_renames.append(line_formatter(current_line, "mastersync func", builtin_escape("@rpc(\"call_local\") func", builtin), line));2684}2685}2686}2687current_line++;2688}26892690return found_renames;2691}26922693void ProjectConverter3To4::rename_input_map_scancode(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {2694// The old Special Key, now colliding with CMD_OR_CTRL.2695const int old_spkey = (1 << 24);26962697for (SourceLine &source_line : source_lines) {2698if (source_line.is_comment) {2699continue;2700}27012702String &line = source_line.line;2703if (uint64_t(line.length()) <= maximum_line_length) {2704TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);27052706for (int i = 0; i < reg_match.size(); ++i) {2707Ref<RegExMatch> match = reg_match[i];2708PackedStringArray strings = match->get_strings();2709int key = strings[3].to_int();27102711if (key & old_spkey) {2712// Create new key, clearing old Special Key and setting new one.2713key = (key & ~old_spkey) | (int)Key::SPECIAL;27142715line = line.replace(strings[0], String(",\"") + strings[1] + "scancode\":" + String::num_int64(key));2716}2717}2718}2719}2720}27212722void ProjectConverter3To4::rename_joypad_buttons_and_axes(Vector<SourceLine> &source_lines, const RegExContainer ®_container) {2723for (SourceLine &source_line : source_lines) {2724if (source_line.is_comment) {2725continue;2726}2727String &line = source_line.line;2728if (uint64_t(line.length()) <= maximum_line_length) {2729// Remap button indexes.2730TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);2731for (int i = 0; i < reg_match.size(); ++i) {2732Ref<RegExMatch> match = reg_match[i];2733PackedStringArray strings = match->get_strings();2734const String &button_index_entry = strings[0];2735int button_index_value = strings[1].to_int();2736if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.2737line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");2738line = line.replace(button_index_entry, ",\"axis\":4,\"axis_value\":1.0");2739} else if (button_index_value == 7) {2740line = line.replace("InputEventJoypadButton", "InputEventJoypadMotion");2741line = line.replace(button_index_entry, ",\"axis\":5,\"axis_value\":1.0");2742} else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.2743const String &pressure_and_pressed_properties = strings[2];2744line = line.replace(button_index_entry, ",\"button_index\":" + String::num_int64(reg_container.joypad_button_mappings[button_index_value]) + "," + pressure_and_pressed_properties);2745}2746}2747// Remap axes. Only L2 and R2 need remapping.2748reg_match = reg_container.joypad_axis.search_all(line);2749for (int i = 0; i < reg_match.size(); ++i) {2750Ref<RegExMatch> match = reg_match[i];2751PackedStringArray strings = match->get_strings();2752const String &axis_entry = strings[0];2753int axis_value = strings[1].to_int();2754if (axis_value == 6) {2755line = line.replace(axis_entry, ",\"axis\":4");2756} else if (axis_value == 7) {2757line = line.replace(axis_entry, ",\"axis\":5");2758}2759}2760}2761}2762}27632764Vector<String> ProjectConverter3To4::check_for_rename_joypad_buttons_and_axes(Vector<String> &lines, const RegExContainer ®_container) {2765Vector<String> found_renames;2766int current_line = 1;2767for (String &line : lines) {2768if (uint64_t(line.length()) <= maximum_line_length) {2769// Remap button indexes.2770TypedArray<RegExMatch> reg_match = reg_container.joypad_button_index.search_all(line);2771for (int i = 0; i < reg_match.size(); ++i) {2772Ref<RegExMatch> match = reg_match[i];2773PackedStringArray strings = match->get_strings();2774const String &button_index_entry = strings[0];2775int button_index_value = strings[1].to_int();2776if (button_index_value == 6) { // L2 and R2 are mapped to joypad axes in Godot 4.2777found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));2778found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":4", line));2779} else if (button_index_value == 7) {2780found_renames.append(line_formatter(current_line, "InputEventJoypadButton", "InputEventJoypadMotion", line));2781found_renames.append(line_formatter(current_line, button_index_entry, ",\"axis\":5", line));2782} else if (button_index_value < 22) { // There are no mappings for indexes greater than 22 in both Godot 3 & 4.2783found_renames.append(line_formatter(current_line, "\"button_index\":" + strings[1], "\"button_index\":" + String::num_int64(reg_container.joypad_button_mappings[button_index_value]), line));2784}2785}2786// Remap axes. Only L2 and R2 need remapping.2787reg_match = reg_container.joypad_axis.search_all(line);2788for (int i = 0; i < reg_match.size(); ++i) {2789Ref<RegExMatch> match = reg_match[i];2790PackedStringArray strings = match->get_strings();2791const String &axis_entry = strings[0];2792int axis_value = strings[1].to_int();2793if (axis_value == 6) {2794found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":4", line));2795} else if (axis_value == 7) {2796found_renames.append(line_formatter(current_line, axis_entry, ",\"axis\":5", line));2797}2798}2799current_line++;2800}2801}2802return found_renames;2803}28042805Vector<String> ProjectConverter3To4::check_for_rename_input_map_scancode(Vector<String> &lines, const RegExContainer ®_container) {2806Vector<String> found_renames;28072808// The old Special Key, now colliding with CMD_OR_CTRL.2809const int old_spkey = (1 << 24);28102811int current_line = 1;2812for (String &line : lines) {2813if (uint64_t(line.length()) <= maximum_line_length) {2814TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);28152816for (int i = 0; i < reg_match.size(); ++i) {2817Ref<RegExMatch> match = reg_match[i];2818PackedStringArray strings = match->get_strings();2819int key = strings[3].to_int();28202821if (key & old_spkey) {2822// Create new key, clearing old Special Key and setting new one.2823key = (key & ~old_spkey) | (int)Key::SPECIAL;28242825found_renames.append(line_formatter(current_line, strings[3], String::num_int64(key), line));2826}2827}2828}2829current_line++;2830}2831return found_renames;2832}28332834void ProjectConverter3To4::custom_rename(Vector<SourceLine> &source_lines, const String &from, const String &to) {2835RegEx reg = RegEx(String("\\b") + from + "\\b");2836CRASH_COND(!reg.is_valid());2837for (SourceLine &source_line : source_lines) {2838if (source_line.is_comment) {2839continue;2840}28412842String &line = source_line.line;2843if (uint64_t(line.length()) <= maximum_line_length) {2844line = reg.sub(line, to, true);2845}2846}2847}28482849Vector<String> ProjectConverter3To4::check_for_custom_rename(Vector<String> &lines, const String &from, const String &to) {2850Vector<String> found_renames;28512852RegEx reg = RegEx(String("\\b") + from + "\\b");2853CRASH_COND(!reg.is_valid());28542855int current_line = 1;2856for (String &line : lines) {2857if (uint64_t(line.length()) <= maximum_line_length) {2858TypedArray<RegExMatch> reg_match = reg.search_all(line);2859if (reg_match.size() > 0) {2860found_renames.append(line_formatter(current_line, from.replace("\\.", "."), to, line)); // Without replacing it will print "\.shader" instead ".shader".2861}2862}2863current_line++;2864}2865return found_renames;2866}28672868void ProjectConverter3To4::rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<SourceLine> &source_lines) {2869for (SourceLine &source_line : source_lines) {2870if (source_line.is_comment) {2871continue;2872}28732874String &line = source_line.line;2875if (uint64_t(line.length()) <= maximum_line_length) {2876for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {2877if (line.contains(array[current_index][0])) {2878line = cached_regexes[current_index]->sub(line, array[current_index][1], true);2879}2880}2881}2882}2883}28842885Vector<String> ProjectConverter3To4::check_for_rename_common(const char *array[][2], LocalVector<RegEx *> &cached_regexes, Vector<String> &lines) {2886Vector<String> found_renames;28872888int current_line = 1;28892890for (String &line : lines) {2891if (uint64_t(line.length()) <= maximum_line_length) {2892for (unsigned int current_index = 0; current_index < cached_regexes.size(); current_index++) {2893if (line.contains(array[current_index][0])) {2894TypedArray<RegExMatch> reg_match = cached_regexes[current_index]->search_all(line);2895if (reg_match.size() > 0) {2896found_renames.append(line_formatter(current_line, array[current_index][0], array[current_index][1], line));2897}2898}2899}2900}2901current_line++;2902}29032904return found_renames;2905}29062907// Prints full info about renamed things e.g.:2908// Line (67) remove -> remove_at - LINE """ doubler._blacklist.remove(0) """2909String ProjectConverter3To4::line_formatter(int current_line, String from, String to, String line) {2910if (from.size() > 200) {2911from = from.substr(0, 197) + "...";2912}2913if (to.size() > 200) {2914to = to.substr(0, 197) + "...";2915}2916if (line.size() > 400) {2917line = line.substr(0, 397) + "...";2918}29192920from = from.strip_escapes();2921to = to.strip_escapes();2922line = line.remove_chars("\r\n").strip_edges();29232924return vformat("Line(%d), %s -> %s - LINE \"\"\" %s \"\"\"", current_line, from, to, line);2925}29262927// Prints only full lines e.g.:2928// Line (1) - FULL LINES - """yield(get_tree().create_timer(3), 'timeout')""" =====> """ await get_tree().create_timer(3).timeout """2929String ProjectConverter3To4::simple_line_formatter(int current_line, String old_line, String new_line) {2930if (old_line.size() > 1000) {2931old_line = old_line.substr(0, 997) + "...";2932}2933if (new_line.size() > 1000) {2934new_line = new_line.substr(0, 997) + "...";2935}29362937old_line = old_line.remove_chars("\r\n").strip_edges();2938new_line = new_line.remove_chars("\r\n").strip_edges();29392940return vformat("Line (%d) - FULL LINES - \"\"\" %s \"\"\" =====> \"\"\" %s \"\"\"", current_line, old_line, new_line);2941}29422943// Collects string from vector strings2944String ProjectConverter3To4::collect_string_from_vector(Vector<SourceLine> &vector) {2945String string = "";2946for (int i = 0; i < vector.size(); i++) {2947string += vector[i].line;29482949if (i != vector.size() - 1) {2950string += "\n";2951}2952}2953return string;2954}29552956#endif // DISABLE_DEPRECATED295729582959