-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Improving code around "Change Type" tool to better respect scripts. #37489
Improving code around "Change Type" tool to better respect scripts. #37489
Conversation
f138108
to
5375244
Compare
I'll also note that I suspect that the |
Apparently `SceneTreeDock::replace_node` duplicates a significant portion of `Node::replace_by`'s `p_keep_data` flag, but then set that flag anyway. This is some sort of code duplication. I set this to false because otherwise the other code should probably be deleted. This is probably to allow undo/redo to work correctly (though that could probably be done simply by setting the flag properly). This then allows two things to function correctly: undo/redo with change type and lets change type function correctly with "script types" (GDScript's with `class_name`s). This certainly breaks something(s).
A portion of the code in Node::replace_by is vestigial and does not actually do anything, both it and the other portion is identical to what was in SceneTreeDock::replace_node. I have refactored the working code of replace_node in to replace_by. I suspect this duplication/copy code should actually be moved even further down the tree into Object (because it is responsible for properties, and the skipping scripts and metadata would make sense in the class responsible for those things. I then elevated the concern of what script the resulting node should have to the "Change Type" code of SceneTreeDock, this seems like the more relevant location to make that decision. The decision is straight forward, if the new type has a script it uses that, if the old node has a script it uses that, then it gives up and uses nothing. This seems to give the best behavior for common use cases. An improved fix for godotengine#37479
5375244
to
e90e991
Compare
Needs rebase 🙃 |
Closing in favor of #91341, which fixes the same issue. |
@KoBeWi As an aside, I stopped bothering trying to contribute to godot when no one replied to this for months, I assumed godot was not interested in outside contributions. And I stopped using godot about a year later. By the time I did get a reply for a rebase two and a half years later I was at a point in my life when I did not have the time to respond. So at four and a half years later, glad to know my attempt to contribute was somewhat appreciated. Good luck! |
An improved fix for #37479 (Change Type does nothing for script "classes")
A portion of the code in
Node::replace_by
is vestigial and does not actually do anything (besides looping over all properties and callingget
), both it and the other portion is identical to what was inSceneTreeDock::replace_node
. I have refactored the working code ofreplace_node
in toreplace_by
. I suspect this duplication/copy code should actually be moved even further down the tree into Object (because it is responsible for properties, and the skipping scripts and metadata would make sense in the class responsible for those things).I then elevated the concern of what script the resulting node should have to the "Change Type" code of SceneTreeDock, this seems like the more relevant location to make that decision. The decision is straight forward, if the new type has a script it uses that, if the old node has a script it uses that, then it gives up and uses nothing. This seems to give the best behavior for common use cases.