Skip to content

Conversation

@aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Jun 24, 2023

Implements this proposal and closes godotengine/godot-proposals#7148

This PR adds a get_partial_path method to NodePath for getting the first X parts of a path. Discussion: Would it be worth specifying the start index too, or getting the last parts of a path? I only need the first parts for my uses.

I added some test cases to ensure the behavior is correct, and I ran into a minor bug where the internal constructors with the StringName arrays will discard the absolute flag if the path is empty. So I added a check to continue with the construction whenever absolute is set to true (return only when absolute is set to false).


NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
if (p_path.size() == 0) {
if (p_path.size() == 0 && !p_absolute) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change and the similar one below? Do I need to include a similar change when making the slice method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was an edge case where p_absolute was being ignored if the path was empty.

@aaronfranke
Copy link
Member Author

Superseded by #81822

@aaronfranke aaronfranke closed this Dec 5, 2023
@aaronfranke aaronfranke removed this from the 4.x milestone Dec 5, 2023
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.

Add a get_partial_path method to NodePath

3 participants