Skip to content

Commit 7a64ea6

Browse files
authored
Merge pull request #1242 from melonjs/typescript
refactor: moved much code to typescript
2 parents f765b00 + f0c1c20 commit 7a64ea6

File tree

139 files changed

+26388
-4710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+26388
-4710
lines changed

eslint.config.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,23 @@ export default tseslint.config(
161161
rules: {
162162
"no-undef": "off",
163163
"no-unused-vars": "off",
164+
"prefer-template": "error",
164165
"@typescript-eslint/no-explicit-any": "off",
165166
"@typescript-eslint/ban-ts-comment": "off",
166167
"@typescript-eslint/no-dynamic-delete": "off",
167168
"@typescript-eslint/no-unsafe-argument": "off",
168169
"@typescript-eslint/no-unsafe-assignment": "off",
169170
"@typescript-eslint/no-unnecessary-condition": "off",
171+
"@typescript-eslint/no-invalid-void-type": "off",
172+
"@typescript-eslint/no-unsafe-return": "off",
173+
"@typescript-eslint/no-non-null-assertion": "off",
170174
"@typescript-eslint/restrict-template-expressions": [
171175
"error",
172176
{ allowNumber: true },
173177
],
174-
"prefer-template": "error",
175178
...jsDocConfig.rules,
179+
"jsdoc/require-jsdoc": "off",
180+
"jsdoc/no-defaults": "off",
176181
},
177182
languageOptions: {
178183
parserOptions: {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
"@eslint/js": "^9.6.0",
2323
"@types/eslint__js": "^8.42.3",
2424
"@types/node": "^20.14.10",
25-
"@vitest/browser": "^2.0.1",
25+
"@vitest/browser": "^2.0.2",
2626
"eslint": "^9.6.0",
2727
"eslint-plugin-jsdoc": "^48.5.2",
2828
"globals": "^15.8.0",
2929
"lefthook": "^1.7.1",
3030
"tsconfig": "workspace:latest",
3131
"typescript": "^5.5.3",
3232
"typescript-eslint": "^8.0.0-alpha.41",
33-
"vitest": "^2.0.1"
33+
"vitest": "^2.0.2"
3434
}
3535
}

packages/examples/src/examples/isometricRpg/play.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ export class PlayScreen extends Stage {
108108
game.world.addChild(new Selector());
109109

110110
// register on mouse event
111-
input.registerPointerEvent(
112-
"pointermove",
113-
game.viewport,
114-
(event) => {
115-
event.emit("pointermove", event);
116-
},
117-
false,
118-
);
111+
// input.registerPointerEvent(
112+
// "pointermove",
113+
// game.viewport,
114+
// (ev) => {
115+
// event.emit(event.POINTERMOVE, ev);
116+
// },
117+
// false,
118+
// );
119119
}
120120
}

packages/examples/src/examples/text/text.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import { BitmapText, Renderable, Text, Tween, pool, video } from "melonjs";
1+
import {
2+
BitmapText,
3+
type Color,
4+
Renderable,
5+
Text,
6+
Tween,
7+
getPool,
8+
video,
9+
} from "melonjs";
210

311
export class TextTest extends Renderable {
12+
color: Color;
13+
414
constructor() {
515
super(0, 0, 640, 480);
616

717
this.anchorPoint.set(0, 0);
818

919
// a default white color object
10-
this.color = pool.pull("me.Color", 255, 255, 255);
20+
this.color = getPool("color").get(255, 255, 255);
1121

1222
// define a tween to cycle the font color
1323
this.tween = new Tween(this.color)
@@ -176,4 +186,8 @@ export class TextTest extends Renderable {
176186
this.fancyBFont.textAlign = "left";
177187
this.fancyBFont.textBaseline = "top";
178188
}
189+
190+
destroy() {
191+
getPool("color").release(this.color);
192+
}
179193
}

packages/melonjs/src/camera/camera2d.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import Vector2d from "./../math/vector2.js";
2-
import Vector3d from "./../math/vector3.js";
3-
import ObservableVector2d from "./../math/observable_vector2.js";
4-
import ObservableVector3d from "./../math/observable_vector3.js";
5-
import Matrix2d from "./../math/matrix2.js";
6-
import Matrix3d from "./../math/matrix3.js";
1+
import { Vector2d, vector2dPool } from "../math/vector2d.ts";
2+
import { Vector3d } from "../math/vector3d.ts";
3+
import { Matrix2d } from "../math/matrix2d.ts";
4+
import { Matrix3d } from "../math/matrix3d.ts";
75
import Rect from "./../geometries/rectangle.js";
86
import { renderer } from "./../video/video.js";
97
import pool from "./../system/pooling.js";
@@ -17,10 +15,12 @@ import {
1715
VIEWPORT_ONCHANGE,
1816
VIEWPORT_ONRESIZE,
1917
} from "../system/event.ts";
18+
import { boundsPool } from "./../physics/bounds.ts";
19+
import { colorPool } from "../math/color.ts";
2020

2121
/**
22-
* @import Bounds from "./../physics/bounds.js";
23-
* @import Color from "./../math/color.js";
22+
* @import {Bounds} from "./../physics/bounds.ts";
23+
* @import {Color} from "./../math/color.ts";
2424
* @import Entity from "./../renderable/entity/entity.js";
2525
* @import Sprite from "./../renderable/sprite.js";
2626
* @import NineSliceSprite from "./../renderable/nineslicesprite.js";
@@ -61,7 +61,7 @@ export default class Camera2d extends Renderable {
6161
* Camera bounds
6262
* @type {Bounds}
6363
*/
64-
this.bounds = pool.pull("Bounds");
64+
this.bounds = boundsPool.get();
6565

6666
/**
6767
* enable or disable damping
@@ -322,12 +322,7 @@ export default class Camera2d extends Renderable {
322322
follow(target, axis, damping) {
323323
if (target instanceof Renderable) {
324324
this.target = target.pos;
325-
} else if (
326-
target instanceof Vector2d ||
327-
target instanceof Vector3d ||
328-
target instanceof ObservableVector2d ||
329-
target instanceof ObservableVector3d
330-
) {
325+
} else if (target instanceof Vector2d || target instanceof Vector3d) {
331326
this.target = target;
332327
} else {
333328
throw new Error("invalid target for me.Camera2d.follow");
@@ -525,7 +520,7 @@ export default class Camera2d extends Renderable {
525520
* });
526521
*/
527522
fadeOut(color, duration = 1000, onComplete) {
528-
this._fadeOut.color = pool.pull("Color").copy(color);
523+
this._fadeOut.color = colorPool.get().copy(color);
529524
this._fadeOut.tween = pool
530525
.pull("Tween", this._fadeOut.color)
531526
.to({ alpha: 0.0 }, { duration })
@@ -545,7 +540,7 @@ export default class Camera2d extends Renderable {
545540
* me.game.viewport.fadeIn("#FFFFFF", 75);
546541
*/
547542
fadeIn(color, duration = 1000, onComplete) {
548-
this._fadeIn.color = pool.pull("Color").copy(color);
543+
this._fadeIn.color = colorPool.get().copy(color);
549544
const _alpha = this._fadeIn.color.alpha;
550545
this._fadeIn.color.alpha = 0.0;
551546
this._fadeIn.tween = pool
@@ -593,7 +588,7 @@ export default class Camera2d extends Renderable {
593588
*/
594589
localToWorld(x, y, v) {
595590
// TODO memoization for one set of coords (multitouch)
596-
v = v || pool.pull("Vector2d");
591+
v = v || vector2dPool.get();
597592
v.set(x, y).add(this.pos).sub(game.world.pos);
598593
if (!this.currentTransform.isIdentity()) {
599594
this.invCurrentTransform.apply(v);
@@ -610,7 +605,7 @@ export default class Camera2d extends Renderable {
610605
*/
611606
worldToLocal(x, y, v) {
612607
// TODO memoization for one set of coords (multitouch)
613-
v = v || pool.pull("Vector2d");
608+
v = v || vector2dPool.get();
614609
v.set(x, y);
615610
if (!this.currentTransform.isIdentity()) {
616611
this.currentTransform.apply(v);
@@ -635,7 +630,7 @@ export default class Camera2d extends Renderable {
635630
// remove the tween if over
636631
if (this._fadeIn.color.alpha === 1.0) {
637632
this._fadeIn.tween = null;
638-
pool.push(this._fadeIn.color);
633+
colorPool.release(this._fadeIn.color);
639634
this._fadeIn.color = null;
640635
}
641636
}
@@ -652,7 +647,7 @@ export default class Camera2d extends Renderable {
652647
// remove the tween if over
653648
if (this._fadeOut.color.alpha === 0.0) {
654649
this._fadeOut.tween = null;
655-
pool.push(this._fadeOut.color);
650+
colorPool.release(this._fadeOut.color);
656651
this._fadeOut.color = null;
657652
}
658653
}

0 commit comments

Comments
 (0)