fix(core): node dispose should trigger parent transform change (#436)

This commit is contained in:
Louis Young 2025-07-01 20:02:11 +08:00 committed by GitHub
parent cbefaa54fb
commit 2d5fac776a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,7 +48,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
clearChildren(): void { clearChildren(): void {
if (this._children) { if (this._children) {
this._children.slice().forEach(child => { this._children.slice().forEach((child) => {
child.setParent(undefined); child.setParent(undefined);
}); });
} }
@ -341,7 +341,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
get bounds(): Rectangle { get bounds(): Rectangle {
if (this.isContainer) { if (this.isContainer) {
const children = this._children!; const children = this._children!;
return Rectangle.enlarge(children.map(c => c.bounds)); return Rectangle.enlarge(children.map((c) => c.bounds));
} }
return Bounds.getBounds(this, this.worldTransform); return Bounds.getBounds(this, this.worldTransform);
} }
@ -369,7 +369,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
get localSize(): SizeSchema { get localSize(): SizeSchema {
let { size } = this; let { size } = this;
if (this.isContainer) { if (this.isContainer) {
const childrenBounds = Rectangle.enlarge(this.children.map(c => c.localBounds)); const childrenBounds = Rectangle.enlarge(this.children.map((c) => c.localBounds));
size = { size = {
width: childrenBounds.width, width: childrenBounds.width,
height: childrenBounds.height, height: childrenBounds.height,
@ -396,12 +396,12 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
get localBounds(): Rectangle { get localBounds(): Rectangle {
if (this.isContainer) { if (this.isContainer) {
const children = this._children!; const children = this._children!;
const childrenBounds = Rectangle.enlarge(children.map(c => c.localBounds)); const childrenBounds = Rectangle.enlarge(children.map((c) => c.localBounds));
// 投射 local // 投射 local
return Bounds.applyMatrix(childrenBounds, this.localTransform); return Bounds.applyMatrix(childrenBounds, this.localTransform);
} }
return this.getMutationCache<Rectangle>('localBounds', () => return this.getMutationCache<Rectangle>('localBounds', () =>
Bounds.getBounds(this, this.localTransform), Bounds.getBounds(this, this.localTransform)
); );
} }
@ -478,6 +478,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
const index = parent._children!.indexOf(this); const index = parent._children!.indexOf(this);
if (index !== -1) { if (index !== -1) {
parent._children!.splice(index, 1); parent._children!.splice(index, 1);
parent.fireChange();
} }
}), }),
]); ]);
@ -496,7 +497,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
this.boundsWithoutRotation, this.boundsWithoutRotation,
this.worldRotation, this.worldRotation,
rect, rect,
0, 0
); );
} }
@ -571,7 +572,7 @@ export class TransformData extends EntityData<TransformSchema> implements Transf
sizeToScaleValue( sizeToScaleValue(
size: { width: number; height: number }, size: { width: number; height: number },
isWorldSize?: boolean, isWorldSize?: boolean
): { x: number; y: number } { ): { x: number; y: number } {
return { return {
x: this.widthToScaleX(size.width, isWorldSize), x: this.widthToScaleX(size.width, isWorldSize),