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