Skip to content

Commit f0c1c20

Browse files
committed
refactor: move color to typescript
1 parent e392c71 commit f0c1c20

20 files changed

+242
-194
lines changed

eslint.config.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ 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",
@@ -174,8 +175,9 @@ export default tseslint.config(
174175
"error",
175176
{ allowNumber: true },
176177
],
177-
"prefer-template": "error",
178178
...jsDocConfig.rules,
179+
"jsdoc/require-jsdoc": "off",
180+
"jsdoc/no-defaults": "off",
179181
},
180182
languageOptions: {
181183
parserOptions: {

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import {
1616
VIEWPORT_ONRESIZE,
1717
} from "../system/event.ts";
1818
import { boundsPool } from "./../physics/bounds.ts";
19+
import { colorPool } from "../math/color.ts";
1920

2021
/**
2122
* @import {Bounds} from "./../physics/bounds.ts";
22-
* @import Color from "./../math/color.js";
23+
* @import {Color} from "./../math/color.ts";
2324
* @import Entity from "./../renderable/entity/entity.js";
2425
* @import Sprite from "./../renderable/sprite.js";
2526
* @import NineSliceSprite from "./../renderable/nineslicesprite.js";
@@ -519,7 +520,7 @@ export default class Camera2d extends Renderable {
519520
* });
520521
*/
521522
fadeOut(color, duration = 1000, onComplete) {
522-
this._fadeOut.color = pool.pull("Color").copy(color);
523+
this._fadeOut.color = colorPool.get().copy(color);
523524
this._fadeOut.tween = pool
524525
.pull("Tween", this._fadeOut.color)
525526
.to({ alpha: 0.0 }, { duration })
@@ -539,7 +540,7 @@ export default class Camera2d extends Renderable {
539540
* me.game.viewport.fadeIn("#FFFFFF", 75);
540541
*/
541542
fadeIn(color, duration = 1000, onComplete) {
542-
this._fadeIn.color = pool.pull("Color").copy(color);
543+
this._fadeIn.color = colorPool.get().copy(color);
543544
const _alpha = this._fadeIn.color.alpha;
544545
this._fadeIn.color.alpha = 0.0;
545546
this._fadeIn.tween = pool
@@ -629,7 +630,7 @@ export default class Camera2d extends Renderable {
629630
// remove the tween if over
630631
if (this._fadeIn.color.alpha === 1.0) {
631632
this._fadeIn.tween = null;
632-
pool.push(this._fadeIn.color);
633+
colorPool.release(this._fadeIn.color);
633634
this._fadeIn.color = null;
634635
}
635636
}
@@ -646,7 +647,7 @@ export default class Camera2d extends Renderable {
646647
// remove the tween if over
647648
if (this._fadeOut.color.alpha === 0.0) {
648649
this._fadeOut.tween = null;
649-
pool.push(this._fadeOut.color);
650+
colorPool.release(this._fadeOut.color);
650651
this._fadeOut.color = null;
651652
}
652653
}

packages/melonjs/src/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import "./polyfill/index.ts";
33

44
// class definition
5-
import Color from "./math/color.js";
65
import Polygon from "./geometries/poly.js";
76
import Line from "./geometries/line.js";
87
import Ellipse from "./geometries/ellipse.js";
@@ -91,6 +90,7 @@ export { Vector2d } from "./math/vector2d.ts";
9190
export { Vector3d } from "./math/vector3d.ts";
9291
export { Matrix2d } from "./math/matrix2d.ts";
9392
export { Matrix3d } from "./math/matrix3d.ts";
93+
export { Color } from "./math/color.ts";
9494
export { Point } from "./geometries/point.ts";
9595
export { Bounds } from "./physics/bounds.ts";
9696
export { createObservableVector2d } from "./math/observableVector2d.ts";
@@ -99,7 +99,6 @@ export { getPool } from "./pool.ts";
9999

100100
// export all class definition
101101
export {
102-
Color,
103102
Polygon,
104103
Line,
105104
Ellipse,
@@ -209,7 +208,6 @@ export function boot() {
209208
pool.register("me.Trigger", Trigger);
210209
pool.register("me.Light2d", Light2d);
211210
pool.register("me.Tween", Tween, true);
212-
pool.register("me.Color", Color, true);
213211
pool.register("me.Particle", Particle, true);
214212
pool.register("me.Sprite", Sprite);
215213
pool.register("me.NineSliceSprite", NineSliceSprite);
@@ -231,7 +229,6 @@ export function boot() {
231229
pool.register("Trigger", Trigger);
232230
pool.register("Light2d", Light2d);
233231
pool.register("Tween", Tween, true);
234-
pool.register("Color", Color, true);
235232
pool.register("Particle", Particle, true);
236233
pool.register("Sprite", Sprite);
237234
pool.register("NineSliceSprite", NineSliceSprite);

packages/melonjs/src/level/tiled/TMXTileMap.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getNewTMXRenderer } from "./renderer/autodetect.js";
1414
import { warning } from "../../lang/console.js";
1515
import { eventEmitter, VIEWPORT_ONRESIZE } from "../../system/event.ts";
1616
import { vector2dPool } from "../../math/vector2d.ts";
17+
import { colorPool } from "../../math/color.ts";
1718

1819
/**
1920
* read the layer Data
@@ -53,7 +54,7 @@ function readImageLayer(map, data, z) {
5354
// convert to melonJS color format (note: this should be done earlier when parsing data)
5455
tint:
5556
typeof data.tintcolor !== "undefined"
56-
? pool.pull("Color").parseHex(data.tintcolor, true)
57+
? colorPool.get().parseHex(data.tintcolor, true)
5758
: undefined,
5859
z: z,
5960
},
@@ -446,7 +447,7 @@ export default class TMXTileMap {
446447
}
447448
// convert to melonJS renderable argument name
448449
if (typeof settings.tintcolor !== "undefined") {
449-
settings.tint = pool.pull("Color");
450+
settings.tint = colorPool.get();
450451
settings.tint.parseHex(settings.tintcolor, true);
451452
}
452453

0 commit comments

Comments
 (0)