summaryrefslogtreecommitdiff
path: root/editor/project_converter_3_to_4.cpp
diff options
context:
space:
mode:
authorNinni Pipping <over999ships@gmail.com>2023-03-02 15:24:00 +0100
committerYuri Sizov <yuris@humnom.net>2023-03-13 21:28:58 +0100
commitf6709a1fda83c3aec884220a73cb5a2daed3f0ca (patch)
tree00a6dcee12565ebf23d0c76fbec409237712ff88 /editor/project_converter_3_to_4.cpp
parent6041ad5c701b05b7cf3518dfda1cf047333aaeb5 (diff)
Add keycode project conversion
(cherry picked from commit fec630f360b93fa221acb7d47efd7aa9b1605801)
Diffstat (limited to 'editor/project_converter_3_to_4.cpp')
-rw-r--r--editor/project_converter_3_to_4.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp
index 5ff438db8f..feb5edcdeb 100644
--- a/editor/project_converter_3_to_4.cpp
+++ b/editor/project_converter_3_to_4.cpp
@@ -139,6 +139,9 @@ public:
LocalVector<RegEx *> class_gd_regexes;
LocalVector<RegEx *> class_shader_regexes;
+ // Keycode.
+ RegEx input_map_keycode = RegEx("\\b,\"((physical_)?)scancode\":(\\d+)\\b");
+
LocalVector<RegEx *> class_regexes;
RegEx class_temp_tscn = RegEx("\\bTEMP_RENAMED_CLASS.tscn\\b");
@@ -415,6 +418,7 @@ bool ProjectConverter3To4::convert() {
} else if (file_name.ends_with("project.godot")) {
rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, lines);
rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines);
+ rename_input_map_scancode(lines, reg_container);
rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, lines);
} else if (file_name.ends_with(".csproj")) {
// TODO
@@ -587,6 +591,7 @@ bool ProjectConverter3To4::validate_conversion() {
} else if (file_name.ends_with("project.godot")) {
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::project_godot_renames, reg_container.project_godot_regexes, lines));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::builtin_types_renames, reg_container.builtin_types_regexes, lines));
+ changed_elements.append_array(check_for_rename_input_map_scancode(lines, reg_container));
changed_elements.append_array(check_for_rename_common(RenamesMap3To4::input_map_renames, reg_container.input_map_regexes, lines));
} else if (file_name.ends_with(".csproj")) {
// TODO
@@ -916,6 +921,10 @@ bool ProjectConverter3To4::test_conversion(RegExContainer &reg_container) {
valid = valid && test_conversion_with_regex("AAA Color.white AF", "AAA Color.WHITE AF", &ProjectConverter3To4::rename_colors, "custom rename", reg_container);
+ // Note: Do not change to *scancode*, it is applied before that conversion.
+ valid = valid && test_conversion_with_regex("\"device\":-1,\"scancode\":16777231,\"physical_scancode\":16777232", "\"device\":-1,\"scancode\":4194319,\"physical_scancode\":4194320", &ProjectConverter3To4::rename_input_map_scancode, "custom rename", reg_container);
+ valid = valid && test_conversion_with_regex("\"device\":-1,\"scancode\":65,\"physical_scancode\":66", "\"device\":-1,\"scancode\":65,\"physical_scancode\":66", &ProjectConverter3To4::rename_input_map_scancode, "custom rename", reg_container);
+
// Custom rule conversion
{
String from = "instance";
@@ -2499,6 +2508,59 @@ Vector<String> ProjectConverter3To4::check_for_rename_gdscript_keywords(Vector<S
return found_renames;
}
+void ProjectConverter3To4::rename_input_map_scancode(Vector<String> &lines, const RegExContainer &reg_container) {
+ // The old Special Key, now colliding with CMD_OR_CTRL.
+ const int old_spkey = (1 << 24);
+
+ for (String &line : lines) {
+ if (uint64_t(line.length()) <= maximum_line_length) {
+ TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
+
+ for (int i = 0; i < reg_match.size(); ++i) {
+ Ref<RegExMatch> match = reg_match[i];
+ PackedStringArray strings = match->get_strings();
+ int key = strings[3].to_int();
+
+ if (key & old_spkey) {
+ // Create new key, clearing old Special Key and setting new one.
+ key = (key & ~old_spkey) | (int)Key::SPECIAL;
+
+ line = line.replace(strings[0], String(",\"") + strings[1] + "scancode\":" + String::num_int64(key));
+ }
+ }
+ }
+ }
+}
+
+Vector<String> ProjectConverter3To4::check_for_rename_input_map_scancode(Vector<String> &lines, const RegExContainer &reg_container) {
+ Vector<String> found_renames;
+
+ // The old Special Key, now colliding with CMD_OR_CTRL.
+ const int old_spkey = (1 << 24);
+
+ int current_line = 1;
+ for (String &line : lines) {
+ if (uint64_t(line.length()) <= maximum_line_length) {
+ TypedArray<RegExMatch> reg_match = reg_container.input_map_keycode.search_all(line);
+
+ for (int i = 0; i < reg_match.size(); ++i) {
+ Ref<RegExMatch> match = reg_match[i];
+ PackedStringArray strings = match->get_strings();
+ int key = strings[3].to_int();
+
+ if (key & old_spkey) {
+ // Create new key, clearing old Special Key and setting new one.
+ key = (key & ~old_spkey) | (int)Key::SPECIAL;
+
+ found_renames.append(line_formatter(current_line, strings[3], String::num_int64(key), line));
+ }
+ }
+ }
+ current_line++;
+ }
+ return found_renames;
+}
+
void ProjectConverter3To4::custom_rename(Vector<String> &lines, String from, String to) {
RegEx reg = RegEx(String("\\b") + from + "\\b");
CRASH_COND(!reg.is_valid());