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

Add NodePath::slice method #81822

Merged
merged 1 commit into from
Feb 29, 2024
Merged

Conversation

nlupugla
Copy link
Contributor

Added slice(begin : int, end : int = INT_MAX) to NodePath.

Example usage:

^"Parent/Child:property".slice(0, -1) # returns ^"Parent/Child"

Closes godotengine/godot-proposals#7148.

Supersedes #78638.

@nlupugla
Copy link
Contributor Author

PS: I'd love if someone could double check my index gymnastics. I tried to be pretty comprehensive with my test cases and was able to catch a few errors that way, but it never hurts to have another pair of eyes. In particular, if anyone can think of a way to make the logic a bit simpler, I'd be very grateful :)

@AThousandShips AThousandShips changed the title Added NodePath::slice method. Add NodePath::slice method Dec 10, 2023
@AThousandShips
Copy link
Member

Maybe add a get_total_name_count to ease the integration

@nlupugla
Copy link
Contributor Author

Maybe add a get_total_name_count to ease the integration

Were you thinking of adding this as an exposed method or just for internal use?

@AThousandShips
Copy link
Member

Initially as just a c++ one, unless also adding a way to access any of the names, surnames or otherwise, with one operation, for convenience

@nlupugla
Copy link
Contributor Author

Initially as just a c++ one, unless also adding a way to access any of the names, surnames or otherwise, with one operation, for convenience

That's not a bad idea and might simplify some of the existing code. That said, I think I'll leave that to a different PR.

I've added a get_total_name_count method as suggested.

Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

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

This looks good to me, it covers my use cases well with slice(0, x), and I think it's a good addition to NodePath.

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Feb 29, 2024
@akien-mga akien-mga merged commit 1cc9190 into godotengine:master Feb 29, 2024
15 checks passed
@akien-mga
Copy link
Member

Thanks!

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
4 participants