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

fix: some functions not return a KEventController #471

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,11 @@ export const initApp = (opt: {
}

function onGamepadConnect(action: (gamepad: KGamepad) => void) {
state.events.on("gamepadConnect", action);
return state.events.on("gamepadConnect", action);
}

function onGamepadDisconnect(action: (gamepad: KGamepad) => void) {
state.events.on("gamepadDisconnect", action);
return state.events.on("gamepadDisconnect", action);
}

function getGamepadStick(stick: GamepadStick): Vec2 {
Expand Down
10 changes: 5 additions & 5 deletions src/game/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ export function onHoverEnd(
}

export function onLoading(action: (progress: number) => void) {
game.events.on("loading", action);
return game.events.on("loading", action);
}

export function onResize(action: () => void) {
app.onResize(action);
return app.onResize(action);
}

export function onError(action: (err: Error) => void) {
game.events.on("error", action);
return game.events.on("error", action);
}

export function onLoad(cb: () => void): void {
export function onLoad(cb: () => void) {
if (assets.loaded) {
cb();
}
else {
game.events.on("load", cb);
return game.events.on("load", cb);
}
}
17 changes: 10 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,28 +1296,28 @@ export interface KAPLAYCtx<
* ```
* @group Events
*/
onLoad(action: () => void): void;
onLoad(action: () => void): KEventController | undefined;
/**
* Register an event that runs every frame when assets are initially loading. Can be used to draw a custom loading screen.
*
* @since v3000.0
* @group Events
*/
onLoading(action: (progress: number) => void): void;
onLoading(action: (progress: number) => void): KEventController;
/**
* Register a custom error handler. Can be used to draw a custom error screen.
*
* @since v3000.0
* @group Events
*/
onError(action: (err: Error) => void): void;
onError(action: (err: Error) => void): KEventController;
/**
* Register an event that runs when the canvas resizes.
*
* @since v3000.0
* @group Events
*/
onResize(action: () => void): void;
onResize(action: () => void): KEventController;
/**
* Cleanup function to run when quit() is called.
*
Expand All @@ -1331,14 +1331,14 @@ export interface KAPLAYCtx<
* @since v3000.0
* @group Input
*/
onGamepadConnect(action: (gamepad: KGamepad) => void): void;
onGamepadConnect(action: (gamepad: KGamepad) => void): KEventController;
/**
* Register an event that runs when a gamepad is disconnected.
*
* @since v3000.0
* @group Input
*/
onGamepadDisconnect(action: (gamepad: KGamepad) => void): void;
onGamepadDisconnect(action: (gamepad: KGamepad) => void): KEventController;
/**
* Register an event that runs once when 2 game objs with certain tags collides (required to have area() component).
*
Expand Down Expand Up @@ -1910,7 +1910,10 @@ export interface KAPLAYCtx<
*
* @group Assets
*/
loadSound(name: string | null, src: string | ArrayBuffer | AudioBuffer): Asset<SoundData>;
loadSound(
name: string | null,
src: string | ArrayBuffer | AudioBuffer,
): Asset<SoundData>;
/**
* Like loadSound(), but the audio is streamed and won't block loading. Use this for big audio files like background music.
*
Expand Down