diff --git a/cocos/game/director.ts b/cocos/game/director.ts index 6ce2669fd9d..57e0a706c82 100644 --- a/cocos/game/director.ts +++ b/cocos/game/director.ts @@ -191,7 +191,7 @@ export class Director extends EventTarget { private _totalFrames: number; private _scheduler: Scheduler; private _systems: System[]; - private _persistRootNodes = {}; + private _persistRootNodes: Record = {}; constructor () { super(); @@ -225,7 +225,9 @@ export class Director extends EventTarget { * @zh 计算从上一帧到现在的时间间隔,结果保存在私有属性中 * @deprecated since v3.3.0 no need to use it anymore */ - public calculateDeltaTime (now): void {} + public calculateDeltaTime (now: any): void { + // do nothing + } /** * @en End the life of director in the next frame @@ -306,22 +308,29 @@ export class Director extends EventTarget { * @param onBeforeLoadScene - The function invoked at the scene before loading. * @param onLaunched - The function invoked at the scene after launch. */ - public runSceneImmediate (scene: Scene | SceneAsset, onBeforeLoadScene?: Director.OnBeforeLoadScene, onLaunched?: Director.OnSceneLaunched): void { + public runSceneImmediate ( + scene: Scene | SceneAsset, + onBeforeLoadScene?: Director.OnBeforeLoadScene, + onLaunched?: Director.OnSceneLaunched, + ): void { if (scene instanceof SceneAsset) scene = scene.scene!; assertID(scene instanceof Scene, 1216); if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.time('InitScene'); } scene._load(); // ensure scene initialized if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('InitScene'); } // Re-attach or replace persist nodes if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.time('AttachPersist'); } - const persistNodeList = Object.keys(this._persistRootNodes).map((x): Node => this._persistRootNodes[x] as Node); + const persistNodeList = Object.keys(this._persistRootNodes).map((x): Node => this._persistRootNodes[x]); for (let i = 0; i < persistNodeList.length; i++) { const node = persistNodeList[i]; node.emit(Node.EventType.SCENE_CHANGED_FOR_PERSISTS, scene.renderScene); @@ -340,12 +349,14 @@ export class Director extends EventTarget { } } if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('AttachPersist'); } const oldScene = this._scene; // unload scene if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.time('Destroy'); } if (isValid(oldScene)) { @@ -354,10 +365,12 @@ export class Director extends EventTarget { if (!EDITOR) { // auto release assets if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.time('AutoRelease'); } releaseManager._autoRelease(oldScene!, scene, this._persistRootNodes); if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('AutoRelease'); } } @@ -366,6 +379,7 @@ export class Director extends EventTarget { // purge destroyed nodes belongs to old scene CCObject._deferredDestroy(); + // eslint-disable-next-line no-console if (BUILD && DEBUG) { console.timeEnd('Destroy'); } if (onBeforeLoadScene) { @@ -377,10 +391,12 @@ export class Director extends EventTarget { this._scene = scene; if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.time('Activate'); } scene._activate(); if (BUILD && DEBUG) { + // eslint-disable-next-line no-console console.timeEnd('Activate'); } // start scene @@ -432,8 +448,10 @@ export class Director extends EventTarget { if (bundle) { this.emit(Director.EVENT_BEFORE_SCENE_LOADING, sceneName); this._loadingScene = sceneName; + // eslint-disable-next-line no-console console.time(`LoadScene ${sceneName}`); bundle.loadScene(sceneName, (err, scene): void => { + // eslint-disable-next-line no-console console.timeEnd(`LoadScene ${sceneName}`); this._loadingScene = ''; if (err) { @@ -489,8 +507,12 @@ export class Director extends EventTarget { const bundle = assetManager.bundles.find((bundle): boolean => !!bundle.getSceneInfo(sceneName)); if (bundle) { // NOTE: the similar function signatures but defined as deferent function types. - bundle.preloadScene(sceneName, null, onProgress as (finished: number, total: number, item: any) => void, - onLoaded as ((err?: Error | null) => void) | null); + bundle.preloadScene( + sceneName, + null, + onProgress as (finished: number, total: number, item: any) => void, + onLoaded as ((err?: Error | null) => void) | null, + ); } else { const err = `Can not preload the scene "${sceneName}" because it is not in the build settings.`; if (onLoaded) { @@ -622,7 +644,7 @@ export class Director extends EventTarget { * @deprecated since 3.0.0 */ public getAnimationManager (): any { - return this.getSystem(cclegacy.AnimationManager.ID); + return this.getSystem(cclegacy.AnimationManager.ID as string); } // Loop management @@ -648,7 +670,7 @@ export class Director extends EventTarget { * @deprecated Since v3.6, please use [tick] instead */ public mainLoop (now: number): void { - let dt; + let dt: number; if (EDITOR_NOT_IN_PREVIEW || TEST) { dt = now; } else { diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 65bf67987c0..7116f67a030 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -221,7 +221,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { get parent (): Node | null { return this._parent; } - set parent (value) { + set parent (value: Node | null) { this.setParent(value); } @@ -330,7 +330,11 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { return null; } - protected static _findChildComponents (children: Node[], constructor, components): void { + protected static _findChildComponents ( + children: Node[], + constructor: Constructor | AbstractedConstructor, + components: Component[], + ): void { for (let i = 0; i < children.length; ++i) { const node = children[i]; Node._findComponents(node, constructor, components); @@ -1001,9 +1005,10 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { const reqComps = (constructor as typeof constructor & { _requireComponent?: typeof Component })._requireComponent; if (reqComps) { + // FIXME: why it can be array here? if (Array.isArray(reqComps)) { for (let i = 0; i < reqComps.length; i++) { - const reqComp = reqComps[i]; + const reqComp = reqComps[i] as Constructor; if (!this.getComponent(reqComp)) { this.addComponent(reqComp); } @@ -1086,11 +1091,13 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { errorID(3813); return; } + let componentInstance: Component | null = null; if (component instanceof Component) { componentInstance = component; } else { - componentInstance = this.getComponent(component); + // "component as string": Just make eslint happy. + componentInstance = this.getComponent(component as string); } if (componentInstance) { componentInstance.destroy(); @@ -1136,7 +1143,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * node.on(NodeEventType.TOUCH_END, callback, this); * ``` */ - public on (type: string | NodeEventType, callback: AnyFunction, target?: unknown, useCapture: any = false): void { + public on (type: string | NodeEventType, callback: AnyFunction, target?: unknown, useCapture: boolean = false): void { switch (type) { case NodeEventType.TRANSFORM_CHANGED: this._eventMask |= TRANSFORM_ON; @@ -1163,7 +1170,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * node.off(NodeEventType.TOUCH_START, callback, this.node); * ``` */ - public off (type: string, callback?: AnyFunction, target?: unknown, useCapture: any = false): void { + public off (type: string, callback?: AnyFunction, target?: unknown, useCapture: boolean = false): void { this._eventProcessor.off(type as NodeEventType, callback, target, useCapture); const hasListeners = this._eventProcessor.hasEventListener(type); @@ -1191,7 +1198,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * The callback is ignored if it is a duplicate (the callbacks are unique). * @param target - The target (this object) to invoke the callback, can be null */ - public once (type: string, callback: AnyFunction, target?: unknown, useCapture?: any): void { + public once (type: string, callback: AnyFunction, target?: unknown, useCapture?: boolean): void { this._eventProcessor.once(type as NodeEventType, callback, target, useCapture); } @@ -1245,7 +1252,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * @zh 移除目标上的所有注册事件。 * @param target - The target to be searched for all related callbacks */ - public targetOff (target: string | unknown): void { + public targetOff (target: unknown): void { this._eventProcessor.targetOff(target); // Check for event mask reset if ((this._eventMask & TRANSFORM_ON) && !this._eventProcessor.hasEventListener(NodeEventType.TRANSFORM_CHANGED)) { @@ -1312,9 +1319,9 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { this.emit(NodeEventType.CHILDREN_ORDER_CHANGED); } - protected _instantiate (cloned, isSyncedNode): any { + protected _instantiate (cloned?: Node | null, isSyncedNode: boolean = false): Node { if (!cloned) { - cloned = legacyCC.instantiate._clone(this, this); + cloned = legacyCC.instantiate._clone(this, this) as Node; } const newPrefabInfo = cloned._prefab; @@ -1333,7 +1340,6 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { cloned._parent = null; cloned._onBatchCreated(isSyncedNode); - // eslint-disable-next-line @typescript-eslint/no-unsafe-return return cloned; } diff --git a/cocos/scene-graph/scene.ts b/cocos/scene-graph/scene.ts index 9afac73b272..ca5e4b5dfca 100644 --- a/cocos/scene-graph/scene.ts +++ b/cocos/scene-graph/scene.ts @@ -129,13 +129,15 @@ export class Scene extends Node { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _onHierarchyChanged (): void { } + public _onHierarchyChanged (): void { + // do nothing + } /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _onPostActivated (active: boolean): void { - + // do nothing } /** @@ -155,11 +157,16 @@ export class Scene extends Node { * @zh * 参考 [[Node.updateWorldTransform]] */ - public updateWorldTransform (): void {} + public updateWorldTransform (): void { + // do nothing + } // life-cycle call backs - protected _instantiate (): void { } + protected _instantiate (cloned?: Node | null, isSyncedNode: boolean = false): Node { + // Can not initialize scene. + return null as unknown as Node; + } /** * @engineInternal