Skip to content
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

Conversation

mason-bially
Copy link

@mason-bially mason-bially commented Apr 1, 2020

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 calling get), 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.

@mason-bially mason-bially force-pushed the mjb/master/script-change-refactor branch from f138108 to 5375244 Compare April 1, 2020 10:22
@mason-bially
Copy link
Author

I'll also note that I suspect that the p_remove_old parameter of SceneTreeDock::replace_node is unused and no longer necessary.

@Calinou Calinou added this to the 4.0 milestone Apr 1, 2020
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
@KoBeWi
Copy link
Member

KoBeWi commented Oct 2, 2022

Needs rebase 🙃

@akien-mga akien-mga modified the milestones: 4.0, 4.x Feb 13, 2023
@KoBeWi
Copy link
Member

KoBeWi commented Oct 22, 2024

Closing in favor of #91341, which fixes the same issue.
Thanks for the contribution nonetheless.

@KoBeWi KoBeWi closed this Oct 22, 2024
@KoBeWi KoBeWi removed this from the 4.x milestone Oct 22, 2024
@mason-bially
Copy link
Author

mason-bially commented Oct 22, 2024

@KoBeWi
Happy to help I suppose.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants