-
-
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
Add get_connection_count
function to GraphEdit
#99564
Add get_connection_count
function to GraphEdit
#99564
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
You forgot to bind the method. |
ed0ca8c
to
8b3d8bc
Compare
Thanks for the comment, I was a bit hasty, fixed |
I generated documentation with --doctool but the function disappeared from GraphEdit.xml, what could be the reason? |
Did you build the editor before running doctool? |
Yes, I compiled godot.windows.editor.x86_64.exe in the bin folder, and ran it as bin\godot.windows.editor.x86_64.exe --doctool |
Then did it vanish or did it get moved to the correct position? |
This comment was marked as resolved.
This comment was marked as resolved.
That's the version without binding the method so it won't show up, you need to rebuild with it bound |
8b3d8bc
to
d21b421
Compare
Thanks @AThousandShips , I think the PR is ready now (If CI doesn't have problems again) |
d21b421
to
3dfad59
Compare
This comment was marked as resolved.
This comment was marked as resolved.
You pressed the button to add the changes on GitHub, which creates commits on its own, you will need to squash the changes when you're done |
This comment was marked as resolved.
This comment was marked as resolved.
You need to pull the changes first, you can just make the changes locally and use |
2b27176
to
a809bab
Compare
Everything is finally ready! Thanks again for your help |
I'll let the GUI team review this but the code looks good |
doc/classes/GraphEdit.xml
Outdated
<param index="0" name="from_node" type="StringName" /> | ||
<param index="1" name="from_port" type="int" /> | ||
<description> | ||
Returns the number of connections from [param from_node] to [param from_port] port. |
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.
Returns the number of connections from [param from_node] to [param from_port] port. | |
Returns the number of connections from [param from_port] of [param from_node]. |
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.
Since I've had a lot of trouble with commit suggestions in the past, to commit and not create a new commit, should I click Commit suggestion or add suggestion to batch ? 😅
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.
Adding to batch will just add one commit for all suggestions. You have to manually copy the suggestion if you want to avoid GitHub's commits.
scene/gui/graph_edit.cpp
Outdated
int GraphEdit::get_connection_count(const StringName &p_node, int p_port) { | ||
int count = 0; | ||
for (const Ref<Connection> &conn : connections) { | ||
if ((conn->to_node == p_node || conn->from_node == p_node) && (conn->to_port == p_port || conn->from_port == p_port)) { |
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.
I'm not sure if this condition is correct. E.g. if to_node
is p_node
and from_port
is p_port
(in another node), it could count a connection to another port.
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.
This allows us to check the right ports as well as the left ones, without this only the left or right port is counted
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 test project did not reveal any problems, this allows us, for example, to test one node that is connected to itself, from left to right, which is the correct behavior. Since we should count any connections
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.
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.
This is actually happening... I had an idea to create two functions, to check from_node from_port
and to_node to_port
, but it seems redundant, what else can I come up with to fix this, any tips?
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.
You just have to rearrange your condition, so it always checks the correct port, i.e. use from_port
only if connecting from this node and to_port
if connecting to this node.
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.
You just have to rearrange your condition, so it always checks the correct port, i.e. use
from_port
only if connecting from this node andto_port
if connecting to this node.
The logic for checking the condition has been changed, now it works as expected
This comment was marked as resolved.
This comment was marked as resolved.
d8e32df
to
4ac3cd3
Compare
f6c696b
to
7d7ed0f
Compare
I broke everything... Is it possible to create a new clean PR? |
I would suggest figuring out how to fix it instead, these kinds of mistakes will happen now and again and it's important to not lose the discussion and feedback in a PR by closing one instead of resolving those issues In this case you should just revert it by using |
7d7ed0f
to
7b0ceae
Compare
7b0ceae
to
17f0573
Compare
scene/gui/graph_edit.cpp
Outdated
int GraphEdit::get_connection_count(const StringName &p_node, int p_port) { | ||
int count = 0; | ||
for (const Ref<Connection> &conn : connections) { | ||
if ((conn->from_node == p_node && conn->from_port == p_node) || (conn->to_node == p_node && conn->to_port == p_port)) { |
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.
if ((conn->from_node == p_node && conn->from_port == p_node) || (conn->to_node == p_node && conn->to_port == p_port)) { | |
if ((conn->from_node == p_node && conn->from_port == p_port) || (conn->to_node == p_node && conn->to_port == p_port)) { |
17f0573
to
8865c0f
Compare
get_connection_count
function to GraphEdit
This PR was like a Git exam for me, but thanks to AThousandShips' tips, I got through it without opening a third PR, thanks! All recommended edits have been applied, now this PR is DEFINITELY READY 🎉 |
Once this has been approved please also remove the Will approve once someone from the GUI/GraphEdit team gives their approval |
Can I change this now?, before something weird happens to my Git :D Should I use |
That would be the way yes! |
8865c0f
to
95ca0aa
Compare
Ready |
Thanks! Congratulations on your first merged contribution! 🎉 |
This is my second attempt at this PR, the first one had problems with Git.
Closes: godotengine/godot-proposals#10942
Adds a method to GraphEdit to get the number of connections to a given node and port
get_connection_count(to_node,to_port)
.With this we can easily limit the number of connections using the condition:
Test project:
graphedit_test_func.zip