Skip to content

Commit

Permalink
fix eslint error (#16969)
Browse files Browse the repository at this point in the history
* fix eslint error
  • Loading branch information
minggo authored May 11, 2024
1 parent 0395112 commit 735d5a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 23 deletions.
38 changes: 30 additions & 8 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class Director extends EventTarget {
private _totalFrames: number;
private _scheduler: Scheduler;
private _systems: System[];
private _persistRootNodes = {};
private _persistRootNodes: Record<string, Node> = {};

constructor () {
super();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -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');
}
}
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
28 changes: 17 additions & 11 deletions cocos/scene-graph/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<T extends Component> (
children: Node[],
constructor: Constructor<T> | AbstractedConstructor<T>,
components: Component[],
): void {
for (let i = 0; i < children.length; ++i) {
const node = children[i];
Node._findComponents(node, constructor, components);
Expand Down Expand Up @@ -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<Component>;
if (!this.getComponent(reqComp)) {
this.addComponent(reqComp);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
15 changes: 11 additions & 4 deletions cocos/scene-graph/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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
Expand Down

0 comments on commit 735d5a5

Please sign in to comment.