littlejsengine 1.24.2 → 1.25.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/EDITOR.md +2 -2
  3. package/FAQ.md +6 -0
  4. package/REFERENCE.md +86 -41
  5. package/dist/littlejs.d.ts +600 -323
  6. package/dist/littlejs.esm.js +2412 -1797
  7. package/dist/littlejs.esm.min.js +38 -24
  8. package/dist/littlejs.js +2410 -1797
  9. package/dist/littlejs.min.js +37 -23
  10. package/dist/littlejs.release.js +2393 -1826
  11. package/package.json +1 -1
  12. package/plugins/box2d.js +41 -28
  13. package/plugins/drawUtilities.js +374 -380
  14. package/plugins/gltf.js +331 -55
  15. package/plugins/lightSystem.js +2 -2
  16. package/plugins/math3d.js +1013 -1014
  17. package/plugins/newgrounds.js +1 -4
  18. package/plugins/particleEffects.js +3 -4
  19. package/plugins/pathFinder.js +52 -28
  20. package/plugins/pluginExport.js +2 -0
  21. package/plugins/postProcess.js +196 -65
  22. package/plugins/render3d.js +8 -6
  23. package/plugins/render3dEditor.js +3 -3
  24. package/plugins/render3dExtras.js +31 -10
  25. package/plugins/render3dLevel.js +15 -4
  26. package/plugins/textureSheet.js +15 -7
  27. package/plugins/tweenSystem.js +43 -38
  28. package/plugins/uiSystem.js +25 -20
  29. package/src/engine.js +39 -21
  30. package/src/engineAudio.js +13 -9
  31. package/src/engineBuild.mjs +49 -2
  32. package/src/engineDebug.js +3 -2
  33. package/src/engineDraw.js +20 -18
  34. package/src/engineEditor.js +75 -23
  35. package/src/engineInput.js +10 -10
  36. package/src/engineMath.js +3 -6
  37. package/src/engineObject.js +8 -9
  38. package/src/engineParticles.js +8 -7
  39. package/src/engineRelease.js +17 -10
  40. package/src/engineTileLayer.js +33 -14
  41. package/src/engineUtilities.js +15 -2
  42. package/src/engineWebGL.js +34 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.24.2",
3
+ "version": "1.25.0",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
package/plugins/box2d.js CHANGED
@@ -303,7 +303,8 @@ class Box2dObject extends EngineObject
303
303
  * @param {number} [density]
304
304
  * @param {number} [friction]
305
305
  * @param {number} [restitution]
306
- * @param {boolean} [isSensor] */
306
+ * @param {boolean} [isSensor]
307
+ * @return {Object} - The fixture made, Box2D's own */
307
308
  addShape(shape, density=1, friction=.2, restitution=0, isSensor=false)
308
309
  {
309
310
  ASSERT(isNumber(density), 'density must be a number');
@@ -332,7 +333,8 @@ class Box2dObject extends EngineObject
332
333
  * @param {number} [density]
333
334
  * @param {number} [friction]
334
335
  * @param {number} [restitution]
335
- * @param {boolean} [isSensor] */
336
+ * @param {boolean} [isSensor]
337
+ * @return {Object|undefined} - The fixture made, Box2D's own, undefined for a shape too small to make */
336
338
  addBox(size=vec2(1), offset=vec2(), angle=0, density, friction, restitution, isSensor)
337
339
  {
338
340
  ASSERT(isVector2(size), 'size must be a Vector2');
@@ -357,7 +359,8 @@ class Box2dObject extends EngineObject
357
359
  * @param {number} [density]
358
360
  * @param {number} [friction]
359
361
  * @param {number} [restitution]
360
- * @param {boolean} [isSensor] */
362
+ * @param {boolean} [isSensor]
363
+ * @return {Object|undefined} - The fixture made, Box2D's own, undefined for a shape too small to make */
361
364
  addPoly(points, density, friction, restitution, isSensor)
362
365
  {
363
366
  ASSERT(isArray(points), 'points must be an array');
@@ -404,7 +407,8 @@ class Box2dObject extends EngineObject
404
407
  * @param {number} [density]
405
408
  * @param {number} [friction]
406
409
  * @param {number} [restitution]
407
- * @param {boolean} [isSensor] */
410
+ * @param {boolean} [isSensor]
411
+ * @return {Object|undefined} - The fixture made, Box2D's own, undefined for a shape too small to make */
408
412
  addRegularPoly(diameter=1, sides=8, density, friction, restitution, isSensor)
409
413
  {
410
414
  ASSERT(isNumber(diameter) && diameter>0, 'diameter must be a positive number');
@@ -424,7 +428,8 @@ class Box2dObject extends EngineObject
424
428
  * @param {number} [density]
425
429
  * @param {number} [friction]
426
430
  * @param {number} [restitution]
427
- * @param {boolean} [isSensor] */
431
+ * @param {boolean} [isSensor]
432
+ * @return {Object|undefined} - The fixture made, Box2D's own, undefined for a shape too small to make */
428
433
  addRandomPoly(diameter=1, density, friction, restitution, isSensor)
429
434
  {
430
435
  ASSERT(isNumber(diameter) && diameter>0, 'diameter must be a positive number');
@@ -443,7 +448,8 @@ class Box2dObject extends EngineObject
443
448
  * @param {number} [density]
444
449
  * @param {number} [friction]
445
450
  * @param {number} [restitution]
446
- * @param {boolean} [isSensor] */
451
+ * @param {boolean} [isSensor]
452
+ * @return {Object} - The fixture made, Box2D's own */
447
453
  addCircle(diameter=1, offset=vec2(), density, friction, restitution, isSensor)
448
454
  {
449
455
  ASSERT(isNumber(diameter) && diameter>0, 'diameter must be a positive number');
@@ -463,7 +469,8 @@ class Box2dObject extends EngineObject
463
469
  * @param {number} [density]
464
470
  * @param {number} [friction]
465
471
  * @param {number} [restitution]
466
- * @param {boolean} [isSensor] */
472
+ * @param {boolean} [isSensor]
473
+ * @return {Object} - The fixture made, Box2D's own */
467
474
  addEdge(point1, point2, density, friction, restitution, isSensor)
468
475
  {
469
476
  ASSERT(isVector2(point1), 'point1 must be a Vector2');
@@ -481,7 +488,8 @@ class Box2dObject extends EngineObject
481
488
  * @param {number} [density]
482
489
  * @param {number} [friction]
483
490
  * @param {number} [restitution]
484
- * @param {boolean} [isSensor] */
491
+ * @param {boolean} [isSensor]
492
+ * @return {Array<Object>} - The fixtures made, Box2D's own */
485
493
  addEdgeList(points, density, friction, restitution, isSensor)
486
494
  {
487
495
  ASSERT(isArray(points), 'points must be an array');
@@ -514,7 +522,8 @@ class Box2dObject extends EngineObject
514
522
  * @param {number} [density]
515
523
  * @param {number} [friction]
516
524
  * @param {number} [restitution]
517
- * @param {boolean} [isSensor] */
525
+ * @param {boolean} [isSensor]
526
+ * @return {Array<Object>} - The fixtures made, Box2D's own */
518
527
  addEdgeLoop(points, density, friction, restitution, isSensor)
519
528
  {
520
529
  ASSERT(isArray(points), 'points must be an array');
@@ -627,7 +636,7 @@ class Box2dObject extends EngineObject
627
636
  * @param {number} angle */
628
637
  setTransform(pos, angle)
629
638
  {
630
- this.pos = pos.copy();
639
+ this.pos.set(pos.x, pos.y); // its own pos kept, as an EngineObject's is
631
640
  this.angle = angle;
632
641
  // box2d uses reverse angle
633
642
  const x = pos.x, y = pos.y;
@@ -643,7 +652,7 @@ class Box2dObject extends EngineObject
643
652
  * @param {Vector2} pos */
644
653
  setPosition(pos)
645
654
  {
646
- this.pos = pos.copy();
655
+ this.pos.set(pos.x, pos.y); // its own pos kept, as an EngineObject's is
647
656
  const x = pos.x, y = pos.y;
648
657
  box2dWhenUnlocked(()=>
649
658
  {
@@ -1432,6 +1441,8 @@ class Box2dRevoluteJoint extends Box2dJoint
1432
1441
  * Box2D Pin Joint
1433
1442
  * - Pins two objects together at a point, where they still turn freely, like a nail through two boards
1434
1443
  * - A revolute joint at that point, so it holds exactly and its limits and motor work too
1444
+ * - new Box2dPinJoint(objectA, objectB, pos, collide): the point defaults to objectA's position, where a revolute
1445
+ * joint's anchor defaults to objectB's
1435
1446
  * @extends Box2dRevoluteJoint
1436
1447
  * @memberof Box2D
1437
1448
  */
@@ -1787,14 +1798,6 @@ class Box2dWeldJoint extends Box2dJoint
1787
1798
  /** Get the damping ratio
1788
1799
  * @return {number} */
1789
1800
  getDampingRatio() { return this.box2dJoint.GetDampingRatio(); }
1790
-
1791
- /** @deprecated since 1.20, use setDampingRatio
1792
- * @param {number} ratio */
1793
- setSpringDampingRatio(ratio) { this.setDampingRatio(ratio); }
1794
-
1795
- /** @deprecated since 1.20, use getDampingRatio
1796
- * @return {number} */
1797
- getSpringDampingRatio() { return this.getDampingRatio(); }
1798
1801
  }
1799
1802
 
1800
1803
  ///////////////////////////////////////////////////////////////////////////////
@@ -2144,7 +2147,8 @@ class Box2dPlugin
2144
2147
  return box2d.raycastAll(start, end, includeSensors)[0];
2145
2148
  }
2146
2149
 
2147
- /** box aabb cast and return all the objects
2150
+ /** Every object whose shapes' bounding boxes overlap a box, not the shapes themselves, so near the corner of a
2151
+ * turned box or a circle it finds one the box does not touch; use pointCast or a raycast for exact
2148
2152
  * @param {Vector2} pos
2149
2153
  * @param {Vector2} size
2150
2154
  * @param {boolean} [includeSensors] - Also find sensors, trigger zones are passed through by default
@@ -2174,7 +2178,8 @@ class Box2dPlugin
2174
2178
  return queryObjects;
2175
2179
  }
2176
2180
 
2177
- /** box aabb cast and return the first object
2181
+ /** The first object whose shapes' bounding boxes overlap a box, not the shapes themselves, so near the corner of
2182
+ * a turned box or a circle it finds one the box does not touch; use pointCast or a raycast for exact
2178
2183
  * @param {Vector2} pos
2179
2184
  * @param {Vector2} size
2180
2185
  * @param {boolean} [includeSensors] - Also find sensors, trigger zones are passed through by default
@@ -2320,7 +2325,8 @@ class Box2dPlugin
2320
2325
  // helper functions
2321
2326
 
2322
2327
  /** converts a box2d vec2 to a Vector2
2323
- * @param {Object} v */
2328
+ * @param {Object} v
2329
+ * @return {Vector2} */
2324
2330
  vec2From(v)
2325
2331
  {
2326
2332
  ASSERT(v instanceof box2d.instance.b2Vec2);
@@ -2328,7 +2334,8 @@ class Box2dPlugin
2328
2334
  }
2329
2335
 
2330
2336
  /** converts a box2d vec2 pointer to a Vector2
2331
- * @param {Object} vp */
2337
+ * @param {Object} vp
2338
+ * @return {Vector2} */
2332
2339
  vec2FromPointer(vp)
2333
2340
  {
2334
2341
  const v = box2d.instance.wrapPointer(vp, box2d.instance.b2Vec2);
@@ -2337,7 +2344,8 @@ class Box2dPlugin
2337
2344
 
2338
2345
  /** converts a Vector2 to a new box2d vec2, which stays until destroyed with box2d.instance.destroy;
2339
2346
  * the plugin itself passes Box2D reused ones, since Box2D copies every vector it is given
2340
- * @param {Vector2} v */
2347
+ * @param {Vector2} v
2348
+ * @return {Object} - A Box2D vector, its b2Vec2 */
2341
2349
  vec2dTo(v)
2342
2350
  {
2343
2351
  ASSERT(isVector2(v));
@@ -2345,11 +2353,13 @@ class Box2dPlugin
2345
2353
  }
2346
2354
 
2347
2355
  /** checks if a box2d object is null
2348
- * @param {Object} o */
2356
+ * @param {Object} o
2357
+ * @return {boolean} */
2349
2358
  isNull(o) { return !box2d.instance.getPointer(o); }
2350
2359
 
2351
2360
  /** casts a box2d object to a shape type
2352
- * @param {Object} o */
2361
+ * @param {Object} o
2362
+ * @return {Object} - The shape as its own Box2D type */
2353
2363
  castShapeObject(o)
2354
2364
  {
2355
2365
  switch (o.GetType())
@@ -2368,7 +2378,8 @@ class Box2dPlugin
2368
2378
  }
2369
2379
 
2370
2380
  /** casts a box2d object to a joint type
2371
- * @param {Object} o */
2381
+ * @param {Object} o
2382
+ * @return {Object} - The joint as its own Box2D type */
2372
2383
  castJointObject(o)
2373
2384
  {
2374
2385
  switch (o.GetType())
@@ -2434,8 +2445,10 @@ async function box2dInit()
2434
2445
  {
2435
2446
  if (o.body)
2436
2447
  {
2448
+ // moved in place, as the engine moves an EngineObject's pos, so what holds it follows the body;
2437
2449
  // box2d uses reverse angle
2438
- o.pos = box2d.vec2From(o.body.GetPosition());
2450
+ const p = o.body.GetPosition();
2451
+ o.pos.set(p.get_x(), p.get_y());
2439
2452
  o.angle = -o.body.GetAngle();
2440
2453
  }
2441
2454
  }