diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 7f36688207a..749b7a2bf3f 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -159,3 +159,5 @@ rules: '@typescript-eslint/explicit-function-return-type': [error, { allowIIFEs: true, # IIFEs are widely used, writing their signature twice is painful }] + + '@typescript-eslint/no-this-alias': off diff --git a/cocos/2d/components/sprite.ts b/cocos/2d/components/sprite.ts index 794bd6eafd9..ce12e123ff7 100644 --- a/cocos/2d/components/sprite.ts +++ b/cocos/2d/components/sprite.ts @@ -596,44 +596,49 @@ export class Sprite extends UIRenderer { } protected _flushAssembler (): void { - const assembler = Sprite.Assembler.getAssembler(this); + const self = this; + const assembler = Sprite.Assembler.getAssembler(self); - if (this._assembler !== assembler) { - this.destroyRenderData(); - this._assembler = assembler; + if (self._assembler !== assembler) { + self.destroyRenderData(); + self._assembler = assembler; } - if (!this._renderData) { - if (this._assembler && this._assembler.createData) { - this._renderData = this._assembler.createData(this); - this._renderData!.material = this.getRenderMaterial(0); - this.markForUpdateRenderData(); - if (this.spriteFrame) { - this._assembler.updateUVs(this); + if (!self._renderData) { + if (assembler && assembler.createData) { + const rd = self._renderData = assembler.createData(self); + rd.material = self.getRenderMaterial(0); + self.markForUpdateRenderData(); + if (self.spriteFrame) { + assembler.updateUVs(self); } - this._updateColor(); + self._updateColor(); } } // Only Sliced type need update uv when sprite frame insets changed - if (this._spriteFrame) { - if (this._type === SpriteType.SLICED) { - this._spriteFrame.on(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this); + const spriteFrame = self._spriteFrame; + if (spriteFrame) { + if (self._type === SpriteType.SLICED) { + spriteFrame.on(SpriteFrameEvent.UV_UPDATED, self._updateUVs, self); } else { - this._spriteFrame.off(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this); + spriteFrame.off(SpriteFrameEvent.UV_UPDATED, self._updateUVs, self); } } } private _applySpriteSize (): void { - if (this._spriteFrame) { - if (BUILD || !this._spriteFrame.isDefault) { - if (SizeMode.RAW === this._sizeMode) { - const size = this._spriteFrame.originalSize; - this.node._uiProps.uiTransformComp!.setContentSize(size); - } else if (SizeMode.TRIMMED === this._sizeMode) { - const rect = this._spriteFrame.rect; - this.node._uiProps.uiTransformComp!.setContentSize(rect.width, rect.height); + const self = this; + const spriteFrame = self._spriteFrame; + if (spriteFrame) { + if (BUILD || !spriteFrame.isDefault) { + const uiProps = self.node._uiProps; + if (SizeMode.RAW === self._sizeMode) { + const size = spriteFrame.originalSize; + uiProps.uiTransformComp!.setContentSize(size); + } else if (SizeMode.TRIMMED === self._sizeMode) { + const rect = spriteFrame.rect; + uiProps.uiTransformComp!.setContentSize(rect.width, rect.height); } } } @@ -685,10 +690,11 @@ export class Sprite extends UIRenderer { } private _applySpriteFrame (oldFrame: SpriteFrame | null): void { - const spriteFrame = this._spriteFrame; + const self = this; + const spriteFrame = self._spriteFrame; - if (oldFrame && this._type === SpriteType.SLICED) { - oldFrame.off(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this); + if (oldFrame && self._type === SpriteType.SLICED) { + oldFrame.off(SpriteFrameEvent.UV_UPDATED, self._updateUVs, self); } let textureChanged = false; @@ -697,23 +703,23 @@ export class Sprite extends UIRenderer { textureChanged = true; } if (textureChanged) { - if (this.renderData) this.renderData.textureDirty = true; + if (self.renderData) self.renderData.textureDirty = true; // texture type changed, set this._instanceMaterialType to default value const oldIsRT = oldFrame ? oldFrame.texture instanceof RenderTexture : false; const newIsRT = spriteFrame.texture instanceof RenderTexture; if (oldIsRT !== newIsRT) { - this._instanceMaterialType = -1; + self._instanceMaterialType = -1; } - this.changeMaterialForDefine(); + self.changeMaterialForDefine(); } - this._applySpriteSize(); - if (this._type === SpriteType.SLICED) { - spriteFrame.on(SpriteFrameEvent.UV_UPDATED, this._updateUVs, this); + self._applySpriteSize(); + if (self._type === SpriteType.SLICED) { + spriteFrame.on(SpriteFrameEvent.UV_UPDATED, self._updateUVs, self); } } if (EDITOR) { - this._applyAtlas(spriteFrame); + self._applyAtlas(spriteFrame); } } diff --git a/cocos/2d/event/pointer-event-dispatcher.ts b/cocos/2d/event/pointer-event-dispatcher.ts index b113538cf38..d9e6b0c3126 100644 --- a/cocos/2d/event/pointer-event-dispatcher.ts +++ b/cocos/2d/event/pointer-event-dispatcher.ts @@ -251,8 +251,8 @@ class PointerEventDispatcher implements IEventDispatcher { } } - const priority1 = n1 ? n1.getSiblingIndex() : 0; - const priority2 = n2 ? n2.getSiblingIndex() : 0; + const priority1 = n1 ? n1.siblingIndex : 0; + const priority2 = n2 ? n2.siblingIndex : 0; return ex ? priority1 - priority2 : priority2 - priority1; } diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index e4b7bb464d6..e347b4cdc1b 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -497,13 +497,14 @@ export class NodeEventProcessor { private _handleMouseDown (event: EventMouse): boolean { const node = this._node; - if (!node || !node._uiProps.uiTransformComp) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp) { return false; } event.getLocation(pos); - if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { + if (uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.MOUSE_DOWN; event.bubbles = true; node.dispatchEvent(event); @@ -515,13 +516,14 @@ export class NodeEventProcessor { private _handleMouseMove (event: EventMouse): boolean { const node = this._node; - if (!node || !node._uiProps.uiTransformComp || this._isMouseLeaveWindow) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp || this._isMouseLeaveWindow) { return false; } event.getLocation(pos); - const hit = node._uiProps.uiTransformComp.hitTest(pos, event.windowId); + const hit = uiTransformComp.hitTest(pos, event.windowId); if (hit) { if (!this.previousMouseIn) { // Fix issue when hover node switched, previous hovered node won't get MOUSE_LEAVE notification @@ -551,13 +553,14 @@ export class NodeEventProcessor { private _handleMouseUp (event: EventMouse): boolean { const node = this._node; - if (!node || !node._uiProps.uiTransformComp) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp) { return false; } event.getLocation(pos); - if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { + if (uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.MOUSE_UP; event.bubbles = true; node.dispatchEvent(event); @@ -569,13 +572,14 @@ export class NodeEventProcessor { private _handleMouseWheel (event: EventMouse): boolean { const node = this._node; - if (!node || !node._uiProps.uiTransformComp) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp) { return false; } event.getLocation(pos); - if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { + if (uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.MOUSE_WHEEL; event.bubbles = true; node.dispatchEvent(event); @@ -631,13 +635,14 @@ export class NodeEventProcessor { private _handleTouchStart (event: EventTouch): boolean { const node = this.node; - if (!node || !node._uiProps.uiTransformComp) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp) { return false; } event.getLocation(pos); - if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { + if (uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.TOUCH_START; event.bubbles = true; this._dispatchingTouch = event.touch; @@ -663,13 +668,14 @@ export class NodeEventProcessor { private _handleTouchEnd (event: EventTouch): void { const node = this.node; - if (!node || !node._uiProps.uiTransformComp) { + const uiTransformComp = node._uiProps.uiTransformComp; + if (!node || !uiTransformComp) { return; } event.getLocation(pos); - if (node._uiProps.uiTransformComp.hitTest(pos, event.windowId)) { + if (uiTransformComp.hitTest(pos, event.windowId)) { event.type = NodeEventType.TOUCH_END; } else { event.type = NodeEventType.TOUCH_CANCEL; diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 6865fba97dc..b81d3cb536d 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1763,17 +1763,19 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { */ @editable set layer (l: number) { - if (this._layer === l) { + const self = this; + if (self._layer === l) { return; } - this._layer = l; + self._layer = l; - if (this._uiProps && this._uiProps.uiComp) { - this._uiProps.uiComp.setNodeDirty(); - this._uiProps.uiComp.markForUpdateRenderData(); + const uiComp = self._uiProps && self._uiProps.uiComp; + if (uiComp) { + uiComp.setNodeDirty(); + uiComp.markForUpdateRenderData(); } - this.emit(NodeEventType.LAYER_CHANGED, this._layer); + self.emit(NodeEventType.LAYER_CHANGED, self._layer); } get layer (): number { @@ -1933,8 +1935,9 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _onPostActivated (active: boolean): void { - if (this._eventMask & ACTIVE_ON) { - this.emit(NodeEventType.ACTIVE_CHANGED, this, active); + const self = this; + if (self._eventMask & ACTIVE_ON) { + self.emit(NodeEventType.ACTIVE_CHANGED, self, active); } const eventProcessor = this._eventProcessor; @@ -1957,12 +1960,13 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { if (active) { // activated // in case transform updated during deactivated period - this.invalidateChildren(TransformBit.TRS); + self.invalidateChildren(TransformBit.TRS); // ALL Node renderData dirty flag will set on here - if (this._uiProps && this._uiProps.uiComp) { - this._uiProps.uiComp.setNodeDirty(); - this._uiProps.uiComp.setTextureDirty(); // for dynamic atlas - this._uiProps.uiComp.markForUpdateRenderData(); + const uiComp = self._uiProps && self._uiProps.uiComp; + if (uiComp) { + uiComp.setNodeDirty(); + uiComp.setTextureDirty(); // for dynamic atlas + uiComp.markForUpdateRenderData(); } } } diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 85f6bf70a45..6811fb184bb 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1655,19 +1655,23 @@ export class Skeleton extends UIRenderer { * @engineInternal */ public _updateColor (): void { - const a = this.node._uiProps.opacity; - // eslint-disable-next-line max-len - if (this._tempColor.r === this._color.r && this._tempColor.g === this._color.g && this._tempColor.b === this._color.b && this._tempColor.a === a) { + const self = this; + const uiProps = self.node._uiProps; + const a = uiProps.opacity; + const tempColor = self._tempColor; + const color = self._color; + + if (tempColor.r === color.r && tempColor.g === color.g && tempColor.b === color.b && tempColor.a === a) { return; } - this.node._uiProps.colorDirty = true; - this._tempColor.r = this._color.r; - this._tempColor.g = this._color.g; - this._tempColor.b = this._color.b; - this._tempColor.a = a; - const r = this._color.r / 255.0; - const g = this._color.g / 255.0; - const b = this._color.b / 255.0; + uiProps.colorDirty = true; + tempColor.r = color.r; + tempColor.g = color.g; + tempColor.b = color.b; + tempColor.a = a; + const r = color.r / 255.0; + const g = color.g / 255.0; + const b = color.b / 255.0; this._instance!.setColor(r, g, b, a); }