Skip to content

Commit

Permalink
fix: types fixings
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Sep 16, 2024
1 parent 7dc2edb commit c26c76d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 104 deletions.
37 changes: 16 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
- Added circle and (rotated) ellipse collision shapes.
- Added an ellipse component.
- Circle area is no longer a box.
- Added a fake cursor API

# v4000.0.0 and v3001.0.0
```js
const myCursor = add([fakeMouse(), sprite("kat"), pos(100, 100)]);

myCursor.press(); // trigger onClick events if the mouse is over
myCursor.release();
myCursor.move(vec2(100, 200)); // move as your wish
```

This version is a double release, with a lot of new features and breaking
changes. v3001 release are focused in backward compatibility with v3000 with the
features of v4000, while v4000 will have the most features and breaking changes.
# v4000.0.0 and v3001.0.0

## Input

Expand Down Expand Up @@ -75,16 +80,6 @@ features of v4000, while v4000 will have the most features and breaking changes.
});
```

- added a fake cursor API (**v4000**)

```js
const myCursor = add([fakeMouse(), sprite("kat"), pos(100, 100)]);
myCursor.press(); // trigger onClick events if the mouse is over
myCursor.release();
myCursor.move(vec2(100, 200)); // move as your wish
```

## Physics

- added effector components: `areaEffector()`, `buoyancyEffector()`,
Expand Down Expand Up @@ -277,17 +272,14 @@ features of v4000, while v4000 will have the most features and breaking changes.
## Debug mode
- added `outline()`, `shader()`, and `area()` properties to `debug.inspect`
(**v3001/4000**)
- added `outline()`, `shader()`, and `area()` properties to `debug.inspect`.
- added `KAPLAYOpt.debugKey` for customizing the key used to toggle debug mode.
(**v3001/4000**)
```js
kaplay({
debugKey: "l",
});
```
- added compatibility with custom properties in debug mode
```js
Expand All @@ -305,11 +297,10 @@ features of v4000, while v4000 will have the most features and breaking changes.
// see the custom properties in debug mode
debug.inspect = true;
```
- Now `debug.log()` accepts multiple argument of any type, like `console.log()`.
## Helpers
> All changes applies for both v3001 and v4000
- added `getSceneName()` to get the current scene name
- added `Color.toArray()` to convert a color to an array
- added global raycast function and raycast method to level
Expand All @@ -325,12 +316,16 @@ features of v4000, while v4000 will have the most features and breaking changes.
## TypeScript
- now you can type `get()` with a type parameter and passing component types.
- Now you can type `get()` with a type parameter and passing component types.
(**v4000**)
```ts
const player = get<BodyComp>("player");
```
- Now `Key` also accepts a string as an acceptable value.
- Now `text()` component doesn't require to pass a string.
- Now `camScale()` and `camPos()` accept only 1 number as parameter.
- Now `shake()` can be called without args.

## Deprecations

Expand Down
4 changes: 2 additions & 2 deletions src/components/transform/rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface RotateComp extends Comp {
rotateTo(s: number): void;
}

export function rotate(r: number): RotateComp {
export function rotate(a?: number): RotateComp {
return {
id: "rotate",
angle: r ?? 0,
angle: a ?? 0,
rotateBy(angle: number) {
this.angle += angle;
},
Expand Down
2 changes: 1 addition & 1 deletion src/gfx/draw/drawDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function drawDebug() {
str += `[time]${log.time.toFixed(2)}[/time]`;
str += " ";
str += `[${style}]${
log.msg?.toString ? log.msg.toString() : log.msg
typeof log?.msg === "string" ? log.msg : String(log.msg)
}[/${style}]`;
logs.push(str);
}
Expand Down
4 changes: 3 additions & 1 deletion src/kaplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ const kaplay = <
stepFrame: updateFrame,
drawCalls: () => gfx.lastDrawCalls,
clearLog: () => game.logs = [],
log: (msg) => {
log: (...msgs) => {
const max = gopt.logMax ?? LOG_MAX;
const msg = msgs.concat(" ").join(" ");

game.logs.unshift({
msg: msg,
time: app.time(),
Expand Down
172 changes: 93 additions & 79 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
AgentCompOpt,
AnchorComp,
AnimateComp,
AnimateCompOpt,
AreaComp,
AreaCompOpt,
AreaEffectorComp,
Expand Down Expand Up @@ -108,6 +109,7 @@ import type {
LineJoin,
Texture,
} from "./gfx";
import { kaplay } from "./kaplay";
import type { GjkCollisionResult } from "./math";
import type { Color, RGBAValue, RGBValue } from "./math/color";
import type {
Expand Down Expand Up @@ -385,9 +387,11 @@ export interface KAPLAYCtx<
/**
* Rotates a Game Object (in degrees).
*
* @param a The angle to rotate by. Defaults to 0.
*
* @group Components
*/
rotate(a: number): RotateComp;
rotate(a?: number): RotateComp;
/**
* Sets the color of a Game Object (rgb 0-255).
*
Expand Down Expand Up @@ -448,6 +452,9 @@ export interface KAPLAYCtx<
/**
* Attach and render a text to a Game Object.
*
* @param txt The text to display.
* @param options Options for the text component. See {@link TextCompOpt}.
*
* @example
* ```js
* // a simple score counter
Expand Down Expand Up @@ -475,7 +482,7 @@ export interface KAPLAYCtx<
*
* @group Components
*/
text(txt: string, options?: TextCompOpt): TextComp;
text(txt?: string, options?: TextCompOpt): TextComp;
/**
* Attach and render a polygon to a Game Object.
*
Expand Down Expand Up @@ -979,7 +986,7 @@ export interface KAPLAYCtx<
* @since v3001.0
* @group Components
*/
animate(): AnimateComp;
animate(opt?: AnimateCompOpt): AnimateComp;
/**
* A fake mouse that follows the mouse position and triggers events.
*
Expand Down Expand Up @@ -2168,6 +2175,8 @@ export interface KAPLAYCtx<
/**
* Camera shake.
*
* @param intensity - The intensity of the shake. Default to 12.
*
* @example
* ```js
* // shake intensively when bean collides with a "bomb"
Expand All @@ -2178,7 +2187,7 @@ export interface KAPLAYCtx<
*
* @group Info
*/
shake(intensity: number): void;
shake(intensity?: number): void;
/**
* Get / set camera position.
*
Expand All @@ -2194,6 +2203,7 @@ export interface KAPLAYCtx<
*/
camPos(pos: Vec2): Vec2;
camPos(x: number, y: number): Vec2;
camPos(xy: number): Vec2;
camPos(): Vec2;
/**
* Get / set camera scale.
Expand All @@ -2202,6 +2212,7 @@ export interface KAPLAYCtx<
*/
camScale(scale: Vec2): Vec2;
camScale(x: number, y: number): Vec2;
camScale(xy: number): Vec2;
camScale(): Vec2;
/**
* Get / set camera rotation.
Expand Down Expand Up @@ -3684,79 +3695,82 @@ export type PluginList<T> = Array<T | KAPLAYPlugin<any>>;
* @group Input
*/
export type Key =
| "f1"
| "f2"
| "f3"
| "f4"
| "f5"
| "f6"
| "f7"
| "f8"
| "f9"
| "f10"
| "f11"
| "f12"
| "`"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "0"
| "-"
| "="
| "q"
| "w"
| "e"
| "r"
| "t"
| "y"
| "u"
| "i"
| "o"
| "p"
| "["
| "]"
| "\\"
| "a"
| "s"
| "d"
| "f"
| "g"
| "h"
| "j"
| "k"
| "l"
| ";"
| "'"
| "z"
| "x"
| "c"
| "v"
| "b"
| "n"
| "m"
| ","
| "."
| "/"
| "escape"
| "backspace"
| "enter"
| "tab"
| "control"
| "alt"
| "meta"
| "space"
| " "
| "left"
| "right"
| "up"
| "down"
| "shift";
| (
| "f1"
| "f2"
| "f3"
| "f4"
| "f5"
| "f6"
| "f7"
| "f8"
| "f9"
| "f10"
| "f11"
| "f12"
| "`"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "0"
| "-"
| "="
| "q"
| "w"
| "e"
| "r"
| "t"
| "y"
| "u"
| "i"
| "o"
| "p"
| "["
| "]"
| "\\"
| "a"
| "s"
| "d"
| "f"
| "g"
| "h"
| "j"
| "k"
| "l"
| ";"
| "'"
| "z"
| "x"
| "c"
| "v"
| "b"
| "n"
| "m"
| ","
| "."
| "/"
| "escape"
| "backspace"
| "enter"
| "tab"
| "control"
| "alt"
| "meta"
| "space"
| " "
| "left"
| "right"
| "up"
| "down"
| "shift"
)
| string & {};

/**
* A mouse button.
Expand Down Expand Up @@ -4782,11 +4796,11 @@ export interface Debug {
/**
* Log some text to on screen debug log.
*/
log(msg: string | { toString(): string }): void;
log(...msg: any): void;
/**
* Log an error message to on screen debug log.
*/
error(msg: string | { toString(): string }): void;
error(msg: any): void;
/**
* The recording handle if currently in recording mode.
*
Expand Down

0 comments on commit c26c76d

Please sign in to comment.