-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 3to4 conversions (thread arguments, OS.window_fullscreen and await) #63299
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1968,7 +1968,7 @@ bool ProjectConverter3To4::test_conversion() { | |
valid = valid & test_conversion_single_additional("(Disconnect(A,B,C) != OK):", "(Disconnect(A,new Callable(B,C)) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename csharp"); | ||
valid = valid & test_conversion_single_additional("(IsConnected(A,B,C) != OK):", "(IsConnected(A,new Callable(B,C)) != OK):", &ProjectConverter3To4::rename_csharp_functions, "custom rename"); | ||
|
||
valid = valid & test_conversion_single_additional("OS.window_fullscreen = Settings.fullscreen", "ProjectSettings.set(\"display/window/size/fullscreen\", Settings.fullscreen)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("OS.window_fullscreen = Settings.fullscreen", "ProjectSettings.set(\\\"display/window/size/fullscreen\\\", Settings.fullscreen)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
||
valid = valid & test_conversion_single_additional("\tvar aa = roman(r.move_and_slide( a, b, c, d, e, f )) # Roman", "\tr.set_motion_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# TODOConverter40 infinite_inertia were removed in Godot 4.0 - previous value `f`\n\tvar aa = roman(r.move_and_slide()) # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("\tvar aa = roman(r.move_and_slide_with_snap( a, g, b, c, d, e, f )) # Roman", "\tr.set_motion_velocity(a)\n\t# TODOConverter40 looks that snap in Godot 4.0 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# TODOConverter40 infinite_inertia were removed in Godot 4.0 - previous value `f`\n\tvar aa = roman(r.move_and_slide()) # Roman", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
@@ -2015,7 +2015,7 @@ bool ProjectConverter3To4::test_conversion() { | |
|
||
valid = valid & test_conversion_single_additional("get_node(@", "get_node(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
||
valid = valid & test_conversion_single_additional("yield(this, \"timeout\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("yield(this, \\\"timeout\\\")", "await this.timeout", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
||
valid = valid & test_conversion_single_additional(" Transform.xform(Vector3(a,b,c)) ", " Transform * Vector3(a,b,c) ", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional(" Transform.xform_inv(Vector3(a,b,c)) ", " Vector3(a,b,c) * Transform ", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
@@ -2043,7 +2043,8 @@ bool ProjectConverter3To4::test_conversion() { | |
valid = valid & test_conversion_single_additional("'.a'", "'.a'", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("\t._input(_event)", "\tsuper._input(_event)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
||
valid = valid & test_conversion_single_additional("(start(A,B,C,D,E,F,G) != OK):", "(start(A,Callable(B,C),D,E,F,G) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("(start(A,B) != OK):", "(start(Callable(A,B)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("(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"); | ||
valid = valid & test_conversion_single_additional("(connect(A,B,C,D,E,F,G) != OK):", "(connect(A,Callable(B,C),D,E,F,G) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("(connect(A,B,C) != OK):", "(connect(A,Callable(B,C)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
valid = valid & test_conversion_single_additional("disconnect(A,B,C) != OK):", "disconnect(A,Callable(B,C)) != OK):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename"); | ||
|
@@ -2706,7 +2707,7 @@ void ProjectConverter3To4::rename_gdscript_functions(String &file_content) { | |
line = reg_setget_get.sub(line, "var $1$2:\n\tget:\n\t\treturn $1 # TODOConverter40 Copy here content of $3 \n\tset(mod_value):\n\t\tmod_value # TODOConverter40 Non existent set function", true); | ||
|
||
// OS.window_fullscreen = true -> ProjectSettings.set("display/window/size/fullscreen",true) | ||
line = reg_os_fullscreen.sub(line, "ProjectSettings.set(\"display/window/size/fullscreen\", $1)", true); | ||
line = reg_os_fullscreen.sub(line, "ProjectSettings.set(\\\"display/window/size/fullscreen\\\", $1)", true); | ||
|
||
// -- r.move_and_slide( a, b, c, d, e ) -> r.set_motion_velocity(a) ... r.move_and_slide() KinematicBody | ||
if (line.find("move_and_slide(") != -1) { | ||
|
@@ -2862,7 +2863,7 @@ void ProjectConverter3To4::rename_gdscript_functions(String &file_content) { | |
if (end > -1) { | ||
Vector<String> parts = parse_arguments(line.substr(start, end)); | ||
if (parts.size() == 2) { | ||
line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start); | ||
line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\\\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start); | ||
} | ||
} | ||
} | ||
|
@@ -2941,14 +2942,17 @@ void ProjectConverter3To4::rename_gdscript_functions(String &file_content) { | |
} | ||
} | ||
} | ||
// -- start(a,b,c) -> start(a,Callable(b,c)) Thread | ||
// -- start(a,b) -> start(Callable(a,b)) Thread | ||
// -- start(a,b,c,d) -> start(Callable(a,b).bind(c,d)) Thread | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Threads in 3.x can take only one userdata argument. |
||
if (line.find("start(") != -1) { | ||
int start = line.find("start("); | ||
int end = get_end_parenthess(line.substr(start)) + 1; | ||
if (end > -1) { | ||
Vector<String> parts = parse_arguments(line.substr(start, end)); | ||
if (parts.size() >= 3) { | ||
line = line.substr(0, start) + "start(" + parts[0] + ",Callable(" + parts[1] + "," + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start); | ||
if (parts.size() == 2) { | ||
line = line.substr(0, start) + "start(Callable(" + parts[0] + "," + parts[1] + "))" + line.substr(end + start); | ||
} else if (parts.size() >= 3) { | ||
line = line.substr(0, start) + "start(Callable(" + parts[0] + "," + parts[1] + ").bind(" + connect_arguments(parts, 2).substr(1) + "))" + line.substr(end + start); | ||
} | ||
} | ||
} | ||
|
@@ -3148,7 +3152,7 @@ Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector< | |
line = reg_setget_get.sub(line, "var $1$2:\n\tget:\n\t\treturn $1 # TODOConverter40 Copy here content of $3 \n\tset(mod_value):\n\t\tmod_value # TODOConverter40 Non existent set function", true); | ||
|
||
// OS.window_fullscreen = true -> ProjectSettings.set("display/window/size/fullscreen",true) | ||
line = reg_os_fullscreen.sub(line, "ProjectSettings.set(\"display/window/size/fullscreen\", $1)", true); | ||
line = reg_os_fullscreen.sub(line, "ProjectSettings.set(\\\"display/window/size/fullscreen\\\", $1)", true); | ||
|
||
// -- r.move_and_slide( a, b, c, d, e ) -> r.set_motion_velocity(a) ... r.move_and_slide() KinematicBody | ||
if (line.find("move_and_slide(") != -1) { | ||
|
@@ -3295,7 +3299,7 @@ Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector< | |
if (end > -1) { | ||
Vector<String> parts = parse_arguments(line.substr(start, end)); | ||
if (parts.size() == 2) { | ||
line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start); | ||
line = line.substr(0, start) + "await " + parts[0] + "." + parts[1].replace("\\\"", "").replace("\'", "").replace(" ", "") + line.substr(end + start); | ||
} | ||
} | ||
} | ||
|
@@ -3370,14 +3374,17 @@ Vector<String> ProjectConverter3To4::check_for_rename_gdscript_functions(Vector< | |
} | ||
} | ||
} | ||
// -- start(a,b,c) -> start(a,Callable(b,c)) Thread | ||
// -- start(a,b) -> start(Callable(a,b)) Thread | ||
// -- start(a,b,c,d) -> start(Callable(a,b).bind(c,d)) Thread | ||
if (line.find("start(") != -1) { | ||
int start = line.find("start("); | ||
int end = get_end_parenthess(line.substr(start)) + 1; | ||
if (end > -1) { | ||
Vector<String> parts = parse_arguments(line.substr(start, end)); | ||
if (parts.size() >= 3) { | ||
line = line.substr(0, start) + "start(" + parts[0] + ",Callable(" + parts[1] + "," + parts[2] + ")" + connect_arguments(parts, 3) + ")" + line.substr(end + start); | ||
if (parts.size() == 2) { | ||
line = line.substr(0, start) + "start(Callable(" + parts[0] + "," + parts[1] + "))" + line.substr(end + start); | ||
} else if (parts.size() >= 3) { | ||
line = line.substr(0, start) + "start(Callable(" + parts[0] + "," + parts[1] + ").bind(" + connect_arguments(parts, 2).substr(1) + ")" + line.substr(end + start); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem happens probably only in builtin scripts, so should be fixed only there - otherwise it will broke normal .gd files(not tested yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Built-in scripts should be unescaped before conversion, if they aren't already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I've totally forgotten that scripts should not be unescaped since they're plaintext. Still, I cannot confirm that built-in scripts are unescaped, i. e. @KoBeWi I can still observe #63291 in the latest master. But I agree that the best solution would be to unescape all built-in scripts before conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between
rename_gdscript_functions
andcheck_for_rename_gdscript_functions
btw? Their code seems almost identical (except for the return value).EDIT: I can see there's a check in
project_converter_3_to_4.cpp:1665
which differentiates.gd
and.tscn
files. Should we probably introduce an extra argument torename_gdscript_functions
such asis_builtin
? This way we could control the behavior of quote escaping insiderename_gdscript_functions
. It would also make sense to callrename_gdscript_functions
inside the.tres
branch several lines below (since resources may also contain built-in scripts).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check_for_rename_gdscript_functions
additionally prints exactly in which line change will happen.At beginning it was very different than
rename_gdscript_functions
, but I unified this one day, so there is a lot of duplicated code, which could be extracted to another function, but when I tried to do it I failed due some strange Regex memory leaks(this shouldn't be too hard to fix)I think that adding
is_builtin
is good solution, but this probably will be only needed by custom renames that use " inside regex e.g.but not with