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

refactor: moved much code to typescript #1242

Merged
merged 2 commits into from
Jul 16, 2024
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
7 changes: 6 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,23 @@ export default tseslint.config(
rules: {
"no-undef": "off",
"no-unused-vars": "off",
"prefer-template": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/restrict-template-expressions": [
"error",
{ allowNumber: true },
],
"prefer-template": "error",
...jsDocConfig.rules,
"jsdoc/require-jsdoc": "off",
"jsdoc/no-defaults": "off",
},
languageOptions: {
parserOptions: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"@eslint/js": "^9.6.0",
"@types/eslint__js": "^8.42.3",
"@types/node": "^20.14.10",
"@vitest/browser": "^2.0.1",
"@vitest/browser": "^2.0.2",
"eslint": "^9.6.0",
"eslint-plugin-jsdoc": "^48.5.2",
"globals": "^15.8.0",
"lefthook": "^1.7.1",
"tsconfig": "workspace:latest",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.41",
"vitest": "^2.0.1"
"vitest": "^2.0.2"
}
}
16 changes: 8 additions & 8 deletions packages/examples/src/examples/isometricRpg/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ export class PlayScreen extends Stage {
game.world.addChild(new Selector());

// register on mouse event
input.registerPointerEvent(
"pointermove",
game.viewport,
(event) => {
event.emit("pointermove", event);
},
false,
);
// input.registerPointerEvent(
// "pointermove",
// game.viewport,
// (ev) => {
// event.emit(event.POINTERMOVE, ev);
// },
// false,
// );
}
}
18 changes: 16 additions & 2 deletions packages/examples/src/examples/text/text.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { BitmapText, Renderable, Text, Tween, pool, video } from "melonjs";
import {
BitmapText,
type Color,
Renderable,
Text,
Tween,
getPool,
video,
} from "melonjs";

export class TextTest extends Renderable {
color: Color;

constructor() {
super(0, 0, 640, 480);

this.anchorPoint.set(0, 0);

// a default white color object
this.color = pool.pull("me.Color", 255, 255, 255);
this.color = getPool("color").get(255, 255, 255);

// define a tween to cycle the font color
this.tween = new Tween(this.color)
Expand Down Expand Up @@ -176,4 +186,8 @@ export class TextTest extends Renderable {
this.fancyBFont.textAlign = "left";
this.fancyBFont.textBaseline = "top";
}

destroy() {
getPool("color").release(this.color);
}
}
37 changes: 16 additions & 21 deletions packages/melonjs/src/camera/camera2d.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Vector2d from "./../math/vector2.js";
import Vector3d from "./../math/vector3.js";
import ObservableVector2d from "./../math/observable_vector2.js";
import ObservableVector3d from "./../math/observable_vector3.js";
import Matrix2d from "./../math/matrix2.js";
import Matrix3d from "./../math/matrix3.js";
import { Vector2d, vector2dPool } from "../math/vector2d.ts";
import { Vector3d } from "../math/vector3d.ts";
import { Matrix2d } from "../math/matrix2d.ts";
import { Matrix3d } from "../math/matrix3d.ts";
import Rect from "./../geometries/rectangle.js";
import { renderer } from "./../video/video.js";
import pool from "./../system/pooling.js";
Expand All @@ -17,10 +15,12 @@ import {
VIEWPORT_ONCHANGE,
VIEWPORT_ONRESIZE,
} from "../system/event.ts";
import { boundsPool } from "./../physics/bounds.ts";
import { colorPool } from "../math/color.ts";

/**
* @import Bounds from "./../physics/bounds.js";
* @import Color from "./../math/color.js";
* @import {Bounds} from "./../physics/bounds.ts";
* @import {Color} from "./../math/color.ts";
* @import Entity from "./../renderable/entity/entity.js";
* @import Sprite from "./../renderable/sprite.js";
* @import NineSliceSprite from "./../renderable/nineslicesprite.js";
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class Camera2d extends Renderable {
* Camera bounds
* @type {Bounds}
*/
this.bounds = pool.pull("Bounds");
this.bounds = boundsPool.get();

/**
* enable or disable damping
Expand Down Expand Up @@ -322,12 +322,7 @@ export default class Camera2d extends Renderable {
follow(target, axis, damping) {
if (target instanceof Renderable) {
this.target = target.pos;
} else if (
target instanceof Vector2d ||
target instanceof Vector3d ||
target instanceof ObservableVector2d ||
target instanceof ObservableVector3d
) {
} else if (target instanceof Vector2d || target instanceof Vector3d) {
this.target = target;
} else {
throw new Error("invalid target for me.Camera2d.follow");
Expand Down Expand Up @@ -525,7 +520,7 @@ export default class Camera2d extends Renderable {
* });
*/
fadeOut(color, duration = 1000, onComplete) {
this._fadeOut.color = pool.pull("Color").copy(color);
this._fadeOut.color = colorPool.get().copy(color);
this._fadeOut.tween = pool
.pull("Tween", this._fadeOut.color)
.to({ alpha: 0.0 }, { duration })
Expand All @@ -545,7 +540,7 @@ export default class Camera2d extends Renderable {
* me.game.viewport.fadeIn("#FFFFFF", 75);
*/
fadeIn(color, duration = 1000, onComplete) {
this._fadeIn.color = pool.pull("Color").copy(color);
this._fadeIn.color = colorPool.get().copy(color);
const _alpha = this._fadeIn.color.alpha;
this._fadeIn.color.alpha = 0.0;
this._fadeIn.tween = pool
Expand Down Expand Up @@ -593,7 +588,7 @@ export default class Camera2d extends Renderable {
*/
localToWorld(x, y, v) {
// TODO memoization for one set of coords (multitouch)
v = v || pool.pull("Vector2d");
v = v || vector2dPool.get();
v.set(x, y).add(this.pos).sub(game.world.pos);
if (!this.currentTransform.isIdentity()) {
this.invCurrentTransform.apply(v);
Expand All @@ -610,7 +605,7 @@ export default class Camera2d extends Renderable {
*/
worldToLocal(x, y, v) {
// TODO memoization for one set of coords (multitouch)
v = v || pool.pull("Vector2d");
v = v || vector2dPool.get();
v.set(x, y);
if (!this.currentTransform.isIdentity()) {
this.currentTransform.apply(v);
Expand All @@ -635,7 +630,7 @@ export default class Camera2d extends Renderable {
// remove the tween if over
if (this._fadeIn.color.alpha === 1.0) {
this._fadeIn.tween = null;
pool.push(this._fadeIn.color);
colorPool.release(this._fadeIn.color);
this._fadeIn.color = null;
}
}
Expand All @@ -652,7 +647,7 @@ export default class Camera2d extends Renderable {
// remove the tween if over
if (this._fadeOut.color.alpha === 0.0) {
this._fadeOut.tween = null;
pool.push(this._fadeOut.color);
colorPool.release(this._fadeOut.color);
this._fadeOut.color = null;
}
}
Expand Down
Loading