melonjs 10.2.3 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
|
@@ -7,11 +7,7 @@ import { degToRad } from "./../../../math/math.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* @classdesc
|
|
9
9
|
* a Staggered Map Renderder
|
|
10
|
-
* @
|
|
11
|
-
* @memberOf me
|
|
12
|
-
* @extends me.TMXHexagonalRenderer
|
|
13
|
-
* @constructor
|
|
14
|
-
* @param {me.TMXTileMap} map the TMX map
|
|
10
|
+
* @augments TMXHexagonalRenderer
|
|
15
11
|
*/
|
|
16
12
|
class TMXStaggeredRenderer extends TMXHexagonalRenderer {
|
|
17
13
|
|
package/src/loader/loader.js
CHANGED
|
@@ -294,7 +294,6 @@ function preloadJavascript(data, onload, onerror) {
|
|
|
294
294
|
/**
|
|
295
295
|
* a small class to manage loading of stuff and manage resources
|
|
296
296
|
* @namespace loader
|
|
297
|
-
* @memberOf me
|
|
298
297
|
*/
|
|
299
298
|
var loader = {
|
|
300
299
|
|
|
@@ -313,7 +312,7 @@ var loader = {
|
|
|
313
312
|
* @public
|
|
314
313
|
* @function
|
|
315
314
|
* @name onload
|
|
316
|
-
* @
|
|
315
|
+
* @memberof loader
|
|
317
316
|
* @example
|
|
318
317
|
* // set a callback when everything is loaded
|
|
319
318
|
* me.loader.onload = this.loaded.bind(this);
|
|
@@ -327,7 +326,7 @@ var loader = {
|
|
|
327
326
|
* @public
|
|
328
327
|
* @function
|
|
329
328
|
* @name onProgress
|
|
330
|
-
* @
|
|
329
|
+
* @memberof loader
|
|
331
330
|
* @example
|
|
332
331
|
* // set a callback for progress notification
|
|
333
332
|
* me.loader.onProgress = this.updateProgress.bind(this);
|
|
@@ -343,7 +342,7 @@ var loader = {
|
|
|
343
342
|
* @type {string}
|
|
344
343
|
* @name crossOrigin
|
|
345
344
|
* @default undefined
|
|
346
|
-
* @
|
|
345
|
+
* @memberof loader
|
|
347
346
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
|
|
348
347
|
* @example
|
|
349
348
|
* // allow for cross-origin texture loading in WebGL
|
|
@@ -361,7 +360,7 @@ var loader = {
|
|
|
361
360
|
* @type {boolean}
|
|
362
361
|
* @name withCredentials
|
|
363
362
|
* @default false
|
|
364
|
-
* @
|
|
363
|
+
* @memberof loader
|
|
365
364
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
|
|
366
365
|
* @example
|
|
367
366
|
* // enable withCredentials
|
|
@@ -411,7 +410,7 @@ var loader = {
|
|
|
411
410
|
* change the default baseURL for the given asset type.<br>
|
|
412
411
|
* (this will prepend the asset URL and must finish with a '/')
|
|
413
412
|
* @name setBaseURL
|
|
414
|
-
* @
|
|
413
|
+
* @memberof loader
|
|
415
414
|
* @public
|
|
416
415
|
* @function
|
|
417
416
|
* @param {string} type "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
|
|
@@ -442,7 +441,7 @@ var loader = {
|
|
|
442
441
|
/**
|
|
443
442
|
* set all the specified game resources to be preloaded.
|
|
444
443
|
* @name preload
|
|
445
|
-
* @
|
|
444
|
+
* @memberof loader
|
|
446
445
|
* @public
|
|
447
446
|
* @function
|
|
448
447
|
* @param {object[]} res
|
|
@@ -450,7 +449,7 @@ var loader = {
|
|
|
450
449
|
* @param {string} res.type "audio", binary", "image", "json","js", "tmx", "tsx", "fontface"
|
|
451
450
|
* @param {string} res.src path and/or file name of the resource (for audio assets only the path is required)
|
|
452
451
|
* @param {boolean} [res.stream] Set to true to force HTML5 Audio, which allows not to wait for large file to be downloaded before playing.
|
|
453
|
-
* @param {Function} [onload=
|
|
452
|
+
* @param {Function} [onload=loader.onload] function to be called when all resources are loaded
|
|
454
453
|
* @param {boolean} [switchToLoadState=true] automatically switch to the loading screen
|
|
455
454
|
* @example
|
|
456
455
|
* game_resources = [
|
|
@@ -507,7 +506,7 @@ var loader = {
|
|
|
507
506
|
/**
|
|
508
507
|
* Load a single resource (to be used if you need to load additional resource during the game)
|
|
509
508
|
* @name load
|
|
510
|
-
* @
|
|
509
|
+
* @memberof loader
|
|
511
510
|
* @public
|
|
512
511
|
* @function
|
|
513
512
|
* @param {object} res
|
|
@@ -577,12 +576,14 @@ var loader = {
|
|
|
577
576
|
/**
|
|
578
577
|
* unload specified resource to free memory
|
|
579
578
|
* @name unload
|
|
580
|
-
* @
|
|
579
|
+
* @memberof loader
|
|
581
580
|
* @public
|
|
582
581
|
* @function
|
|
583
582
|
* @param {object} res
|
|
583
|
+
* @param {string} res.name internal name of the resource
|
|
584
|
+
* @param {string} res.type "audio", binary", "image", "json", "tmx", "tsx"
|
|
584
585
|
* @returns {boolean} true if unloaded
|
|
585
|
-
* @example me.loader.unload({name: "avatar", type:"image"
|
|
586
|
+
* @example me.loader.unload({name: "avatar", type:"image"});
|
|
586
587
|
*/
|
|
587
588
|
unload(res) {
|
|
588
589
|
switch (res.type) {
|
|
@@ -637,7 +638,7 @@ var loader = {
|
|
|
637
638
|
/**
|
|
638
639
|
* unload all resources to free memory
|
|
639
640
|
* @name unloadAll
|
|
640
|
-
* @
|
|
641
|
+
* @memberof loader
|
|
641
642
|
* @public
|
|
642
643
|
* @function
|
|
643
644
|
* @example me.loader.unloadAll();
|
|
@@ -692,7 +693,7 @@ var loader = {
|
|
|
692
693
|
/**
|
|
693
694
|
* return the specified TMX/TSX object
|
|
694
695
|
* @name getTMX
|
|
695
|
-
* @
|
|
696
|
+
* @memberof loader
|
|
696
697
|
* @public
|
|
697
698
|
* @function
|
|
698
699
|
* @param {string} elt name of the tmx/tsx element ("map1");
|
|
@@ -710,7 +711,7 @@ var loader = {
|
|
|
710
711
|
/**
|
|
711
712
|
* return the specified Binary object
|
|
712
713
|
* @name getBinary
|
|
713
|
-
* @
|
|
714
|
+
* @memberof loader
|
|
714
715
|
* @public
|
|
715
716
|
* @function
|
|
716
717
|
* @param {string} elt name of the binary object ("ymTrack");
|
|
@@ -728,7 +729,7 @@ var loader = {
|
|
|
728
729
|
/**
|
|
729
730
|
* return the specified Image Object
|
|
730
731
|
* @name getImage
|
|
731
|
-
* @
|
|
732
|
+
* @memberof loader
|
|
732
733
|
* @public
|
|
733
734
|
* @function
|
|
734
735
|
* @param {string} image name of the Image element ("tileset-platformer");
|
|
@@ -747,7 +748,7 @@ var loader = {
|
|
|
747
748
|
/**
|
|
748
749
|
* return the specified JSON Object
|
|
749
750
|
* @name getJSON
|
|
750
|
-
* @
|
|
751
|
+
* @memberof loader
|
|
751
752
|
* @public
|
|
752
753
|
* @function
|
|
753
754
|
* @param {string} elt name of the json file to load
|
|
@@ -4,7 +4,6 @@ import * as event from "./../system/event.js";
|
|
|
4
4
|
import {nextPowerOfTwo} from "./../math/math.js";
|
|
5
5
|
import pool from "./../system/pooling.js";
|
|
6
6
|
import Renderable from "./../renderable/renderable.js";
|
|
7
|
-
import ColorLayer from "./../renderable/colorlayer.js";
|
|
8
7
|
import Stage from "./../state/stage.js";
|
|
9
8
|
|
|
10
9
|
|
|
@@ -118,9 +117,7 @@ class IconLogo extends Renderable {
|
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
119
|
* a default loading screen
|
|
121
|
-
* @memberOf me
|
|
122
120
|
* @ignore
|
|
123
|
-
* @constructor
|
|
124
121
|
*/
|
|
125
122
|
class DefaultLoadingScreen extends Stage {
|
|
126
123
|
/**
|
|
@@ -130,8 +127,8 @@ class DefaultLoadingScreen extends Stage {
|
|
|
130
127
|
onResetEvent() {
|
|
131
128
|
var barHeight = 8;
|
|
132
129
|
|
|
133
|
-
//
|
|
134
|
-
world.
|
|
130
|
+
// set a background color
|
|
131
|
+
world.backgroundColor.parseCSS("#202020");
|
|
135
132
|
|
|
136
133
|
// progress bar
|
|
137
134
|
world.addChild(new ProgressBar(
|
package/src/math/color.js
CHANGED
|
@@ -172,18 +172,16 @@ var cssToRGB = new Map();
|
|
|
172
172
|
/**
|
|
173
173
|
* @classdesc
|
|
174
174
|
* A color manipulation object.
|
|
175
|
-
* @class Color
|
|
176
|
-
* @memberOf me
|
|
177
|
-
* @constructor
|
|
178
|
-
* @param {number|Float32Array} [r=0] red component or array of color components
|
|
179
|
-
* @param {number} [g=0] green component
|
|
180
|
-
* @param {number} [b=0] blue component
|
|
181
|
-
* @param {number} [alpha=1.0] alpha value
|
|
182
175
|
*/
|
|
183
176
|
class Color {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
177
|
+
/**
|
|
178
|
+
* @param {number} [r=0] red component or array of color components
|
|
179
|
+
* @param {number} [g=0] green component
|
|
180
|
+
* @param {number} [b=0] blue component
|
|
181
|
+
* @param {number} [alpha=1.0] alpha value
|
|
182
|
+
*/
|
|
183
|
+
constructor(r = 0, g = 0, b = 0, alpha = 1.0) {
|
|
184
|
+
this.onResetEvent(r, g, b, alpha);
|
|
187
185
|
}
|
|
188
186
|
|
|
189
187
|
/**
|
|
@@ -204,11 +202,8 @@ class Color {
|
|
|
204
202
|
/**
|
|
205
203
|
* Color Red Component [0 .. 255]
|
|
206
204
|
* @type {number}
|
|
207
|
-
* @
|
|
208
|
-
* @readonly
|
|
209
|
-
* @memberOf me.Color
|
|
205
|
+
* @memberof Color
|
|
210
206
|
*/
|
|
211
|
-
|
|
212
207
|
get r() {
|
|
213
208
|
return ~~(this.glArray[0] * 255);
|
|
214
209
|
}
|
|
@@ -221,11 +216,8 @@ class Color {
|
|
|
221
216
|
/**
|
|
222
217
|
* Color Green Component [0 .. 255]
|
|
223
218
|
* @type {number}
|
|
224
|
-
* @
|
|
225
|
-
* @readonly
|
|
226
|
-
* @memberOf me.Color
|
|
219
|
+
* @memberof Color
|
|
227
220
|
*/
|
|
228
|
-
|
|
229
221
|
get g() {
|
|
230
222
|
return ~~(this.glArray[1] * 255);
|
|
231
223
|
}
|
|
@@ -238,15 +230,11 @@ class Color {
|
|
|
238
230
|
/**
|
|
239
231
|
* Color Blue Component [0 .. 255]
|
|
240
232
|
* @type {number}
|
|
241
|
-
* @
|
|
242
|
-
* @readonly
|
|
243
|
-
* @memberOf me.Color
|
|
233
|
+
* @memberof Color
|
|
244
234
|
*/
|
|
245
|
-
|
|
246
235
|
get b() {
|
|
247
236
|
return ~~(this.glArray[2] * 255);
|
|
248
237
|
}
|
|
249
|
-
|
|
250
238
|
set b(value) {
|
|
251
239
|
this.glArray[2] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
252
240
|
}
|
|
@@ -254,11 +242,8 @@ class Color {
|
|
|
254
242
|
/**
|
|
255
243
|
* Color Alpha Component [0.0 .. 1.0]
|
|
256
244
|
* @type {number}
|
|
257
|
-
* @
|
|
258
|
-
* @readonly
|
|
259
|
-
* @memberOf me.Color
|
|
245
|
+
* @memberof Color
|
|
260
246
|
*/
|
|
261
|
-
|
|
262
247
|
get alpha() {
|
|
263
248
|
return this.glArray[3];
|
|
264
249
|
}
|
|
@@ -271,20 +256,15 @@ class Color {
|
|
|
271
256
|
/**
|
|
272
257
|
* Set this color to the specified value.
|
|
273
258
|
* @name setColor
|
|
274
|
-
* @
|
|
259
|
+
* @memberof Color
|
|
275
260
|
* @function
|
|
276
261
|
* @param {number} r red component [0 .. 255]
|
|
277
262
|
* @param {number} g green component [0 .. 255]
|
|
278
263
|
* @param {number} b blue component [0 .. 255]
|
|
279
264
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
280
|
-
* @returns {
|
|
265
|
+
* @returns {Color} Reference to this object for method chaining
|
|
281
266
|
*/
|
|
282
267
|
setColor(r, g, b, alpha = 1.0) {
|
|
283
|
-
// Private initialization: copy Color value directly
|
|
284
|
-
if (r instanceof Color) {
|
|
285
|
-
this.glArray.set(r.glArray);
|
|
286
|
-
return r;
|
|
287
|
-
}
|
|
288
268
|
this.r = r;
|
|
289
269
|
this.g = g;
|
|
290
270
|
this.b = b;
|
|
@@ -295,21 +275,21 @@ class Color {
|
|
|
295
275
|
/**
|
|
296
276
|
* Create a new copy of this color object.
|
|
297
277
|
* @name clone
|
|
298
|
-
* @
|
|
278
|
+
* @memberof Color
|
|
299
279
|
* @function
|
|
300
|
-
* @returns {
|
|
280
|
+
* @returns {Color} Reference to the newly cloned object
|
|
301
281
|
*/
|
|
302
282
|
clone() {
|
|
303
|
-
return pool.pull("Color"
|
|
283
|
+
return pool.pull("Color").copy(this);
|
|
304
284
|
}
|
|
305
285
|
|
|
306
286
|
/**
|
|
307
287
|
* Copy a color object or CSS color into this one.
|
|
308
288
|
* @name copy
|
|
309
|
-
* @
|
|
289
|
+
* @memberof Color
|
|
310
290
|
* @function
|
|
311
|
-
* @param {
|
|
312
|
-
* @returns {
|
|
291
|
+
* @param {Color|string} color
|
|
292
|
+
* @returns {Color} Reference to this object for method chaining
|
|
313
293
|
*/
|
|
314
294
|
copy(color) {
|
|
315
295
|
if (color instanceof Color) {
|
|
@@ -323,10 +303,10 @@ class Color {
|
|
|
323
303
|
/**
|
|
324
304
|
* Blend this color with the given one using addition.
|
|
325
305
|
* @name add
|
|
326
|
-
* @
|
|
306
|
+
* @memberof Color
|
|
327
307
|
* @function
|
|
328
|
-
* @param {
|
|
329
|
-
* @returns {
|
|
308
|
+
* @param {Color} color
|
|
309
|
+
* @returns {Color} Reference to this object for method chaining
|
|
330
310
|
*/
|
|
331
311
|
add(color) {
|
|
332
312
|
this.glArray[0] = clamp(this.glArray[0] + color.glArray[0], 0, 1);
|
|
@@ -340,10 +320,10 @@ class Color {
|
|
|
340
320
|
/**
|
|
341
321
|
* Darken this color value by 0..1
|
|
342
322
|
* @name darken
|
|
343
|
-
* @
|
|
323
|
+
* @memberof Color
|
|
344
324
|
* @function
|
|
345
325
|
* @param {number} scale
|
|
346
|
-
* @returns {
|
|
326
|
+
* @returns {Color} Reference to this object for method chaining
|
|
347
327
|
*/
|
|
348
328
|
darken(scale) {
|
|
349
329
|
scale = clamp(scale, 0, 1);
|
|
@@ -357,11 +337,11 @@ class Color {
|
|
|
357
337
|
/**
|
|
358
338
|
* Linearly interpolate between this color and the given one.
|
|
359
339
|
* @name lerp
|
|
360
|
-
* @
|
|
340
|
+
* @memberof Color
|
|
361
341
|
* @function
|
|
362
|
-
* @param {
|
|
342
|
+
* @param {Color} color
|
|
363
343
|
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
364
|
-
* @returns {
|
|
344
|
+
* @returns {Color} Reference to this object for method chaining
|
|
365
345
|
*/
|
|
366
346
|
lerp(color, alpha) {
|
|
367
347
|
alpha = clamp(alpha, 0, 1);
|
|
@@ -375,10 +355,10 @@ class Color {
|
|
|
375
355
|
/**
|
|
376
356
|
* Lighten this color value by 0..1
|
|
377
357
|
* @name lighten
|
|
378
|
-
* @
|
|
358
|
+
* @memberof Color
|
|
379
359
|
* @function
|
|
380
360
|
* @param {number} scale
|
|
381
|
-
* @returns {
|
|
361
|
+
* @returns {Color} Reference to this object for method chaining
|
|
382
362
|
*/
|
|
383
363
|
lighten(scale) {
|
|
384
364
|
scale = clamp(scale, 0, 1);
|
|
@@ -392,11 +372,11 @@ class Color {
|
|
|
392
372
|
/**
|
|
393
373
|
* Generate random r,g,b values for this color object
|
|
394
374
|
* @name random
|
|
395
|
-
* @
|
|
375
|
+
* @memberof Color
|
|
396
376
|
* @function
|
|
397
377
|
* @param {number} [min=0] minimum value for the random range
|
|
398
378
|
* @param {number} [max=255] maxmium value for the random range
|
|
399
|
-
* @returns {
|
|
379
|
+
* @returns {Color} Reference to this object for method chaining
|
|
400
380
|
*/
|
|
401
381
|
random(min = 0, max = 255) {
|
|
402
382
|
if (min < 0) {
|
|
@@ -418,9 +398,9 @@ class Color {
|
|
|
418
398
|
* Return true if the r,g,b,a values of this color are equal with the
|
|
419
399
|
* given one.
|
|
420
400
|
* @name equals
|
|
421
|
-
* @
|
|
401
|
+
* @memberof Color
|
|
422
402
|
* @function
|
|
423
|
-
* @param {
|
|
403
|
+
* @param {Color} color
|
|
424
404
|
* @returns {boolean}
|
|
425
405
|
*/
|
|
426
406
|
equals(color) {
|
|
@@ -436,10 +416,10 @@ class Color {
|
|
|
436
416
|
* Parse a CSS color string and set this color to the corresponding
|
|
437
417
|
* r,g,b values
|
|
438
418
|
* @name parseCSS
|
|
439
|
-
* @
|
|
419
|
+
* @memberof Color
|
|
440
420
|
* @function
|
|
441
421
|
* @param {string} cssColor
|
|
442
|
-
* @returns {
|
|
422
|
+
* @returns {Color} Reference to this object for method chaining
|
|
443
423
|
*/
|
|
444
424
|
parseCSS(cssColor) {
|
|
445
425
|
// TODO : Memoize this function by caching its input
|
|
@@ -454,10 +434,10 @@ class Color {
|
|
|
454
434
|
/**
|
|
455
435
|
* Parse an RGB or RGBA CSS color string
|
|
456
436
|
* @name parseRGB
|
|
457
|
-
* @
|
|
437
|
+
* @memberof Color
|
|
458
438
|
* @function
|
|
459
439
|
* @param {string} rgbColor
|
|
460
|
-
* @returns {
|
|
440
|
+
* @returns {Color} Reference to this object for method chaining
|
|
461
441
|
*/
|
|
462
442
|
parseRGB(rgbColor) {
|
|
463
443
|
// TODO : Memoize this function by caching its input
|
|
@@ -474,11 +454,11 @@ class Color {
|
|
|
474
454
|
* Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
|
|
475
455
|
* the corresponding r,g,b,a values
|
|
476
456
|
* @name parseHex
|
|
477
|
-
* @
|
|
457
|
+
* @memberof Color
|
|
478
458
|
* @function
|
|
479
459
|
* @param {string} hexColor
|
|
480
460
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
481
|
-
* @returns {
|
|
461
|
+
* @returns {Color} Reference to this object for method chaining
|
|
482
462
|
*/
|
|
483
463
|
parseHex(hexColor, argb = false) {
|
|
484
464
|
// TODO : Memoize this function by caching its input
|
|
@@ -534,10 +514,10 @@ class Color {
|
|
|
534
514
|
/**
|
|
535
515
|
* Pack this color into a Uint32 ARGB representation
|
|
536
516
|
* @name toUint32
|
|
537
|
-
* @
|
|
517
|
+
* @memberof Color
|
|
538
518
|
* @function
|
|
539
519
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
540
|
-
* @returns {
|
|
520
|
+
* @returns {number}
|
|
541
521
|
*/
|
|
542
522
|
toUint32(alpha = this.alpha) {
|
|
543
523
|
var ur = this.r & 0xff;
|
|
@@ -551,7 +531,7 @@ class Color {
|
|
|
551
531
|
/**
|
|
552
532
|
* return an array representation of this object
|
|
553
533
|
* @name toArray
|
|
554
|
-
* @
|
|
534
|
+
* @memberof Color
|
|
555
535
|
* @function
|
|
556
536
|
* @returns {Float32Array}
|
|
557
537
|
*/
|
|
@@ -563,7 +543,7 @@ class Color {
|
|
|
563
543
|
/**
|
|
564
544
|
* Get the color in "#RRGGBB" format
|
|
565
545
|
* @name toHex
|
|
566
|
-
* @
|
|
546
|
+
* @memberof Color
|
|
567
547
|
* @function
|
|
568
548
|
* @returns {string}
|
|
569
549
|
*/
|
|
@@ -577,7 +557,7 @@ class Color {
|
|
|
577
557
|
/**
|
|
578
558
|
* Get the color in "#RRGGBBAA" format
|
|
579
559
|
* @name toHex8
|
|
580
|
-
* @
|
|
560
|
+
* @memberof Color
|
|
581
561
|
* @function
|
|
582
562
|
* @returns {string}
|
|
583
563
|
*/
|
|
@@ -591,7 +571,7 @@ class Color {
|
|
|
591
571
|
/**
|
|
592
572
|
* Get the color in "rgb(R,G,B)" format
|
|
593
573
|
* @name toRGB
|
|
594
|
-
* @
|
|
574
|
+
* @memberof Color
|
|
595
575
|
* @function
|
|
596
576
|
* @returns {string}
|
|
597
577
|
*/
|
|
@@ -609,7 +589,7 @@ class Color {
|
|
|
609
589
|
/**
|
|
610
590
|
* Get the color in "rgba(R,G,B,A)" format
|
|
611
591
|
* @name toRGBA
|
|
612
|
-
* @
|
|
592
|
+
* @memberof Color
|
|
613
593
|
* @function
|
|
614
594
|
* @returns {string}
|
|
615
595
|
*/
|
package/src/math/math.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* a collection of math utility functions
|
|
3
3
|
* @namespace Math
|
|
4
|
-
* @memberOf me
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -9,7 +8,7 @@
|
|
|
9
8
|
* @public
|
|
10
9
|
* @type {number}
|
|
11
10
|
* @name DEG_TO_RAD
|
|
12
|
-
* @
|
|
11
|
+
* @memberof Math
|
|
13
12
|
*/
|
|
14
13
|
export const DEG_TO_RAD = Math.PI / 180.0;
|
|
15
14
|
|
|
@@ -18,7 +17,7 @@ export const DEG_TO_RAD = Math.PI / 180.0;
|
|
|
18
17
|
* @public
|
|
19
18
|
* @type {number}
|
|
20
19
|
* @name RAD_TO_DEG
|
|
21
|
-
* @
|
|
20
|
+
* @memberof Math
|
|
22
21
|
*/
|
|
23
22
|
export const RAD_TO_DEG = 180.0 / Math.PI;
|
|
24
23
|
|
|
@@ -27,7 +26,7 @@ export const RAD_TO_DEG = 180.0 / Math.PI;
|
|
|
27
26
|
* @public
|
|
28
27
|
* @type {number}
|
|
29
28
|
* @name TAU
|
|
30
|
-
* @
|
|
29
|
+
* @memberof Math
|
|
31
30
|
*/
|
|
32
31
|
export const TAU = Math.PI * 2;
|
|
33
32
|
|
|
@@ -36,7 +35,7 @@ export const TAU = Math.PI * 2;
|
|
|
36
35
|
* @public
|
|
37
36
|
* @type {number}
|
|
38
37
|
* @name ETA
|
|
39
|
-
* @
|
|
38
|
+
* @memberof Math
|
|
40
39
|
*/
|
|
41
40
|
export const ETA = Math.PI * 0.5;
|
|
42
41
|
|
|
@@ -45,7 +44,7 @@ export const ETA = Math.PI * 0.5;
|
|
|
45
44
|
* @public
|
|
46
45
|
* @type {number}
|
|
47
46
|
* @name EPSILON
|
|
48
|
-
* @
|
|
47
|
+
* @memberof Math
|
|
49
48
|
*/
|
|
50
49
|
export const EPSILON = 0.000001;
|
|
51
50
|
|
|
@@ -53,7 +52,7 @@ export const EPSILON = 0.000001;
|
|
|
53
52
|
* returns true if the given value is a power of two
|
|
54
53
|
* @public
|
|
55
54
|
* @function
|
|
56
|
-
* @
|
|
55
|
+
* @memberof Math
|
|
57
56
|
* @name isPowerOfTwo
|
|
58
57
|
* @param {number} val
|
|
59
58
|
* @returns {boolean}
|
|
@@ -66,7 +65,7 @@ export function isPowerOfTwo(val) {
|
|
|
66
65
|
* returns the next power of two for the given value
|
|
67
66
|
* @public
|
|
68
67
|
* @function
|
|
69
|
-
* @
|
|
68
|
+
* @memberof Math
|
|
70
69
|
* @name nextPowerOfTwo
|
|
71
70
|
* @param {number} val
|
|
72
71
|
* @returns {boolean}
|
|
@@ -86,7 +85,7 @@ export function nextPowerOfTwo(val) {
|
|
|
86
85
|
* Converts an angle in degrees to an angle in radians
|
|
87
86
|
* @public
|
|
88
87
|
* @function
|
|
89
|
-
* @
|
|
88
|
+
* @memberof Math
|
|
90
89
|
* @name degToRad
|
|
91
90
|
* @param {number} angle angle in degrees
|
|
92
91
|
* @returns {number} corresponding angle in radians
|
|
@@ -102,7 +101,7 @@ export function degToRad(angle) {
|
|
|
102
101
|
* Converts an angle in radians to an angle in degrees.
|
|
103
102
|
* @public
|
|
104
103
|
* @function
|
|
105
|
-
* @
|
|
104
|
+
* @memberof Math
|
|
106
105
|
* @name radToDeg
|
|
107
106
|
* @param {number} radians angle in radians
|
|
108
107
|
* @returns {number} corresponding angle in degrees
|
|
@@ -118,7 +117,7 @@ export function radToDeg(radians) {
|
|
|
118
117
|
* clamp the given value
|
|
119
118
|
* @public
|
|
120
119
|
* @function
|
|
121
|
-
* @
|
|
120
|
+
* @memberof Math
|
|
122
121
|
* @name clamp
|
|
123
122
|
* @param {number} val the value to clamp
|
|
124
123
|
* @param {number} low lower limit
|
|
@@ -133,7 +132,7 @@ export function clamp(val, low, high) {
|
|
|
133
132
|
* return a random integer between min (included) and max (excluded)
|
|
134
133
|
* @public
|
|
135
134
|
* @function
|
|
136
|
-
* @
|
|
135
|
+
* @memberof Math
|
|
137
136
|
* @name random
|
|
138
137
|
* @param {number} min minimum value.
|
|
139
138
|
* @param {number} max maximum value.
|
|
@@ -150,7 +149,7 @@ export function random(min, max) {
|
|
|
150
149
|
* return a random float between min, max (exclusive)
|
|
151
150
|
* @public
|
|
152
151
|
* @function
|
|
153
|
-
* @
|
|
152
|
+
* @memberof Math
|
|
154
153
|
* @name randomFloat
|
|
155
154
|
* @param {number} min minimum value.
|
|
156
155
|
* @param {number} max maximum value.
|
|
@@ -167,7 +166,7 @@ export function randomFloat(min, max) {
|
|
|
167
166
|
* return a weighted random between min, max (exclusive)
|
|
168
167
|
* @public
|
|
169
168
|
* @function
|
|
170
|
-
* @
|
|
169
|
+
* @memberof Math
|
|
171
170
|
* @name weightedRandom
|
|
172
171
|
* @param {number} min minimum value.
|
|
173
172
|
* @param {number} max maximum value.
|
|
@@ -184,7 +183,7 @@ export function weightedRandom(min, max) {
|
|
|
184
183
|
* round a value to the specified number of digit
|
|
185
184
|
* @public
|
|
186
185
|
* @function
|
|
187
|
-
* @
|
|
186
|
+
* @memberof Math
|
|
188
187
|
* @name round
|
|
189
188
|
* @param {number} num value to be rounded.
|
|
190
189
|
* @param {number} [dec=0] number of decimal digit to be rounded to.
|
|
@@ -203,7 +202,7 @@ export function round(num, dec = 0) {
|
|
|
203
202
|
* check if the given value is close to the expected one
|
|
204
203
|
* @public
|
|
205
204
|
* @function
|
|
206
|
-
* @
|
|
205
|
+
* @memberof Math
|
|
207
206
|
* @name toBeCloseTo
|
|
208
207
|
* @param {number} expected value to be compared with.
|
|
209
208
|
* @param {number} actual actual value to compare
|