Skip to content

Commit

Permalink
feat: add typescript checkint to all examples (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel authored Sep 16, 2024
1 parent 7d68eaf commit b3fe49d
Show file tree
Hide file tree
Showing 88 changed files with 364 additions and 168 deletions.
39 changes: 18 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,18 @@ 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.
- Now `loadShader()` and `loadShaderURL()` accepts null for unused parameters.
- Now `RectCompOpt` accepts a array of numbers for `radius`.

## Deprecations

Expand Down
2 changes: 2 additions & 0 deletions examples/add.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Adding game objects to screen

// Start a KAPLAY game
Expand Down
2 changes: 2 additions & 0 deletions examples/ai.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Use state() component to handle basic AI

// Start kaboom
Expand Down
4 changes: 3 additions & 1 deletion examples/animation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Start kaboom
kaplay();

Expand Down Expand Up @@ -174,7 +176,7 @@ console.log(JSON.stringify(serializeAnimation(curvingBean, "root"), "", 2));

/*onDraw(() => {
drawCurve(t => evaluateCatmullRom(
vec2(200, 400),
vec2(200, 400),\
vec2(250, 500),
vec2(300, 400),
vec2(350, 500), t), { color: RED })
Expand Down
2 changes: 2 additions & 0 deletions examples/audio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// audio playback & control

kaplay({
Expand Down
2 changes: 2 additions & 0 deletions examples/bench.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-config

// bench marking sprite rendering performance

kaplay();
Expand Down
2 changes: 2 additions & 0 deletions examples/binding.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay({
buttons: {
"jump": {
Expand Down
2 changes: 2 additions & 0 deletions examples/burp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Start the game in burp mode
kaplay({
burp: true,
Expand Down
3 changes: 3 additions & 0 deletions examples/button.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Simple Button UI

kaplay({
Expand All @@ -16,6 +18,7 @@ function addButton(txt, p, f) {
scale(1),
anchor("center"),
outline(4),
color(0, 0, 0),
]);

// add a child object that displays the text
Expand Down
8 changes: 6 additions & 2 deletions examples/camera.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Adjust camera / viewport

// Start game
Expand Down Expand Up @@ -77,7 +79,8 @@ onKeyDown("right", () => player.move(SPEED, 0));

let score = 0;

// Add a ui layer with fixed() component to make the object not affected by camera
// Add a ui layer with fixed() component to make the object
// not affected by camera
const ui = add([
fixed(),
]);
Expand All @@ -94,6 +97,7 @@ ui.add([
]);

onClick(() => {
// Use toWorld() to transform a screen-space coordinate (like mousePos()) to the world-space coordinate, which has the camera transform applied
// Use toWorld() to transform a screen-space coordinate (like mousePos()) to
// the world-space coordinate, which has the camera transform applied
addKaboom(toWorld(mousePos()));
});
2 changes: 2 additions & 0 deletions examples/children.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

loadSprite("bean", "/sprites/bean.png");
Expand Down
2 changes: 2 additions & 0 deletions examples/collision.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Collision handling

// Start kaboom
Expand Down
2 changes: 2 additions & 0 deletions examples/collisionshapes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

setGravity(300);
Expand Down
1 change: 1 addition & 0 deletions examples/component.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
// Custom component

kaplay();
Expand Down
2 changes: 2 additions & 0 deletions examples/concert.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// bean is holding a concert to celebrate kaboom2000!

kaplay({
Expand Down
6 changes: 4 additions & 2 deletions examples/confetti.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// @ts-check

kaplay();

const DEF_COUNT = 80;
const DEF_GRAVITY = 800;
const DEF_AIR_DRAG = 0.9;
Expand All @@ -9,8 +13,6 @@ const DEF_SPIN = [2, 8];
const DEF_SATURATION = 0.7;
const DEF_LIGHTNESS = 0.6;

kaplay();

add([
text("click for confetti"),
anchor("top"),
Expand Down
2 changes: 2 additions & 0 deletions examples/curves.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

function addPoint(c, ...args) {
Expand Down
2 changes: 2 additions & 0 deletions examples/dialog.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Simple dialogues with character avatars

kaplay({
Expand Down
8 changes: 5 additions & 3 deletions examples/doublejump.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay({
background: [141, 183, 255],
});
Expand Down Expand Up @@ -37,7 +39,7 @@ function spin(speed = 1200) {

scene("game", () => {
const score = add([
text("0", 24),
text("0", { size: 24 }),
pos(24, 24),
{ value: 0 },
]);
Expand Down Expand Up @@ -111,7 +113,7 @@ scene("game", () => {
destroy(c);
play("coin");
score.value += 1;
score.text = score.value;
score.text = score.value.toString();
genCoin(c.idx);
});

Expand Down Expand Up @@ -161,7 +163,7 @@ scene("game", () => {
const timer = add([
anchor("topright"),
pos(width() - 24, 24),
text(timeLeft),
text(timeLeft.toString()),
]);

onUpdate(() => {
Expand Down
2 changes: 2 additions & 0 deletions examples/drag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Drag & drop interaction

kaplay();
Expand Down
3 changes: 3 additions & 0 deletions examples/draw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Kaboom as pure rendering lib (no component / game obj etc.)

kaplay();
Expand Down Expand Up @@ -26,6 +28,7 @@ const py = 160;
const doodles = [];
const trail = [];

/** @type { import("../dist/declaration").Outline } */
const outline = {
width: 4,
color: rgb(0, 0, 0),
Expand Down
2 changes: 2 additions & 0 deletions examples/easing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

add([
Expand Down
8 changes: 6 additions & 2 deletions examples/eatlove.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

const fruits = [
Expand Down Expand Up @@ -80,7 +82,9 @@ scene("game", () => {
let score = 0;

const scoreLabel = add([
text(score, 32),
text(score.toString(), {
size: 32,
}),
pos(12, 12),
]);

Expand All @@ -89,7 +93,7 @@ scene("game", () => {
addKaboom(player.pos);
score += 1;
destroy(heart);
scoreLabel.text = score;
scoreLabel.text = score.toString();
burp();
shake(12);
});
Expand Down
3 changes: 2 additions & 1 deletion examples/egg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
// Egg minigames (yes, like Peppa)

kaplay({
Expand Down Expand Up @@ -74,7 +75,7 @@ onKeyPress("enter", () => {
e.use(sprite("bean"));
addKaboom(e.pos.sub(0, e.height / 2));
counter.value += 1;
counter.text = counter.value;
counter.text = counter.value.toString();
}
});
});
2 changes: 2 additions & 0 deletions examples/fadeIn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

loadBean();
Expand Down
2 changes: 2 additions & 0 deletions examples/fakeMouse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

loadSprite("bean", "/sprites/bean.png");
Expand Down
2 changes: 2 additions & 0 deletions examples/fall.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Build levels with addLevel()

// Start game
Expand Down
2 changes: 2 additions & 0 deletions examples/fixedUpdate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

let fixedCount = 0;
Expand Down
2 changes: 2 additions & 0 deletions examples/flamebar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

// Mario-like flamebar

// Start kaboom
Expand Down
6 changes: 4 additions & 2 deletions examples/flappy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-check

kaplay();

loadSprite("bean", "/sprites/bean.png");
Expand Down Expand Up @@ -109,7 +111,7 @@ scene("game", () => {

// display score
const scoreLabel = add([
text(score),
text(score.toString()),
anchor("center"),
pos(width() / 2, 80),
fixed(),
Expand All @@ -118,7 +120,7 @@ scene("game", () => {

function addScore() {
score++;
scoreLabel.text = score;
scoreLabel.text = score.toString();
play("score");
}
});
Expand Down
Loading

0 comments on commit b3fe49d

Please sign in to comment.