littlejsengine 1.18.1 → 1.18.2
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/.claude/settings.local.json +7 -0
- package/.github/workflows/test.yml +17 -0
- package/AI.md +10 -0
- package/README.md +2 -2
- package/dist/littlejs.d.ts +36 -7
- package/dist/littlejs.esm.js +36 -15
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +32 -13
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +32 -13
- package/examples/shorts/base.html +1 -1
- package/examples/starter/index.html +2 -2
- package/package.json +3 -2
- package/src/engine.js +1 -1
- package/src/engineExport.js +4 -2
- package/src/engineInput.js +17 -4
- package/src/engineObject.js +1 -0
- package/src/engineSettings.js +13 -8
- package/test/math.test.mjs +774 -0
- package/test/setup.mjs +22 -0
- package/test/smoke.test.mjs +258 -0
- package/test/util.test.mjs +80 -0
package/dist/littlejs.release.js
CHANGED
|
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
|
|
|
35
35
|
* @type {string}
|
|
36
36
|
* @default
|
|
37
37
|
* @memberof Engine */
|
|
38
|
-
const engineVersion = '1.18.
|
|
38
|
+
const engineVersion = '1.18.2';
|
|
39
39
|
|
|
40
40
|
/** Frames per second to update
|
|
41
41
|
* @type {number}
|
|
@@ -2323,18 +2323,22 @@ let touchInputEnable = true;
|
|
|
2323
2323
|
|
|
2324
2324
|
/** True if touch gamepad should appear on mobile devices
|
|
2325
2325
|
* - Supports left analog stick, 4 face buttons and start button (button 9)
|
|
2326
|
+
* - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
|
|
2327
|
+
* - Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
|
|
2328
|
+
|
|
2326
2329
|
* @type {boolean}
|
|
2327
2330
|
* @default
|
|
2328
2331
|
* @memberof Settings */
|
|
2329
2332
|
let touchGamepadEnable = false;
|
|
2330
2333
|
|
|
2331
2334
|
/** True if touch gamepad should have start button in the center
|
|
2335
|
+
* - Prevents activating if overlappng with virtual stick or buttons if they are enabled
|
|
2332
2336
|
* - When the game is paused, any touch will press the button
|
|
2333
|
-
* -
|
|
2334
|
-
* @type {
|
|
2337
|
+
* - Set size to enable the center button
|
|
2338
|
+
* @type {number}
|
|
2335
2339
|
* @default
|
|
2336
2340
|
* @memberof Settings */
|
|
2337
|
-
let
|
|
2341
|
+
let touchGamepadCenterButtonSize = 300;
|
|
2338
2342
|
|
|
2339
2343
|
/** Number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
|
|
2340
2344
|
* @type {number}
|
|
@@ -2352,7 +2356,7 @@ let touchGamepadAnalog = true;
|
|
|
2352
2356
|
* @type {number}
|
|
2353
2357
|
* @default
|
|
2354
2358
|
* @memberof Settings */
|
|
2355
|
-
let touchGamepadSize =
|
|
2359
|
+
let touchGamepadSize = 100;
|
|
2356
2360
|
|
|
2357
2361
|
/** Transparency of touch gamepad overlay
|
|
2358
2362
|
* @type {number}
|
|
@@ -2620,11 +2624,12 @@ function setTouchInputEnable(enable) { touchInputEnable = enable; }
|
|
|
2620
2624
|
* @memberof Settings */
|
|
2621
2625
|
function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
|
|
2622
2626
|
|
|
2623
|
-
/**
|
|
2624
|
-
* -
|
|
2625
|
-
*
|
|
2627
|
+
/** Set if touch gamepad should have start button in the center
|
|
2628
|
+
* - Set size to enable the center button
|
|
2629
|
+
* - When the game is paused, any touch will press the button
|
|
2630
|
+
* @param {number} size
|
|
2626
2631
|
* @memberof Settings */
|
|
2627
|
-
function
|
|
2632
|
+
function setTouchGamepadCenterButtonSize(size) { touchGamepadCenterButtonSize = size; }
|
|
2628
2633
|
|
|
2629
2634
|
/** Set number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
|
|
2630
2635
|
* @param {number} count
|
|
@@ -3162,6 +3167,7 @@ class EngineObject
|
|
|
3162
3167
|
child.parent = this;
|
|
3163
3168
|
child.localPos = localPos.copy();
|
|
3164
3169
|
child.localAngle = localAngle;
|
|
3170
|
+
child.updateTransforms();
|
|
3165
3171
|
return child;
|
|
3166
3172
|
}
|
|
3167
3173
|
|
|
@@ -4893,7 +4899,7 @@ function inputInit()
|
|
|
4893
4899
|
if (touching)
|
|
4894
4900
|
{
|
|
4895
4901
|
touchGamepadTimer.set();
|
|
4896
|
-
if (
|
|
4902
|
+
if (touchGamepadCenterButtonSize && !wasTouching && paused)
|
|
4897
4903
|
{
|
|
4898
4904
|
// touch anywhere to press start when paused
|
|
4899
4905
|
touchGamepadButtons[9] = 1;
|
|
@@ -4918,6 +4924,7 @@ function inputInit()
|
|
|
4918
4924
|
// virtual analog stick
|
|
4919
4925
|
const delta = touchPos.subtract(stickCenter);
|
|
4920
4926
|
touchGamepadSticks[0] = delta.scale(2/touchGamepadSize).clampLength();
|
|
4927
|
+
touchGamepadButtons[10] = 1; // also press a button when touching stick
|
|
4921
4928
|
}
|
|
4922
4929
|
else if (buttonCenter.distance(touchPos) < touchGamepadSize)
|
|
4923
4930
|
{
|
|
@@ -4926,6 +4933,7 @@ function inputInit()
|
|
|
4926
4933
|
// virtual right analog stick
|
|
4927
4934
|
const delta = touchPos.subtract(buttonCenter);
|
|
4928
4935
|
touchGamepadSticks[1] = delta.scale(2/touchGamepadSize).clampLength();
|
|
4936
|
+
touchGamepadButtons[11] = 1; // also press a button when touching right stick
|
|
4929
4937
|
}
|
|
4930
4938
|
// virtual face buttons
|
|
4931
4939
|
let button = buttonCenter.subtract(touchPos).direction();
|
|
@@ -4942,8 +4950,7 @@ function inputInit()
|
|
|
4942
4950
|
if (button < touchGamepadButtonCount)
|
|
4943
4951
|
touchGamepadButtons[button] = 1;
|
|
4944
4952
|
}
|
|
4945
|
-
else if (
|
|
4946
|
-
startCenter.distance(touchPos) < touchGamepadSize)
|
|
4953
|
+
else if (startCenter.distance(touchPos) < touchGamepadCenterButtonSize)
|
|
4947
4954
|
{
|
|
4948
4955
|
// virtual start button in center
|
|
4949
4956
|
touchGamepadButtons[9] = 1;
|
|
@@ -4992,6 +4999,18 @@ function inputUpdate()
|
|
|
4992
4999
|
// update touch gamepad if enabled
|
|
4993
5000
|
if (touchGamepadEnable && isTouchDevice)
|
|
4994
5001
|
{
|
|
5002
|
+
if (debugGamepads)
|
|
5003
|
+
{
|
|
5004
|
+
const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
|
|
5005
|
+
const buttonCenter = touchGamepadButtonCenter();
|
|
5006
|
+
const startCenter = mainCanvasSize.scale(.5);
|
|
5007
|
+
|
|
5008
|
+
debugCircle(stickCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
|
|
5009
|
+
debugCircle(buttonCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
|
|
5010
|
+
if (touchGamepadCenterButtonSize)
|
|
5011
|
+
debugCircle(startCenter, 2*touchGamepadCenterButtonSize, 'cyan', 0, false, true);
|
|
5012
|
+
}
|
|
5013
|
+
|
|
4995
5014
|
if (!touchGamepadTimer.isSet()) return;
|
|
4996
5015
|
|
|
4997
5016
|
// read virtual analog stick
|
|
@@ -5019,7 +5038,7 @@ function inputUpdate()
|
|
|
5019
5038
|
|
|
5020
5039
|
// read virtual gamepad buttons
|
|
5021
5040
|
const data = inputData[1] ?? (inputData[1] = []);
|
|
5022
|
-
for (let i=
|
|
5041
|
+
for (let i=12; i--;)
|
|
5023
5042
|
{
|
|
5024
5043
|
const wasDown = gamepadIsDown(i,0);
|
|
5025
5044
|
data[i] = touchGamepadButtons[i] ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1.18.
|
|
10
|
+
<script src=../../dist/littlejs.js?1.18.2></script>
|
|
11
11
|
|
|
12
12
|
<!-- LittleJS Engine Source
|
|
13
13
|
<script src=../../src/engine.js></script>
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
-->
|
|
33
33
|
|
|
34
34
|
<!-- Add your game scripts here -->
|
|
35
|
-
<script src=game.js?1.18.
|
|
35
|
+
<script src=game.js?1.18.2></script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "littlejsengine",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.2",
|
|
4
4
|
"description": "LittleJS - Tiny and Fast HTML5 Game Engine",
|
|
5
5
|
"main": "dist/littlejs.esm.js",
|
|
6
6
|
"types": "dist/littlejs.d.ts",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/KilledByAPixel/LittleJS",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "node src/engineBuild.mjs"
|
|
33
|
+
"build": "node src/engineBuild.mjs",
|
|
34
|
+
"test": "node --test --import ./test/setup.mjs \"test/**/*.test.mjs\""
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"bestzip": "^2.2.1",
|
package/src/engine.js
CHANGED
package/src/engineExport.js
CHANGED
|
@@ -80,7 +80,7 @@ export
|
|
|
80
80
|
gamepadDirectionEmulateStick,
|
|
81
81
|
inputWASDEmulateDirection,
|
|
82
82
|
touchGamepadEnable,
|
|
83
|
-
|
|
83
|
+
touchGamepadCenterButtonSize,
|
|
84
84
|
touchGamepadAnalog,
|
|
85
85
|
touchGamepadSize,
|
|
86
86
|
touchGamepadAlpha,
|
|
@@ -128,7 +128,7 @@ export
|
|
|
128
128
|
setGamepadDirectionEmulateStick,
|
|
129
129
|
setInputWASDEmulateDirection,
|
|
130
130
|
setTouchGamepadEnable,
|
|
131
|
-
|
|
131
|
+
setTouchGamepadCenterButtonSize,
|
|
132
132
|
setTouchGamepadButtonCount,
|
|
133
133
|
setTouchGamepadAnalog,
|
|
134
134
|
setTouchGamepadSize,
|
|
@@ -168,10 +168,12 @@ export
|
|
|
168
168
|
distanceAngle,
|
|
169
169
|
lerpAngle,
|
|
170
170
|
lerp,
|
|
171
|
+
percentLerp,
|
|
171
172
|
smoothStep,
|
|
172
173
|
nearestPowerOfTwo,
|
|
173
174
|
isOverlapping,
|
|
174
175
|
isIntersecting,
|
|
176
|
+
lineTest,
|
|
175
177
|
oscillate,
|
|
176
178
|
|
|
177
179
|
// Utilities
|
package/src/engineInput.js
CHANGED
|
@@ -497,7 +497,7 @@ function inputInit()
|
|
|
497
497
|
if (touching)
|
|
498
498
|
{
|
|
499
499
|
touchGamepadTimer.set();
|
|
500
|
-
if (
|
|
500
|
+
if (touchGamepadCenterButtonSize && !wasTouching && paused)
|
|
501
501
|
{
|
|
502
502
|
// touch anywhere to press start when paused
|
|
503
503
|
touchGamepadButtons[9] = 1;
|
|
@@ -522,6 +522,7 @@ function inputInit()
|
|
|
522
522
|
// virtual analog stick
|
|
523
523
|
const delta = touchPos.subtract(stickCenter);
|
|
524
524
|
touchGamepadSticks[0] = delta.scale(2/touchGamepadSize).clampLength();
|
|
525
|
+
touchGamepadButtons[10] = 1; // also press a button when touching stick
|
|
525
526
|
}
|
|
526
527
|
else if (buttonCenter.distance(touchPos) < touchGamepadSize)
|
|
527
528
|
{
|
|
@@ -530,6 +531,7 @@ function inputInit()
|
|
|
530
531
|
// virtual right analog stick
|
|
531
532
|
const delta = touchPos.subtract(buttonCenter);
|
|
532
533
|
touchGamepadSticks[1] = delta.scale(2/touchGamepadSize).clampLength();
|
|
534
|
+
touchGamepadButtons[11] = 1; // also press a button when touching right stick
|
|
533
535
|
}
|
|
534
536
|
// virtual face buttons
|
|
535
537
|
let button = buttonCenter.subtract(touchPos).direction();
|
|
@@ -546,8 +548,7 @@ function inputInit()
|
|
|
546
548
|
if (button < touchGamepadButtonCount)
|
|
547
549
|
touchGamepadButtons[button] = 1;
|
|
548
550
|
}
|
|
549
|
-
else if (
|
|
550
|
-
startCenter.distance(touchPos) < touchGamepadSize)
|
|
551
|
+
else if (startCenter.distance(touchPos) < touchGamepadCenterButtonSize)
|
|
551
552
|
{
|
|
552
553
|
// virtual start button in center
|
|
553
554
|
touchGamepadButtons[9] = 1;
|
|
@@ -596,6 +597,18 @@ function inputUpdate()
|
|
|
596
597
|
// update touch gamepad if enabled
|
|
597
598
|
if (touchGamepadEnable && isTouchDevice)
|
|
598
599
|
{
|
|
600
|
+
if (debugGamepads)
|
|
601
|
+
{
|
|
602
|
+
const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
|
|
603
|
+
const buttonCenter = touchGamepadButtonCenter();
|
|
604
|
+
const startCenter = mainCanvasSize.scale(.5);
|
|
605
|
+
|
|
606
|
+
debugCircle(stickCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
|
|
607
|
+
debugCircle(buttonCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
|
|
608
|
+
if (touchGamepadCenterButtonSize)
|
|
609
|
+
debugCircle(startCenter, 2*touchGamepadCenterButtonSize, 'cyan', 0, false, true);
|
|
610
|
+
}
|
|
611
|
+
|
|
599
612
|
if (!touchGamepadTimer.isSet()) return;
|
|
600
613
|
|
|
601
614
|
// read virtual analog stick
|
|
@@ -623,7 +636,7 @@ function inputUpdate()
|
|
|
623
636
|
|
|
624
637
|
// read virtual gamepad buttons
|
|
625
638
|
const data = inputData[1] ?? (inputData[1] = []);
|
|
626
|
-
for (let i=
|
|
639
|
+
for (let i=12; i--;)
|
|
627
640
|
{
|
|
628
641
|
const wasDown = gamepadIsDown(i,0);
|
|
629
642
|
data[i] = touchGamepadButtons[i] ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
|
package/src/engineObject.js
CHANGED
package/src/engineSettings.js
CHANGED
|
@@ -230,18 +230,22 @@ let touchInputEnable = true;
|
|
|
230
230
|
|
|
231
231
|
/** True if touch gamepad should appear on mobile devices
|
|
232
232
|
* - Supports left analog stick, 4 face buttons and start button (button 9)
|
|
233
|
+
* - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
|
|
234
|
+
* - Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
|
|
235
|
+
|
|
233
236
|
* @type {boolean}
|
|
234
237
|
* @default
|
|
235
238
|
* @memberof Settings */
|
|
236
239
|
let touchGamepadEnable = false;
|
|
237
240
|
|
|
238
241
|
/** True if touch gamepad should have start button in the center
|
|
242
|
+
* - Prevents activating if overlappng with virtual stick or buttons if they are enabled
|
|
239
243
|
* - When the game is paused, any touch will press the button
|
|
240
|
-
* -
|
|
241
|
-
* @type {
|
|
244
|
+
* - Set size to enable the center button
|
|
245
|
+
* @type {number}
|
|
242
246
|
* @default
|
|
243
247
|
* @memberof Settings */
|
|
244
|
-
let
|
|
248
|
+
let touchGamepadCenterButtonSize = 300;
|
|
245
249
|
|
|
246
250
|
/** Number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
|
|
247
251
|
* @type {number}
|
|
@@ -259,7 +263,7 @@ let touchGamepadAnalog = true;
|
|
|
259
263
|
* @type {number}
|
|
260
264
|
* @default
|
|
261
265
|
* @memberof Settings */
|
|
262
|
-
let touchGamepadSize =
|
|
266
|
+
let touchGamepadSize = 100;
|
|
263
267
|
|
|
264
268
|
/** Transparency of touch gamepad overlay
|
|
265
269
|
* @type {number}
|
|
@@ -527,11 +531,12 @@ function setTouchInputEnable(enable) { touchInputEnable = enable; }
|
|
|
527
531
|
* @memberof Settings */
|
|
528
532
|
function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
|
|
529
533
|
|
|
530
|
-
/**
|
|
531
|
-
* -
|
|
532
|
-
*
|
|
534
|
+
/** Set if touch gamepad should have start button in the center
|
|
535
|
+
* - Set size to enable the center button
|
|
536
|
+
* - When the game is paused, any touch will press the button
|
|
537
|
+
* @param {number} size
|
|
533
538
|
* @memberof Settings */
|
|
534
|
-
function
|
|
539
|
+
function setTouchGamepadCenterButtonSize(size) { touchGamepadCenterButtonSize = size; }
|
|
535
540
|
|
|
536
541
|
/** Set number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
|
|
537
542
|
* @param {number} count
|