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: Fixes double push, exports system. #567

Merged
merged 1 commit into from
Dec 18, 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
1 change: 0 additions & 1 deletion src/game/make.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export function make<T>(comps: CompList<T> = []): GameObj<T> {
}
obj.parent = this;
calcTransform(obj, obj.transform);
this.children.push(obj);
// TODO: trigger add for children
obj.trigger("add", obj);
_k.game.events.trigger("add", obj);
Expand Down
19 changes: 12 additions & 7 deletions src/kaplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ const kaplay = <
>(
gopt: KAPLAYOpt<TPlugins, TButtons> = {},
): TPlugins extends [undefined] ? KAPLAYCtx<TButtons, TButtonsName>
: KAPLAYCtx<TButtons, TButtonsName> & MergePlugins<TPlugins> => {
: KAPLAYCtx<TButtons, TButtonsName> & MergePlugins<TPlugins> =>
{
if (_k.k) {
console.warn(
"KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs!",
Expand Down Expand Up @@ -489,7 +490,10 @@ const kaplay = <

game.root.use(timer());

system("collision", checkFrame, [LCEvents.AfterFixedUpdate, LCEvents.AfterUpdate])
system("collision", checkFrame, [
LCEvents.AfterFixedUpdate,
LCEvents.AfterUpdate,
]);

function makeCanvas(w: number, h: number) {
const fb = new FrameBuffer(ggl, w, h);
Expand Down Expand Up @@ -1000,7 +1004,7 @@ const kaplay = <

// TODO: this should only run once
app.run(
() => { },
() => {},
() => {
frameStart();

Expand Down Expand Up @@ -1063,7 +1067,7 @@ const kaplay = <
// clear canvas
gl.clear(
gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT
| gl.STENCIL_BUFFER_BIT,
| gl.STENCIL_BUFFER_BIT,
);

// unbind everything
Expand Down Expand Up @@ -1111,7 +1115,7 @@ const kaplay = <
}
}

//checkFrame();
// checkFrame();
}
} catch (e) {
handleErr(e as Error);
Expand Down Expand Up @@ -1157,7 +1161,7 @@ const kaplay = <
}
}

//checkFrame();
// checkFrame();
frameStart();

for (const sys of _k.systemsByEvent[LCEvents.BeforeDraw]) {
Expand Down Expand Up @@ -1516,6 +1520,7 @@ const kaplay = <
downloadBlob,
// plugin
plug,
system,
// char sets
ASCII_CHARS,
// dom
Expand Down Expand Up @@ -1556,7 +1561,7 @@ const kaplay = <
// export everything to window if global is set
if (gopt.global !== false) {
for (const key in ctx) {
(<any>window[<any>key]) = ctx[key as keyof KAPLAYCtx];
(<any> window[<any> key]) = ctx[key as keyof KAPLAYCtx];
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5385,6 +5385,17 @@ export interface KAPLAYCtx<
* @group Plugins
*/
plug<T extends Record<string, any>>(plugin: KAPLAYPlugin<T>): KAPLAYCtx & T;
/**
* Runs a system at the specified events in the pipeline
*
* @param name The name of the system. Overwrites an existing system if the name has been used before.
* @param cb The function to run.
* @param when When to run the function.
*
* @since v4000.0
* @group Plugins
*/
system(name: string, cb: () => void, when: LCEvents[]): void;
/**
* Take a screenshot and get the data url of the image.
*
Expand Down
Loading