Skip to content
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
5 changes: 5 additions & 0 deletions packages/melonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [19.4.0] (melonJS 2) - _unreleased_

### Changed
- `throttle(fn, wait)` is now generic over its argument tuple — `throttle<T extends unknown[]>((...args: T) => void, wait)` preserves the wrapped function's parameter types. Drops the `as unknown as () => void` cast that the pointer-event handler used to need.

## [19.3.0] (melonJS 2) - _2026-05-08_

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/melonjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "melonjs",
"version": "19.3.0",
"version": "19.4.0",
"description": "melonJS Game Engine",
"homepage": "http://www.melonjs.org/",
"type": "module",
Expand Down
4 changes: 1 addition & 3 deletions packages/melonjs/src/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
this.settings = settings;

// identify parent element and/or the html target for resizing
this.parentElement = device.getElement(this.settings.parent!);

Check warning on line 276 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 276 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 276 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
if (typeof this.settings.scaleTarget !== "undefined") {
this.settings.scaleTarget = device.getElement(this.settings.scaleTarget);
}
Expand Down Expand Up @@ -412,9 +412,7 @@
// point to the current active stage "default" camera
const current = state.get();
if (typeof current !== "undefined") {
this.viewport = (current.cameras as unknown as Map<string, Camera2d>).get(
"default",
)!;
this.viewport = current.cameras.get("default")!;

Check warning on line 415 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 415 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 415 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
}

// publish reset notification
Expand Down Expand Up @@ -521,21 +519,21 @@
globalThis.removeEventListener("resize", this._onResize);
globalThis.removeEventListener(
"orientationchange",
this._onOrientationChange!,

Check warning on line 522 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 522 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 522 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
);
globalThis.removeEventListener("scroll", this._onScroll!);

Check warning on line 524 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 524 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 524 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion
if (device.screenOrientation) {
globalThis.screen.orientation.onchange = null;
}
}

// destroy the world and all its children
if (this.world) {

Check warning on line 531 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy

Check warning on line 531 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy

Check warning on line 531 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Unnecessary conditional, value is always truthy
this.world.destroy();
}

// remove the canvas from the DOM
if (removeCanvas && this.renderer) {

Check warning on line 536 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy

Check warning on line 536 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary conditional, value is always truthy

Check warning on line 536 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Unnecessary conditional, value is always truthy
const canvas = this.renderer.getCanvas();
if (canvas.parentElement) {
canvas.parentElement.removeChild(canvas);
Expand Down Expand Up @@ -654,7 +652,7 @@
// update all objects (and pass the elapsed time since last frame)
this.isDirty = this.world.update(this.updateDelta);
this.isDirty =
state.current()!.update(this.updateDelta) || this.isDirty;

Check warning on line 655 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 655 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 655 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion

this.lastUpdate = globalThis.performance.now();
this.updateAverageDelta = this.lastUpdate - this.lastUpdateStart;
Expand Down Expand Up @@ -683,7 +681,7 @@
this.renderer.clear();

// render the stage
state.current()!.draw(this.renderer, this.world);

Check warning on line 684 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 684 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 684 in packages/melonjs/src/application/application.ts

View workflow job for this annotation

GitHub Actions / test

Forbidden non-null assertion

// set back to flag
this.isDirty = false;
Expand Down
7 changes: 2 additions & 5 deletions packages/melonjs/src/input/pointerevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function enablePointerEvent(): void {
if (activeEventList.indexOf(events[i]) !== -1) {
pointerEventTarget.addEventListener(
events[i],
onMoveEvent as EventListener,
onMoveEvent,
{ passive: true }, // do not preventDefault on Move events
);
}
Expand All @@ -201,10 +201,7 @@ function enablePointerEvent(): void {
if (activeEventList.indexOf(events[i]) !== -1) {
pointerEventTarget.addEventListener(
events[i],
throttle(
onMoveEvent as unknown as () => void,
throttlingInterval,
) as EventListener,
throttle(onMoveEvent, throttlingInterval),
{ passive: true }, // do not preventDefault on Move events
Comment thread
obiot marked this conversation as resolved.
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/melonjs/src/math/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class Color {
this.setColor(r, g, b, alpha);
} else if (typeof r === "string") {
this.glArray = new Float32Array([0, 0, 0, 1]);
this.parseCSS(r as ColorName);
this.parseCSS(r);
} else if (typeof r === "object") {
this.glArray = r.glArray.slice();
} else {
Expand Down Expand Up @@ -410,7 +410,7 @@ export class Color {
* @returns Reference to the newly cloned object.
*/
clone() {
return colorPool.get(this as Color);
return colorPool.get(this);
}

/**
Expand All @@ -420,7 +420,7 @@ export class Color {
*/
copy(color: Color | string) {
if (typeof color === "string") {
return this.parseCSS(color as ColorName);
return this.parseCSS(color);
} else {
this.glArray.set(color.glArray);
return this;
Expand Down
7 changes: 5 additions & 2 deletions packages/melonjs/src/utils/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export function defer(
* @param [wait] - the delay in ms
* @returns the function that will be throttled
*/
export const throttle = (fn: () => void, wait: number = 100) => {
export const throttle = <T extends unknown[]>(
fn: (...args: T) => void,
wait: number = 100,
) => {
let inThrottle: boolean,
lastFn: ReturnType<typeof setTimeout>,
lastTime: number;
return (...args: [] /* empty array */) => {
return (...args: T) => {
if (!inThrottle) {
fn.apply(this, args);
lastTime = Date.now();
Expand Down
Loading
Loading