From 1c271d00aeb0992714b59605643894d39614d511 Mon Sep 17 00:00:00 2001 From: Marius Hanl Date: Mon, 17 Apr 2023 19:53:50 +0200 Subject: [PATCH] Fix pause_mode may not be converted correctly in .tscn files. --- editor/project_converter_3_to_4.cpp | 26 ++++++++++++++++++++++++-- editor/project_converter_3_to_4.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp index cae055c6c57c..e694f2b088e3 100644 --- a/editor/project_converter_3_to_4.cpp +++ b/editor/project_converter_3_to_4.cpp @@ -399,6 +399,8 @@ bool ProjectConverter3To4::convert() { custom_rename(source_lines, "\\.shader", ".gdshader"); } else if (file_name.ends_with(".tscn")) { + fix_pause_mode(source_lines, reg_container); + rename_classes(source_lines, reg_container); // Using only specialized function. rename_common(RenamesMap3To4::enum_renames, reg_container.enum_regexes, source_lines); @@ -758,6 +760,12 @@ bool ProjectConverter3To4::test_conversion(RegExContainer ®_container) { valid = valid && test_conversion_with_regex("\n tool", "\n tool", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container); valid = valid && test_conversion_with_regex("\n\ntool", "@tool\n\n", &ProjectConverter3To4::fix_tool_declaration, "gdscript keyword", reg_container); + valid = valid && test_conversion_with_regex("pause_mode = 2", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container); + valid = valid && test_conversion_with_regex("pause_mode = 1", "pause_mode = 1", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container); + valid = valid && test_conversion_with_regex("pause_mode = 3", "pause_mode = 3", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container); + valid = valid && test_conversion_with_regex("somepause_mode = 2", "somepause_mode = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container); + valid = valid && test_conversion_with_regex("pause_mode_ext = 2", "pause_mode_ext = 2", &ProjectConverter3To4::fix_pause_mode, "pause_mode", reg_container); + valid = valid && test_conversion_basic("TYPE_REAL", "TYPE_FLOAT", RenamesMap3To4::enum_renames, reg_container.enum_regexes, "enum"); valid = valid && test_conversion_basic("can_instance", "can_instantiate", RenamesMap3To4::gdscript_function_renames, reg_container.gdscript_function_regexes, "gdscript function"); @@ -1441,12 +1449,26 @@ Vector ProjectConverter3To4::check_for_rename_colors(Vector &lin } void ProjectConverter3To4::fix_tool_declaration(Vector &source_lines, const RegExContainer ®_container) { - // In godot4, "tool" became "@tool" and must be located at the top of the file + // In godot4, "tool" became "@tool" and must be located at the top of the file. for (int i = 0; i < source_lines.size(); ++i) { if (source_lines[i].line == "tool") { source_lines.remove_at(i); source_lines.insert(0, { "@tool", false }); - return; // assuming there's at most 1 tool declaration + return; // assuming there's at most 1 tool declaration. + } + } +} + +void ProjectConverter3To4::fix_pause_mode(Vector &source_lines, const RegExContainer ®_container) { + // In Godot 3, the pause_mode 2 equals the PAUSE_MODE_PROCESS value. + // In Godot 4, the pause_mode PAUSE_MODE_PROCESS was renamed to PROCESS_MODE_ALWAYS and equals the number 3. + // We therefore convert pause_mode = 2 to pause_mode = 3. + for (SourceLine &source_line : source_lines) { + String &line = source_line.line; + + if (line == "pause_mode = 2") { + // Note: pause_mode is renamed to process_mode later on, so no need to do it here. + line = "pause_mode = 3"; } } } diff --git a/editor/project_converter_3_to_4.h b/editor/project_converter_3_to_4.h index 134273b4bed6..64106d453502 100644 --- a/editor/project_converter_3_to_4.h +++ b/editor/project_converter_3_to_4.h @@ -72,6 +72,7 @@ class ProjectConverter3To4 { uint64_t maximum_line_length; void fix_tool_declaration(Vector &source_lines, const RegExContainer ®_container); + void fix_pause_mode(Vector &source_lines, const RegExContainer ®_container); void rename_colors(Vector &source_lines, const RegExContainer ®_container); Vector check_for_rename_colors(Vector &lines, const RegExContainer ®_container);