Skip to content
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

Show correct type for preloadScene #17625

Open
wants to merge 1 commit into
base: v3.8.5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class Director extends EventTarget {
* @param sceneName @en The name of the scene to load @zh 场景名称。
* @param onLoaded @en Callback to execute once the scene is loaded @zh 加载回调。
*/
public preloadScene (sceneName: string, onLoaded?: Director.OnSceneLoaded): void;
public preloadScene (sceneName: string, onLoaded?: Director.OnScenePreloaded): void;

/**
* @en
Expand All @@ -462,12 +462,12 @@ export class Director extends EventTarget {
* @param onProgress @en Callback to execute when the load progression change. @zh 加载进度回调。
* @param onLoaded @en Callback to execute once the scene is loaded @zh 加载回调。
*/
public preloadScene (sceneName: string, onProgress: Director.OnLoadSceneProgress, onLoaded: Director.OnSceneLoaded): void;
public preloadScene (sceneName: string, onProgress: Director.OnLoadSceneProgress, onLoaded: Director.OnScenePreloaded): void;

public preloadScene (
sceneName: string,
onProgress?: Director.OnLoadSceneProgress | Director.OnSceneLoaded,
onLoaded?: Director.OnSceneLoaded,
onProgress?: Director.OnLoadSceneProgress | Director.OnScenePreloaded,
onLoaded?: Director.OnScenePreloaded,
): void {
const bundle = assetManager.bundles.find((bundle): boolean => !!bundle.getSceneInfo(sceneName));
if (bundle) {
Expand Down Expand Up @@ -819,6 +819,7 @@ export declare namespace Director {

export type OnUnload = () => void;

export type OnScenePreloaded = (error?: Error) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, rename it to OnScenePreloaded is more clear. But it will break compatibility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the main problem is that the current interface is really misleading since the extra argument. I wanted instead to at least make it valid

export type OnSceneLoaded = (error: null | Error, sceneAsset?: SceneAsset) => void;

export type OnSceneLaunched = (error: null | Error, scene?: Scene) => void;
Expand Down
Loading