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: screenPos() worldPos() correctly type set functionality (and other type errors) #593

Merged
merged 2 commits into from
Jan 23, 2025
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
9 changes: 6 additions & 3 deletions src/components/physics/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,24 @@ export interface AreaComp extends Comp {
*
* @since v2001.0
*/
onCollide(tag: Tag, f: (obj: GameObj, col?: Collision) => void): void;
onCollide(
tag: Tag,
f: (obj: GameObj, col?: Collision) => void,
): KEventController;
/**
* Register an event runs once when collide with another game obj.
*
* @since v2000.1
*/
onCollide(f: (obj: GameObj, col?: Collision) => void): void;
onCollide(f: (obj: GameObj, col?: Collision) => void): KEventController;
/**
* Register an event runs every frame when collide with another game obj with certain tag.
*
* @since v3000.0
*/
onCollideUpdate(
tag: Tag,
f: (obj: GameObj, col?: Collision) => void,
f: (obj: GameObj, col?: Collision) => KEventController,
): KEventController;
/**
* Register an event runs every frame when collide with another game obj.
Expand Down
17 changes: 13 additions & 4 deletions src/components/transform/pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,48 @@ export interface PosComp extends Comp {
moveTo(dest: Vec2, speed?: number): void;
moveTo(x: number, y: number, speed?: number): void;
/**
* Get the position of the object on the screen.
* Get / Set the position of the object on the screen.
*
* @since v2000.0
*/
screenPos(): Vec2 | null;
screenPos(newPos?: Vec2): Vec2 | null;
/**
* Get the position of the object relative to the root.
* Get / Set the position of the object relative to the root.
*
* @since v2000.0
*/
worldPos(): Vec2 | null;
worldPos(newPos?: Vec2): Vec2 | null;
/**
* Transform a local point (relative to this) to a screen point (relative to the camera)
*/
toScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
/**
* Transform a local point (relative to this) to a world point (relative to the root)
*
* @since v3001.0
*/
toWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a screen point (relative to the camera) to a local point (relative to this)
*
* @since v3001.0
*/
fromScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
/**
* Transform a world point (relative to the root) to a local point (relative to this)
*
* @since v3001.0
*/
fromWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a point relative to this to a point relative to other
*
* @since v3001.0
*/
toOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a point relative to other to a point relative to this
*
* @since v3001.0
*/
fromOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;
Expand Down
Loading