melonjs 10.3.0 → 10.5.1
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 +3147 -3293
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3411 -3852
- package/dist/melonjs.module.js +3448 -3210
- package/package.json +18 -17
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +9 -26
- 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 +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +65 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +39 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +46 -143
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +114 -125
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- 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 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- 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 +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +24 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
- package/src/entity/draggable.js +0 -130
- package/src/entity/droptarget.js +0 -101
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
509
|
+
* @memberof loader
|
|
511
510
|
* @public
|
|
512
511
|
* @function
|
|
513
512
|
* @param {object} res
|
|
@@ -577,7 +576,7 @@ var loader = {
|
|
|
577
576
|
/**
|
|
578
577
|
* unload specified resource to free memory
|
|
579
578
|
* @name unload
|
|
580
|
-
* @memberof
|
|
579
|
+
* @memberof loader
|
|
581
580
|
* @public
|
|
582
581
|
* @function
|
|
583
582
|
* @param {object} res
|
|
@@ -639,7 +638,7 @@ var loader = {
|
|
|
639
638
|
/**
|
|
640
639
|
* unload all resources to free memory
|
|
641
640
|
* @name unloadAll
|
|
642
|
-
* @memberof
|
|
641
|
+
* @memberof loader
|
|
643
642
|
* @public
|
|
644
643
|
* @function
|
|
645
644
|
* @example me.loader.unloadAll();
|
|
@@ -694,7 +693,7 @@ var loader = {
|
|
|
694
693
|
/**
|
|
695
694
|
* return the specified TMX/TSX object
|
|
696
695
|
* @name getTMX
|
|
697
|
-
* @memberof
|
|
696
|
+
* @memberof loader
|
|
698
697
|
* @public
|
|
699
698
|
* @function
|
|
700
699
|
* @param {string} elt name of the tmx/tsx element ("map1");
|
|
@@ -712,7 +711,7 @@ var loader = {
|
|
|
712
711
|
/**
|
|
713
712
|
* return the specified Binary object
|
|
714
713
|
* @name getBinary
|
|
715
|
-
* @memberof
|
|
714
|
+
* @memberof loader
|
|
716
715
|
* @public
|
|
717
716
|
* @function
|
|
718
717
|
* @param {string} elt name of the binary object ("ymTrack");
|
|
@@ -730,7 +729,7 @@ var loader = {
|
|
|
730
729
|
/**
|
|
731
730
|
* return the specified Image Object
|
|
732
731
|
* @name getImage
|
|
733
|
-
* @memberof
|
|
732
|
+
* @memberof loader
|
|
734
733
|
* @public
|
|
735
734
|
* @function
|
|
736
735
|
* @param {string} image name of the Image element ("tileset-platformer");
|
|
@@ -749,7 +748,7 @@ var loader = {
|
|
|
749
748
|
/**
|
|
750
749
|
* return the specified JSON Object
|
|
751
750
|
* @name getJSON
|
|
752
|
-
* @memberof
|
|
751
|
+
* @memberof loader
|
|
753
752
|
* @public
|
|
754
753
|
* @function
|
|
755
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,7 +117,6 @@ class IconLogo extends Renderable {
|
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
119
|
* a default loading screen
|
|
121
|
-
* @memberof me
|
|
122
120
|
* @ignore
|
|
123
121
|
*/
|
|
124
122
|
class DefaultLoadingScreen extends Stage {
|
|
@@ -129,8 +127,8 @@ class DefaultLoadingScreen extends Stage {
|
|
|
129
127
|
onResetEvent() {
|
|
130
128
|
var barHeight = 8;
|
|
131
129
|
|
|
132
|
-
//
|
|
133
|
-
world.
|
|
130
|
+
// set a background color
|
|
131
|
+
world.backgroundColor.parseCSS("#202020");
|
|
134
132
|
|
|
135
133
|
// progress bar
|
|
136
134
|
world.addChild(new ProgressBar(
|
package/src/math/color.js
CHANGED
|
@@ -172,17 +172,16 @@ var cssToRGB = new Map();
|
|
|
172
172
|
/**
|
|
173
173
|
* @classdesc
|
|
174
174
|
* A color manipulation object.
|
|
175
|
-
* @class Color
|
|
176
|
-
* @memberof me
|
|
177
|
-
* @param {number|Float32Array} [r=0] red component or array of color components
|
|
178
|
-
* @param {number} [g=0] green component
|
|
179
|
-
* @param {number} [b=0] blue component
|
|
180
|
-
* @param {number} [alpha=1.0] alpha value
|
|
181
175
|
*/
|
|
182
176
|
class Color {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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);
|
|
186
185
|
}
|
|
187
186
|
|
|
188
187
|
/**
|
|
@@ -203,11 +202,8 @@ class Color {
|
|
|
203
202
|
/**
|
|
204
203
|
* Color Red Component [0 .. 255]
|
|
205
204
|
* @type {number}
|
|
206
|
-
* @
|
|
207
|
-
* @readonly
|
|
208
|
-
* @memberof me.Color
|
|
205
|
+
* @memberof Color
|
|
209
206
|
*/
|
|
210
|
-
|
|
211
207
|
get r() {
|
|
212
208
|
return ~~(this.glArray[0] * 255);
|
|
213
209
|
}
|
|
@@ -220,11 +216,8 @@ class Color {
|
|
|
220
216
|
/**
|
|
221
217
|
* Color Green Component [0 .. 255]
|
|
222
218
|
* @type {number}
|
|
223
|
-
* @
|
|
224
|
-
* @readonly
|
|
225
|
-
* @memberof me.Color
|
|
219
|
+
* @memberof Color
|
|
226
220
|
*/
|
|
227
|
-
|
|
228
221
|
get g() {
|
|
229
222
|
return ~~(this.glArray[1] * 255);
|
|
230
223
|
}
|
|
@@ -237,15 +230,11 @@ class Color {
|
|
|
237
230
|
/**
|
|
238
231
|
* Color Blue Component [0 .. 255]
|
|
239
232
|
* @type {number}
|
|
240
|
-
* @
|
|
241
|
-
* @readonly
|
|
242
|
-
* @memberof me.Color
|
|
233
|
+
* @memberof Color
|
|
243
234
|
*/
|
|
244
|
-
|
|
245
235
|
get b() {
|
|
246
236
|
return ~~(this.glArray[2] * 255);
|
|
247
237
|
}
|
|
248
|
-
|
|
249
238
|
set b(value) {
|
|
250
239
|
this.glArray[2] = clamp(~~value || 0, 0, 255) / 255.0;
|
|
251
240
|
}
|
|
@@ -253,11 +242,8 @@ class Color {
|
|
|
253
242
|
/**
|
|
254
243
|
* Color Alpha Component [0.0 .. 1.0]
|
|
255
244
|
* @type {number}
|
|
256
|
-
* @
|
|
257
|
-
* @readonly
|
|
258
|
-
* @memberof me.Color
|
|
245
|
+
* @memberof Color
|
|
259
246
|
*/
|
|
260
|
-
|
|
261
247
|
get alpha() {
|
|
262
248
|
return this.glArray[3];
|
|
263
249
|
}
|
|
@@ -270,20 +256,15 @@ class Color {
|
|
|
270
256
|
/**
|
|
271
257
|
* Set this color to the specified value.
|
|
272
258
|
* @name setColor
|
|
273
|
-
* @memberof
|
|
259
|
+
* @memberof Color
|
|
274
260
|
* @function
|
|
275
261
|
* @param {number} r red component [0 .. 255]
|
|
276
262
|
* @param {number} g green component [0 .. 255]
|
|
277
263
|
* @param {number} b blue component [0 .. 255]
|
|
278
264
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
279
|
-
* @returns {
|
|
265
|
+
* @returns {Color} Reference to this object for method chaining
|
|
280
266
|
*/
|
|
281
267
|
setColor(r, g, b, alpha = 1.0) {
|
|
282
|
-
// Private initialization: copy Color value directly
|
|
283
|
-
if (r instanceof Color) {
|
|
284
|
-
this.glArray.set(r.glArray);
|
|
285
|
-
return r;
|
|
286
|
-
}
|
|
287
268
|
this.r = r;
|
|
288
269
|
this.g = g;
|
|
289
270
|
this.b = b;
|
|
@@ -294,21 +275,21 @@ class Color {
|
|
|
294
275
|
/**
|
|
295
276
|
* Create a new copy of this color object.
|
|
296
277
|
* @name clone
|
|
297
|
-
* @memberof
|
|
278
|
+
* @memberof Color
|
|
298
279
|
* @function
|
|
299
|
-
* @returns {
|
|
280
|
+
* @returns {Color} Reference to the newly cloned object
|
|
300
281
|
*/
|
|
301
282
|
clone() {
|
|
302
|
-
return pool.pull("Color"
|
|
283
|
+
return pool.pull("Color").copy(this);
|
|
303
284
|
}
|
|
304
285
|
|
|
305
286
|
/**
|
|
306
287
|
* Copy a color object or CSS color into this one.
|
|
307
288
|
* @name copy
|
|
308
|
-
* @memberof
|
|
289
|
+
* @memberof Color
|
|
309
290
|
* @function
|
|
310
|
-
* @param {
|
|
311
|
-
* @returns {
|
|
291
|
+
* @param {Color|string} color
|
|
292
|
+
* @returns {Color} Reference to this object for method chaining
|
|
312
293
|
*/
|
|
313
294
|
copy(color) {
|
|
314
295
|
if (color instanceof Color) {
|
|
@@ -322,10 +303,10 @@ class Color {
|
|
|
322
303
|
/**
|
|
323
304
|
* Blend this color with the given one using addition.
|
|
324
305
|
* @name add
|
|
325
|
-
* @memberof
|
|
306
|
+
* @memberof Color
|
|
326
307
|
* @function
|
|
327
|
-
* @param {
|
|
328
|
-
* @returns {
|
|
308
|
+
* @param {Color} color
|
|
309
|
+
* @returns {Color} Reference to this object for method chaining
|
|
329
310
|
*/
|
|
330
311
|
add(color) {
|
|
331
312
|
this.glArray[0] = clamp(this.glArray[0] + color.glArray[0], 0, 1);
|
|
@@ -339,10 +320,10 @@ class Color {
|
|
|
339
320
|
/**
|
|
340
321
|
* Darken this color value by 0..1
|
|
341
322
|
* @name darken
|
|
342
|
-
* @memberof
|
|
323
|
+
* @memberof Color
|
|
343
324
|
* @function
|
|
344
325
|
* @param {number} scale
|
|
345
|
-
* @returns {
|
|
326
|
+
* @returns {Color} Reference to this object for method chaining
|
|
346
327
|
*/
|
|
347
328
|
darken(scale) {
|
|
348
329
|
scale = clamp(scale, 0, 1);
|
|
@@ -356,11 +337,11 @@ class Color {
|
|
|
356
337
|
/**
|
|
357
338
|
* Linearly interpolate between this color and the given one.
|
|
358
339
|
* @name lerp
|
|
359
|
-
* @memberof
|
|
340
|
+
* @memberof Color
|
|
360
341
|
* @function
|
|
361
|
-
* @param {
|
|
342
|
+
* @param {Color} color
|
|
362
343
|
* @param {number} alpha with alpha = 0 being this color, and alpha = 1 being the given one.
|
|
363
|
-
* @returns {
|
|
344
|
+
* @returns {Color} Reference to this object for method chaining
|
|
364
345
|
*/
|
|
365
346
|
lerp(color, alpha) {
|
|
366
347
|
alpha = clamp(alpha, 0, 1);
|
|
@@ -374,10 +355,10 @@ class Color {
|
|
|
374
355
|
/**
|
|
375
356
|
* Lighten this color value by 0..1
|
|
376
357
|
* @name lighten
|
|
377
|
-
* @memberof
|
|
358
|
+
* @memberof Color
|
|
378
359
|
* @function
|
|
379
360
|
* @param {number} scale
|
|
380
|
-
* @returns {
|
|
361
|
+
* @returns {Color} Reference to this object for method chaining
|
|
381
362
|
*/
|
|
382
363
|
lighten(scale) {
|
|
383
364
|
scale = clamp(scale, 0, 1);
|
|
@@ -391,11 +372,11 @@ class Color {
|
|
|
391
372
|
/**
|
|
392
373
|
* Generate random r,g,b values for this color object
|
|
393
374
|
* @name random
|
|
394
|
-
* @memberof
|
|
375
|
+
* @memberof Color
|
|
395
376
|
* @function
|
|
396
377
|
* @param {number} [min=0] minimum value for the random range
|
|
397
378
|
* @param {number} [max=255] maxmium value for the random range
|
|
398
|
-
* @returns {
|
|
379
|
+
* @returns {Color} Reference to this object for method chaining
|
|
399
380
|
*/
|
|
400
381
|
random(min = 0, max = 255) {
|
|
401
382
|
if (min < 0) {
|
|
@@ -417,9 +398,9 @@ class Color {
|
|
|
417
398
|
* Return true if the r,g,b,a values of this color are equal with the
|
|
418
399
|
* given one.
|
|
419
400
|
* @name equals
|
|
420
|
-
* @memberof
|
|
401
|
+
* @memberof Color
|
|
421
402
|
* @function
|
|
422
|
-
* @param {
|
|
403
|
+
* @param {Color} color
|
|
423
404
|
* @returns {boolean}
|
|
424
405
|
*/
|
|
425
406
|
equals(color) {
|
|
@@ -435,10 +416,10 @@ class Color {
|
|
|
435
416
|
* Parse a CSS color string and set this color to the corresponding
|
|
436
417
|
* r,g,b values
|
|
437
418
|
* @name parseCSS
|
|
438
|
-
* @memberof
|
|
419
|
+
* @memberof Color
|
|
439
420
|
* @function
|
|
440
421
|
* @param {string} cssColor
|
|
441
|
-
* @returns {
|
|
422
|
+
* @returns {Color} Reference to this object for method chaining
|
|
442
423
|
*/
|
|
443
424
|
parseCSS(cssColor) {
|
|
444
425
|
// TODO : Memoize this function by caching its input
|
|
@@ -453,10 +434,10 @@ class Color {
|
|
|
453
434
|
/**
|
|
454
435
|
* Parse an RGB or RGBA CSS color string
|
|
455
436
|
* @name parseRGB
|
|
456
|
-
* @memberof
|
|
437
|
+
* @memberof Color
|
|
457
438
|
* @function
|
|
458
439
|
* @param {string} rgbColor
|
|
459
|
-
* @returns {
|
|
440
|
+
* @returns {Color} Reference to this object for method chaining
|
|
460
441
|
*/
|
|
461
442
|
parseRGB(rgbColor) {
|
|
462
443
|
// TODO : Memoize this function by caching its input
|
|
@@ -473,11 +454,11 @@ class Color {
|
|
|
473
454
|
* Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to
|
|
474
455
|
* the corresponding r,g,b,a values
|
|
475
456
|
* @name parseHex
|
|
476
|
-
* @memberof
|
|
457
|
+
* @memberof Color
|
|
477
458
|
* @function
|
|
478
459
|
* @param {string} hexColor
|
|
479
460
|
* @param {boolean} [argb = false] true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)
|
|
480
|
-
* @returns {
|
|
461
|
+
* @returns {Color} Reference to this object for method chaining
|
|
481
462
|
*/
|
|
482
463
|
parseHex(hexColor, argb = false) {
|
|
483
464
|
// TODO : Memoize this function by caching its input
|
|
@@ -533,10 +514,10 @@ class Color {
|
|
|
533
514
|
/**
|
|
534
515
|
* Pack this color into a Uint32 ARGB representation
|
|
535
516
|
* @name toUint32
|
|
536
|
-
* @memberof
|
|
517
|
+
* @memberof Color
|
|
537
518
|
* @function
|
|
538
519
|
* @param {number} [alpha=1.0] alpha value [0.0 .. 1.0]
|
|
539
|
-
* @returns {
|
|
520
|
+
* @returns {number}
|
|
540
521
|
*/
|
|
541
522
|
toUint32(alpha = this.alpha) {
|
|
542
523
|
var ur = this.r & 0xff;
|
|
@@ -550,7 +531,7 @@ class Color {
|
|
|
550
531
|
/**
|
|
551
532
|
* return an array representation of this object
|
|
552
533
|
* @name toArray
|
|
553
|
-
* @memberof
|
|
534
|
+
* @memberof Color
|
|
554
535
|
* @function
|
|
555
536
|
* @returns {Float32Array}
|
|
556
537
|
*/
|
|
@@ -562,7 +543,7 @@ class Color {
|
|
|
562
543
|
/**
|
|
563
544
|
* Get the color in "#RRGGBB" format
|
|
564
545
|
* @name toHex
|
|
565
|
-
* @memberof
|
|
546
|
+
* @memberof Color
|
|
566
547
|
* @function
|
|
567
548
|
* @returns {string}
|
|
568
549
|
*/
|
|
@@ -576,7 +557,7 @@ class Color {
|
|
|
576
557
|
/**
|
|
577
558
|
* Get the color in "#RRGGBBAA" format
|
|
578
559
|
* @name toHex8
|
|
579
|
-
* @memberof
|
|
560
|
+
* @memberof Color
|
|
580
561
|
* @function
|
|
581
562
|
* @returns {string}
|
|
582
563
|
*/
|
|
@@ -590,7 +571,7 @@ class Color {
|
|
|
590
571
|
/**
|
|
591
572
|
* Get the color in "rgb(R,G,B)" format
|
|
592
573
|
* @name toRGB
|
|
593
|
-
* @memberof
|
|
574
|
+
* @memberof Color
|
|
594
575
|
* @function
|
|
595
576
|
* @returns {string}
|
|
596
577
|
*/
|
|
@@ -608,7 +589,7 @@ class Color {
|
|
|
608
589
|
/**
|
|
609
590
|
* Get the color in "rgba(R,G,B,A)" format
|
|
610
591
|
* @name toRGBA
|
|
611
|
-
* @memberof
|
|
592
|
+
* @memberof Color
|
|
612
593
|
* @function
|
|
613
594
|
* @returns {string}
|
|
614
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|
-
* @memberof
|
|
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
|