summaryrefslogtreecommitdiffstats
path: root/editor/project_converter_3_to_4.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-06-19 22:34:43 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-06-19 22:34:43 +0200
commit764193629ff0bac11c4a6ddfa946f1dd3d841799 (patch)
tree0f80cd38bf873294c44be9b91edb0f7ee4900934 /editor/project_converter_3_to_4.cpp
parent7ff0a3086def515d725dc64d4719c0f256c7e246 (diff)
parent1c271d00aeb0992714b59605643894d39614d511 (diff)
downloadredot-engine-764193629ff0bac11c4a6ddfa946f1dd3d841799.tar.gz
Merge pull request #76179 from Maran23/pause-mode-convert-fix
Fix `pause_mode` may not be converted correctly in .tscn files.
Diffstat (limited to 'editor/project_converter_3_to_4.cpp')
-rw-r--r--editor/project_converter_3_to_4.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp
index e9af697226..c5c2c9db51 100644
--- a/editor/project_converter_3_to_4.cpp
+++ b/editor/project_converter_3_to_4.cpp
@@ -410,6 +410,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);
@@ -774,6 +776,12 @@ bool ProjectConverter3To4::test_conversion(RegExContainer &reg_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");
@@ -1476,12 +1484,26 @@ Vector<String> ProjectConverter3To4::check_for_rename_colors(Vector<String> &lin
}
void ProjectConverter3To4::fix_tool_declaration(Vector<SourceLine> &source_lines, const RegExContainer &reg_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<SourceLine> &source_lines, const RegExContainer &reg_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";
}
}
}