-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Godot 3.x -> Godot 4.0 project converter #51950
Conversation
e12e414
to
3d4585a
Compare
This comment has been minimized.
This comment has been minimized.
Hey @qarmin I think some of the ones that are commented out that are ambiguous are kind of important and probably better to assume the common case. For example, I consider Control.get_icon->get_theme_icon to be worth doing automatically, even though there are some rare cases in the Theme class and the TreeItem class that this would break. FuncRef -> Callable is another one that needs to be addressed There are many patterns that would be nice to do if we had a place to add more general purpose regular expressions that don't fit neatly into the functions or methods buckets: Here are some regexes to handle cases I found to be common in my code, such as ("\\.xform", "*"), # Transform3D
(r"([\w.]+)\s*\.\s*xform_inv\s*([^)]*)", r"((\2) * (\1))"), # Transform3D
("pause_mode = 2", "process_mode = "),
("pause_mode", "process_mode"),
(r"\b(connect|disconnect|is_connected)(\s*)\((\s*)([^,]*),(\s*)(?!Callable)([^,\s][^,]*),([^,]*)([,)])", r"\1\2(\3\4,\5Callable(\6,\7)\8"),
(r"\byield\s*\((.*?)\)\s*$|\byield (.*)$", "await \\1\\2"),
(r"\byield\s*\(\s*(\S[\s\S]*?)(\s*,\s*)*[\"'](.*)[\"']\s*\)\s*$", "await \\1.\\3"),
(r"\b@?master(\s*)func\b", "@rpc(master)\\1func"),
(r"\b@?puppet(\s*)func\b", "@rpc(puppet)\\1func"),
(r"\b@?remote(\s*)func\b", "@rpc(any)\\1func"),
(r"\b@?remotesync(\s*)func\b", "@rpc(any,sync)\\1func"),
(r"\bfunc(\s+)_init(\s*)\(([^)]*)\)[^:]*:", r"func\1_init\2(\3):"),
(r"\bget_node(\s+)\((\s+)\@", r"get_node\1(\2^"), These replacements would be only for EditorPlugin: adding the missing _ to some of the overridable functions like get_name and so on. (r"\bfunc(\s+)edit\b", r'func\1_edit', ['EditorPlugin']),
(r"\bfunc(\s+)get_name\b", r'func\1_get_plugin_name', ['EditorPlugin']),
(r"\bfunc(\s+)handles\b", r'func\1_handles', ['EditorPlugin']),
(r"\bfunc(\s+)make_visible\b", r'func\1_make_visible', ['EditorPlugin']), Finally some for
My python script here has a bunch of code to handle that. The export one breaks in a few cases, for example if the line contains a comma. Replacing setget seems moderately reliable. Clearly I can understand if these heuristics and regexes wouldn't make it in, but I just want to get the discussion going on some other legitimately useful changes. With all of my regexes as well as the function&class name replacements which your change does well, it usually only requires a few small edits and replaces to fix the rest. The biggest one that my regex usually messes up is mismatching parentheses on the connect syntax, when used like if (something.connect("signal", self, "method")==OK) |
This PR should be created in my repository, because for now there is 2 different PR which implements a little different functions(I added new commit yesterday and I will add probably another today).
Non casual renames like e.g. |
@qarmin Apologies, I seem to have done a poor job communicating. I only created that draft PR as a way to publish the diff on top of your PR so that you could merge in the changes. Since there are a few things to fix from my commit, I'll post them here and close my draft PR: These are wrong and should probably be removed:
The closest analogy for invert is "reverse" but it no longer returns the array, so it's not a drop-in replacement. I'd perhaps still suggest changing invert to reverse and leave the user to fix the return value error. Here are more safe functions from my PR that I would like added (I know enabled_focus_mode isn't one-to-one with focus_mode but it internally calls focus_mode in most cases so it should be as close as you can get):
Properties in patch form: diff --git a/editor/converter.cpp b/editor/converter.cpp
index 3ae8c6883f74..3fcf17db5500 100644
--- a/editor/converter.cpp
+++ b/editor/converter.cpp
@@ -351,19 +380,27 @@ static const char *properties_renames[][2] = {
// {"Skeleton3D","Skeleton"}, // Polygon2D - this would rename also classes
// {"rotate","rotates"}, // PathFollow2D - probably function exists with same name
{ "Debug Shape3D", "Debug Shape" }, // RayCast3D
+ { "doubleclick", "double_click" }, // InputEventMouseButton
{ "Emission Shape3D", "Emission Shape" }, // ParticlesMaterial
+ { "enabled_focus_mode", "focus_mode" }, // BaseButton - Removed
+ { "as_normalmap", "as_normal_map" }, // NoiseTexture
{ "caret_moving_by_right_click", "caret_move_on_right_click" }, // TextEdit
- { "d", "disatance" }, //WorldMarginShape2D
+ { "d", "distance" }, //WorldMarginShape2D
{ "global_rate_scale", "playback_speed_scale" }, // AudioServer
{ "group", "button_group" }, // BaseButton
+ { "popup_exclusive", "exclusive" }, //Window
{ "region_filter_clip", "region_filter_clip_enabled" }, // Sprite2D
{ "syntax_highlighting", "syntax_highlighter" }, // TextEdit
+ { "toplevel", "top_level" }, // Node
{ "translation", "position" }, // Node3D - broke GLTFNode
+ { "zfar", "far" }, // Camera3D
+ { "znear", "near" }, // Camera3D
{ nullptr, nullptr },
}; new signal:
not sure about these:
the first one is unlikely. the second one might show up due to GDNative. it's probably best to leave them as is instead of replacing with Node3D. |
89e763b
to
1fe9925
Compare
I changed code according to suggestions. Now I started to create manual regex for each specific function (like connect -> Callable) This is how it looks in code
so it shouldn't be too hard to create, since I use builtin in Godot regex object.
|
882d890
to
bb73963
Compare
@lyuma can you add real life examples(or even simplified) about your regex's from above/python script?
than
|
In this example, cyclic renames could be handled by renaming |
Adding support for this, probably will require to add new array/function. |
dbaa796
to
acf79ac
Compare
Where is this method used exactly in this PR? I don't see any code that calls If it's not directly needed right now, it might be easier to merge the rest of the converter as agreeing on how to expose |
acf79ac
to
72fb23f
Compare
I expected that this code will find more breaking changes, but looks that not found any(at least yet), so it is not so important as I think that it would be. I commented this code. |
72fb23f
to
a972595
Compare
a972595
to
a9bf33b
Compare
Not certain this is the best place to put it, but if not I moved that over to the correct issue/proposal/discussion. 😅 If you want to add an Open Source project to test it on and compare with a real life conversion : Wish you the best, have a great weekend ^^ |
What are the blockers on merging this in a timely matter now? |
Does the converter support theme property renames? Several theme properties were renamed in #60261, and there may be others as well. |
a9bf33b
to
4aa6223
Compare
One more shader rename that could be added: |
4aa6223
to
6062975
Compare
6062975
to
24f45bd
Compare
I pushed an update to improve some names:
And fixed build with RegEx module disabled. |
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.
It's a pretty good start for converting projects. There are more conversions that can be added in future PRs, and still some manual work needed, but it does make it possible to open a fairly big project like Jetpaca in 4.0 and run it (with bugs) and with minor manual script changes.
Thanks! |
Is this the right place to submit remaining methods which still need to be included in the converter as of Beta12? |
@golddotasksquestions I think that you should just open a ticket. |
Implementation of project converter(currently 3.x -> 4.0, but it can be easily upgraded to handle new versions) godotengine/godot-proposals#387
This PR contains #49053, so it would be good to merge that PR before this because it is needed to check if all functions exists even in builtin types.Most of things are renamed by "whole word" feature and some with simple Regex.
Before conversion I suggest to use this tool - https://github.com/Scony/godot-gdscript-toolkit to unify code look with some big line length(converter doesn't support multi line expressions and won't support, because it would be too complicated) - e.g.
find ./ | grep "\.gd$" | xargs gdformat --line-length 400
For me this is the best way to upgrade project:
godot4 --validation-conversion-3to4 --headless
(current directory must contains godot project)godot4 --convert-3to4 --headless
Also during converting, this text about current progress is printing to console
Done things:
connect
->Callable
) - only some, but can be easily addedThings which may be implemented in future
Problematic things:
choose_it
change toselect_this
, but Node3D changesselect_this
tochoose_it
. So running tool, will renames allselect_this
functions tochoose_it
(assuming that this records have bigger index infunction_renames
array). Depends of the usage, some things may be renamed(this will broke other functions) when class is used more(like Node3D vs HTTPRequest).Geometry
were split at two classesGeometry2D
andGeometry3D
, so all instances ofGeometry
are renamed toGeometry2D
. If proper class isGeometry3D
, then this needs to be fixed manuallycall_deffered
which use little different syntax, won't be always fully renamed.alt
. Renaming them, would broke a lot of users scripts, because this words are usable often.Tested projects:
String && bool
(GDScript), nill objects(GDScript)to_lower
not found in StringName(GDScript)parse_dictionary
(GDScript)Legend:
How to find functions that needs to be converted
classes.txt
which contains info about almost all possible functions, classes, enums etc.)project.godot
inside this foldergodot4 --convert-to-godot40 --headless
(This will convert all things from.gd
files)classes3.gd
withclasses4.txt
etc. with Meldapt install meld