littlejsengine 1.18.15 → 1.18.17
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 +4 -4
- package/dist/littlejs.d.ts +198 -17
- package/dist/littlejs.esm.js +1180 -257
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1160 -257
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +1134 -241
- package/package.json +1 -1
- package/plugins/box2d.js +9 -13
- package/plugins/drawUtilities.js +63 -0
- package/plugins/lightSystem.js +330 -0
- package/plugins/medalSystem.js +36 -5
- package/plugins/pluginExport.js +8 -0
- package/src/engine.js +1 -1
- package/src/engineAudio.js +21 -3
- package/src/engineBuild.mjs +1 -0
- package/src/engineDebug.js +27 -16
- package/src/engineDraw.js +9 -6
- package/src/engineExport.js +12 -0
- package/src/engineInput.js +528 -189
- package/src/engineObject.js +5 -2
- package/src/engineParticles.js +19 -15
- package/src/engineRelease.js +1 -0
- package/src/engineSettings.js +111 -10
- package/src/engineTileLayer.js +5 -0
package/src/engineDebug.js
CHANGED
|
@@ -44,7 +44,7 @@ let debugKey = 'Escape';
|
|
|
44
44
|
let debugOverlay = false;
|
|
45
45
|
|
|
46
46
|
// Engine internal variables not exposed to documentation
|
|
47
|
-
let debugPrimitives = [], debugPhysics = false, debugRaycast = false, debugParticles = false, debugGamepads = false, debugTakeScreenshot;
|
|
47
|
+
let debugPrimitives = [], debugPhysics = false, debugRaycast = false, debugParticles = false, debugGamepads = false, debugSound = false, debugTakeScreenshot;
|
|
48
48
|
|
|
49
49
|
///////////////////////////////////////////////////////////////////////////////
|
|
50
50
|
// Debug helper functions
|
|
@@ -284,6 +284,8 @@ function debugUpdate()
|
|
|
284
284
|
debugRaycast = !debugRaycast;
|
|
285
285
|
if (keyWasPressed('Digit5'))
|
|
286
286
|
debugScreenshot();
|
|
287
|
+
if (keyWasPressed('Digit7'))
|
|
288
|
+
debugSound = !debugSound;
|
|
287
289
|
}
|
|
288
290
|
if (debugVideoCaptureIsActive())
|
|
289
291
|
{
|
|
@@ -303,6 +305,9 @@ function debugRender()
|
|
|
303
305
|
// flush any gl sprites before drawing debug info
|
|
304
306
|
glFlush();
|
|
305
307
|
|
|
308
|
+
const savedDrawCount = drawCount;
|
|
309
|
+
const savedPrimitiveCount = primitiveCount;
|
|
310
|
+
|
|
306
311
|
if (debugTakeScreenshot)
|
|
307
312
|
{
|
|
308
313
|
// combine canvases, remove alpha and save
|
|
@@ -336,6 +341,8 @@ function debugRender()
|
|
|
336
341
|
const stickCount = gamepadStickData[i].length;
|
|
337
342
|
for (let j = 0; j < stickCount; j++)
|
|
338
343
|
{
|
|
344
|
+
if (!(j in gamepadStickData[i]))
|
|
345
|
+
continue; // skip sticks that are not present (eg a disabled touch left stick)
|
|
339
346
|
const stick = gamepadStick(j, i);
|
|
340
347
|
const drawPos = cornerPos.add(vec2(j*stickScale*2, 0));
|
|
341
348
|
const stickPos = drawPos.add(stick.scale(stickScale));
|
|
@@ -514,6 +521,8 @@ function debugRender()
|
|
|
514
521
|
debugContext.fillStyle = '#fff';
|
|
515
522
|
debugContext.fillText('5: Save Screenshot', x, y += h);
|
|
516
523
|
debugContext.fillText('6: Toggle Video Capture', x, y += h);
|
|
524
|
+
debugContext.fillStyle = debugSound ? '#f00' : '#fff';
|
|
525
|
+
debugContext.fillText('7: Debug Sound', x, y += h);
|
|
517
526
|
|
|
518
527
|
let keysPressed = '';
|
|
519
528
|
let mousePressed = '';
|
|
@@ -548,10 +557,27 @@ function debugRender()
|
|
|
548
557
|
debugContext.fillText(debugParticles ? 'Debug Particles' : '', x, y += h);
|
|
549
558
|
debugContext.fillText(debugRaycast ? 'Debug Raycasts' : '', x, y += h);
|
|
550
559
|
debugContext.fillText(debugGamepads ? 'Debug Gamepads' : '', x, y += h);
|
|
560
|
+
debugContext.fillText(debugSound ? 'Debug Sound' : '', x, y += h);
|
|
551
561
|
}
|
|
552
562
|
|
|
553
563
|
debugContext.restore();
|
|
554
564
|
}
|
|
565
|
+
|
|
566
|
+
if (debugWatermark || debugOverlay)
|
|
567
|
+
{
|
|
568
|
+
// show fps stats display
|
|
569
|
+
mainContext.textAlign = 'right';
|
|
570
|
+
mainContext.textBaseline = 'top';
|
|
571
|
+
mainContext.font = '1em monospace';
|
|
572
|
+
mainContext.fillStyle = '#000';
|
|
573
|
+
const text = engineName + ' v' + engineVersion + ' / '
|
|
574
|
+
+ savedDrawCount + ' / ' + savedPrimitiveCount + ' / '
|
|
575
|
+
+ engineObjects.length + ' / ' + averageFPS.toFixed(1)
|
|
576
|
+
+ (glEnable ? ' GL' : ' 2D') ;
|
|
577
|
+
mainContext.fillText(text, mainCanvas.width-3, 3);
|
|
578
|
+
mainContext.fillStyle = '#fff';
|
|
579
|
+
mainContext.fillText(text, mainCanvas.width-2, 2);
|
|
580
|
+
}
|
|
555
581
|
}
|
|
556
582
|
|
|
557
583
|
function debugRenderPost()
|
|
@@ -561,21 +587,6 @@ function debugRenderPost()
|
|
|
561
587
|
debugVideoCaptureUpdate();
|
|
562
588
|
return;
|
|
563
589
|
}
|
|
564
|
-
|
|
565
|
-
if (!debugWatermark && !debugOverlay) return;
|
|
566
|
-
|
|
567
|
-
// update fps display
|
|
568
|
-
mainContext.textAlign = 'right';
|
|
569
|
-
mainContext.textBaseline = 'top';
|
|
570
|
-
mainContext.font = '1em monospace';
|
|
571
|
-
mainContext.fillStyle = '#000';
|
|
572
|
-
const text = engineName + ' v' + engineVersion + ' / '
|
|
573
|
-
+ drawCount + ' / ' + primitiveCount + ' / '
|
|
574
|
-
+ engineObjects.length + ' / ' + averageFPS.toFixed(1)
|
|
575
|
-
+ (glEnable ? ' GL' : ' 2D') ;
|
|
576
|
-
mainContext.fillText(text, mainCanvas.width-3, 3);
|
|
577
|
-
mainContext.fillStyle = '#fff';
|
|
578
|
-
mainContext.fillText(text, mainCanvas.width-2, 2);
|
|
579
590
|
}
|
|
580
591
|
|
|
581
592
|
///////////////////////////////////////////////////////////////////////////////
|
package/src/engineDraw.js
CHANGED
|
@@ -329,11 +329,12 @@ function drawTile(pos, size=vec2(1), tileInfo, color=WHITE,
|
|
|
329
329
|
// normal canvas 2D rendering method (slower)
|
|
330
330
|
++drawCount;
|
|
331
331
|
++primitiveCount;
|
|
332
|
-
size = new Vector2(size.x, -size.y); // flip upside down sprites
|
|
333
332
|
drawCanvas2D(pos, size, angle, mirror, (context)=>
|
|
334
333
|
{
|
|
335
334
|
if (textureInfo)
|
|
336
335
|
{
|
|
336
|
+
// un-flip Y so the image renders right-side up under drawCanvas2D's Y flip
|
|
337
|
+
context.scale(1, -1);
|
|
337
338
|
// calculate uvs and render
|
|
338
339
|
const x = tileInfo.pos.x, y = tileInfo.pos.y;
|
|
339
340
|
const w = tileInfo.size.x, h = tileInfo.size.y;
|
|
@@ -341,7 +342,7 @@ function drawTile(pos, size=vec2(1), tileInfo, color=WHITE,
|
|
|
341
342
|
}
|
|
342
343
|
else
|
|
343
344
|
{
|
|
344
|
-
// if no tile info, use untextured rect
|
|
345
|
+
// if no tile info, use untextured rect (Y-symmetric, no compensation needed)
|
|
345
346
|
const c = additiveColor ? color.add(additiveColor) : color;
|
|
346
347
|
context.fillStyle = c.toString();
|
|
347
348
|
context.fillRect(-.5, -.5, 1, 1);
|
|
@@ -415,11 +416,10 @@ function drawRectGradient(pos, size, colorTop=WHITE, colorBottom=CLEAR_WHITE, an
|
|
|
415
416
|
// normal canvas 2D rendering method (slower)
|
|
416
417
|
++drawCount;
|
|
417
418
|
++primitiveCount;
|
|
418
|
-
size = new Vector2(size.x, -size.y); // fix upside down sprites
|
|
419
419
|
drawCanvas2D(pos, size, angle, false, (context)=>
|
|
420
420
|
{
|
|
421
|
-
//
|
|
422
|
-
const gradient = context.createLinearGradient(0,
|
|
421
|
+
// gradient endpoints are flipped to match the Y flip inside drawCanvas2D
|
|
422
|
+
const gradient = context.createLinearGradient(0, .5, 0, -.5);
|
|
423
423
|
gradient.addColorStop(0, colorTop.toString());
|
|
424
424
|
gradient.addColorStop(1, colorBottom.toString());
|
|
425
425
|
context.fillStyle = gradient;
|
|
@@ -838,7 +838,10 @@ function drawCircleGradient(pos, size=1, colorInner=WHITE, colorOuter=CLEAR_WHIT
|
|
|
838
838
|
* @memberof Draw
|
|
839
839
|
*/
|
|
840
840
|
|
|
841
|
-
/** Draw directly to a 2d canvas context in world space
|
|
841
|
+
/** Draw directly to a 2d canvas context in world space.
|
|
842
|
+
* The Y axis is flipped so world-Y-up coordinates render right-side up
|
|
843
|
+
* (matches the WebGL path). Callers whose drawing depends on Y direction
|
|
844
|
+
* (e.g. linear gradients) should flip their own Y endpoints accordingly.
|
|
842
845
|
* @param {Vector2} pos
|
|
843
846
|
* @param {Vector2} size
|
|
844
847
|
* @param {number} angle
|
package/src/engineExport.js
CHANGED
|
@@ -85,12 +85,18 @@ export
|
|
|
85
85
|
inputWASDEmulateDirection,
|
|
86
86
|
touchInputEnable,
|
|
87
87
|
touchGamepadEnable,
|
|
88
|
+
touchGamepadPassthrough,
|
|
88
89
|
touchGamepadCenterButtonSize,
|
|
89
90
|
touchGamepadButtonCount,
|
|
91
|
+
touchGamepadLeftStick,
|
|
92
|
+
touchGamepadLeftButtonCount,
|
|
93
|
+
touchGamepadRightStick,
|
|
90
94
|
touchGamepadAnalog,
|
|
95
|
+
touchGamepadFloating,
|
|
91
96
|
touchGamepadSize,
|
|
92
97
|
touchGamepadAlpha,
|
|
93
98
|
touchGamepadDisplayTime,
|
|
99
|
+
touchGamepadVibration,
|
|
94
100
|
vibrateEnable,
|
|
95
101
|
soundEnable,
|
|
96
102
|
soundVolume,
|
|
@@ -133,12 +139,18 @@ export
|
|
|
133
139
|
setGamepadDirectionEmulateStick,
|
|
134
140
|
setInputWASDEmulateDirection,
|
|
135
141
|
setTouchGamepadEnable,
|
|
142
|
+
setTouchGamepadPassthrough,
|
|
136
143
|
setTouchGamepadCenterButtonSize,
|
|
137
144
|
setTouchGamepadButtonCount,
|
|
145
|
+
setTouchGamepadLeftStick,
|
|
146
|
+
setTouchGamepadLeftButtonCount,
|
|
147
|
+
setTouchGamepadRightStick,
|
|
138
148
|
setTouchGamepadAnalog,
|
|
149
|
+
setTouchGamepadFloating,
|
|
139
150
|
setTouchGamepadSize,
|
|
140
151
|
setTouchGamepadAlpha,
|
|
141
152
|
setTouchGamepadDisplayTime,
|
|
153
|
+
setTouchGamepadVibration,
|
|
142
154
|
setVibrateEnable,
|
|
143
155
|
setSoundEnable,
|
|
144
156
|
setSoundVolume,
|