-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Update node.ts setSiblingIndex support negative index #17592
Conversation
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.
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
Interface Check ReportThis pull request does not change any public interfaces ! |
@kaokei, Please check the result of
Task Details |
@kaokei, Please check the result of
Task Details |
It will break compatibility. |
@minggo |
My fault. I doesn't break compatibility. And this PR just make code more clear, it doesn't support more index range. As the current implementation also supports -2 and -3. |
@@ -630,7 +630,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { | |||
return; | |||
} | |||
const siblings = this._parent._children; | |||
index = index !== -1 ? index : siblings.length - 1; | |||
index = index >= 0 ? index : siblings.length + index; | |||
const oldIndex = siblings.indexOf(this); |
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.
Would it run well if passing a negative value that smaller than -siblings.length
?
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.
@kaokei
Could you take a look at this question?
If index
< -siblings.length
, for example, it's -siblings.length - 10
,
After this logic index = index >= 0 ? index : siblings.length + index;
The index will be siblings.length + (-siblings.length - 10)
= -10
, -10 will be a invalid index.
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.
It seems splice
will check whether the index is in the range and do a clamp operation.
https://github.com/cocos/cocos-engine/blob/v3.8.5/native/cocos/core/scene-graph/Node.cpp#L347 Also need to modify the cpp code for native platforms. |
@dumganhar |
@kaokei, Please check the result of
Task Details |
@kaokei, Please check the result of
Task Details |
OK, I will be glad to update the cpp code later. |
@kaokei I found you have already updated the cpp code. It looks good. |
@kaokei could you please send it to v3.8.5? Thanks. |
eg. -1 equals siblings.length -1. -2 equals siblings.length -2. -3 equals siblings.length -3.
Force index=0 when index smaller than -siblings.length.
32a86c5
to
f3164f9
Compare
done. @dumganhar |
@cocos-robot run test cases |
@kaokei, Please check the result of
Task Details
|
@kaokei, Please check the result of
Task Details
|
eg.
-1 equals siblings.length -1.
-2 equals siblings.length -2.
-3 equals siblings.length -3.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request:
Greptile Summary
This PR updates the setSiblingIndex method in the Node class to support negative indices for more convenient node positioning within the scene graph.
setSiblingIndex
incocos/scene-graph/node.ts
to handle negative indices