littlejsengine 1.18.4 → 1.18.8
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/COPYRIGHT.txt +38 -0
- package/FAQ.md +633 -0
- package/README.md +19 -1
- package/dist/littlejs.d.ts +354 -55
- package/dist/littlejs.esm.js +1531 -489
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1499 -476
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +1493 -470
- package/package.json +8 -1
- package/plugins/box2d.js +32 -7
- package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
- package/plugins/pathFinder.js +758 -0
- package/plugins/pluginExport.js +19 -0
- package/plugins/{tween.js → tweenSystem.js} +7 -7
- package/plugins/uiSystem.js +186 -25
- package/src/engine.js +2 -141
- package/src/engineAudio.js +3 -3
- package/src/engineBuild.mjs +4 -2
- package/src/engineDebug.js +7 -7
- package/src/engineDraw.js +26 -8
- package/src/engineExport.js +13 -13
- package/src/engineInput.js +8 -8
- package/src/engineLogo.js +146 -0
- package/src/engineMath.js +15 -6
- package/src/engineObject.js +11 -5
- package/src/engineParticles.js +6 -3
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +0 -47
- package/src/engineUtilities.js +13 -8
- package/src/engineWebGL.js +34 -7
- package/src/jsconfig.json +3 -1
- package/.github/workflows/test.yml +0 -17
- package/AI.md +0 -173
- package/CLAUDE.md +0 -1
- package/examples/box2d/game.js +0 -192
- package/examples/box2d/gameObjects.js +0 -564
- package/examples/box2d/index.html +0 -9
- package/examples/box2d/scenes.js +0 -194
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +0 -175
- package/examples/breakout/gameObjects.js +0 -147
- package/examples/breakout/index.html +0 -8
- package/examples/breakout/tiles.png +0 -0
- package/examples/breakoutTutorial/README.md +0 -521
- package/examples/breakoutTutorial/game.js +0 -191
- package/examples/breakoutTutorial/images/1.png +0 -0
- package/examples/breakoutTutorial/images/10.png +0 -0
- package/examples/breakoutTutorial/images/11.png +0 -0
- package/examples/breakoutTutorial/images/2.png +0 -0
- package/examples/breakoutTutorial/images/3.png +0 -0
- package/examples/breakoutTutorial/images/4.png +0 -0
- package/examples/breakoutTutorial/images/5.png +0 -0
- package/examples/breakoutTutorial/images/6.png +0 -0
- package/examples/breakoutTutorial/images/7.png +0 -0
- package/examples/breakoutTutorial/images/8.png +0 -0
- package/examples/breakoutTutorial/images/9.png +0 -0
- package/examples/breakoutTutorial/index.html +0 -8
- package/examples/electron/build.mjs +0 -127
- package/examples/electron/electron.js +0 -35
- package/examples/electron/game.js +0 -54
- package/examples/electron/index.html +0 -13
- package/examples/electron/package.json +0 -5
- package/examples/electron/tiles.png +0 -0
- package/examples/empty/game.js +0 -51
- package/examples/empty/index.html +0 -5
- package/examples/empty/tiles.png +0 -0
- package/examples/favicon.png +0 -0
- package/examples/games.jpg +0 -0
- package/examples/htmlMenu/game.js +0 -82
- package/examples/htmlMenu/index.html +0 -45
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +0 -62
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/build.mjs +0 -124
- package/examples/module/game.js +0 -132
- package/examples/module/index.html +0 -10
- package/examples/module/tiles.png +0 -0
- package/examples/particles/index.html +0 -426
- package/examples/particles/tiles.png +0 -0
- package/examples/platformer/data/gameLevelData.tmx +0 -143
- package/examples/platformer/data/gameLevelData.tsx +0 -4
- package/examples/platformer/game.js +0 -147
- package/examples/platformer/gameCharacter.js +0 -309
- package/examples/platformer/gameEffects.js +0 -278
- package/examples/platformer/gameLevel.js +0 -205
- package/examples/platformer/gameLevelData.json +0 -171
- package/examples/platformer/gameObjects.js +0 -378
- package/examples/platformer/gamePlayer.js +0 -35
- package/examples/platformer/index.html +0 -9
- package/examples/platformer/tiles.png +0 -0
- package/examples/platformer/tilesLevel.png +0 -0
- package/examples/puzzle/game.js +0 -331
- package/examples/puzzle/index.html +0 -8
- package/examples/puzzle/tiles.png +0 -0
- package/examples/screenshot.jpg +0 -0
- package/examples/shorts/animation.js +0 -18
- package/examples/shorts/base.html +0 -54
- package/examples/shorts/blending.js +0 -14
- package/examples/shorts/box2d.js +0 -51
- package/examples/shorts/box2dCar.js +0 -59
- package/examples/shorts/box2dPool.js +0 -107
- package/examples/shorts/box2dTileLayer.js +0 -48
- package/examples/shorts/cameraDrag.js +0 -22
- package/examples/shorts/clock.js +0 -21
- package/examples/shorts/colors.js +0 -25
- package/examples/shorts/debugDraw.js +0 -37
- package/examples/shorts/empty.js +0 -30
- package/examples/shorts/flappyGame.js +0 -55
- package/examples/shorts/fontImage.js +0 -17
- package/examples/shorts/fps.js +0 -90
- package/examples/shorts/helloWorld.js +0 -11
- package/examples/shorts/hillGlideGame.js +0 -63
- package/examples/shorts/input.js +0 -64
- package/examples/shorts/landerGame.js +0 -57
- package/examples/shorts/maze.js +0 -48
- package/examples/shorts/medals.js +0 -51
- package/examples/shorts/music.js +0 -78
- package/examples/shorts/musicPlayer.js +0 -137
- package/examples/shorts/nineSlice.js +0 -40
- package/examples/shorts/parallax.js +0 -72
- package/examples/shorts/particles.js +0 -28
- package/examples/shorts/piano.js +0 -44
- package/examples/shorts/platformer.js +0 -45
- package/examples/shorts/pongGame.js +0 -41
- package/examples/shorts/postProcess.js +0 -62
- package/examples/shorts/sequencer.js +0 -124
- package/examples/shorts/shader.js +0 -29
- package/examples/shorts/shapes.js +0 -21
- package/examples/shorts/slidingPuzzle.js +0 -52
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/sound.js +0 -36
- package/examples/shorts/spaceGame.js +0 -58
- package/examples/shorts/spriteAtlas.js +0 -31
- package/examples/shorts/starfield.js +0 -15
- package/examples/shorts/texture.js +0 -16
- package/examples/shorts/textureWrapped.js +0 -12
- package/examples/shorts/tileLayer.js +0 -48
- package/examples/shorts/tileRaycast.js +0 -39
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +0 -63
- package/examples/shorts/timers.js +0 -53
- package/examples/shorts/topDown.js +0 -38
- package/examples/shorts/tween.js +0 -24
- package/examples/shorts/uiSystem.js +0 -61
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +0 -34
- package/examples/shorts.js +0 -743
- package/examples/starter/build.bat +0 -7
- package/examples/starter/build.mjs +0 -126
- package/examples/starter/game.js +0 -137
- package/examples/starter/index.html +0 -35
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +0 -173
- package/examples/style.css +0 -150
- package/examples/tweenSystem/game.js +0 -171
- package/examples/tweenSystem/index.html +0 -10
- package/examples/tweenSystem/tiles.png +0 -0
- package/examples/typescript/build.mjs +0 -60
- package/examples/typescript/game.js +0 -100
- package/examples/typescript/game.ts +0 -132
- package/examples/typescript/index.html +0 -10
- package/examples/typescript/tiles.png +0 -0
- package/examples/typescript/tsconfig.json +0 -17
- package/examples/uiSystem/game.js +0 -139
- package/examples/uiSystem/index.html +0 -10
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +0 -12
- package/plugins/desktop.ini +0 -2
- package/reference.md +0 -448
- package/test/math.test.mjs +0 -774
- package/test/setup.mjs +0 -22
- package/test/smoke.test.mjs +0 -274
- package/test/tween.test.mjs +0 -576
- package/test/util.test.mjs +0 -80
package/README.md
CHANGED
|
@@ -54,11 +54,13 @@ The code is very clean and well documented with many examples to get you started
|
|
|
54
54
|
- Robust arcade physics system with collision handling
|
|
55
55
|
- Fast tilemap collision and raycasting
|
|
56
56
|
- Full Box2D integration for realistic physics
|
|
57
|
+
- Grid-based A* pathfinding plugin with optional path smoothing
|
|
57
58
|
|
|
58
59
|
### 🚀 Flexibility
|
|
59
60
|
|
|
60
61
|
- Compatible with all modern web browsers and mobile devices
|
|
61
62
|
- Full TypeScript and Module support with example projects for both
|
|
63
|
+
- [Vite](https://vite.dev) starter template for instant dev server with hot reload
|
|
62
64
|
- Great for size coding competitions like [Js13kGames](https://js13kgames.com/)
|
|
63
65
|
- Open Source and [MIT licensed](https://github.com/KilledByAPixel/LittleJS/blob/main/LICENSE)
|
|
64
66
|
|
|
@@ -72,7 +74,23 @@ The code is very clean and well documented with many examples to get you started
|
|
|
72
74
|
|
|
73
75
|
## How To Use LittleJS
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
|
|
78
|
+
To get started download the latest LittleJS package from GitHub or install via npm:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
npm install littlejsengine
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
or use `degit` for an empty Vite template
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
npx degit KilledByAPixel/LittleJS/examples/vite-starter my-game
|
|
88
|
+
cd my-game
|
|
89
|
+
npm install
|
|
90
|
+
npm run dev
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Tutorials
|
|
76
94
|
|
|
77
95
|
- [Making Awesome Games With LittleJS](https://youtu.be/_dXKU0WgAj8?si=ZDXLYAFDWp54hrGT) - A short talk about LittleJS with some tips on how to use it.
|
|
78
96
|
- [Tutorial: Breakout](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial) - Learn how to make a simple game from scratch
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -88,6 +88,10 @@ declare module "littlejsengine" {
|
|
|
88
88
|
* @type {Array<EngineObject>}
|
|
89
89
|
* @memberof Engine */
|
|
90
90
|
export let engineObjects: Array<EngineObject>;
|
|
91
|
+
/** Array with only objects set to collide with other objects this frame (for optimization)
|
|
92
|
+
* @type {Array<EngineObject>}
|
|
93
|
+
* @memberof Engine */
|
|
94
|
+
export let engineObjectsCollide: Array<EngineObject>;
|
|
91
95
|
/** Current update frame, used to calculate time
|
|
92
96
|
* @type {number}
|
|
93
97
|
* @memberof Engine */
|
|
@@ -226,6 +230,11 @@ declare module "littlejsengine" {
|
|
|
226
230
|
* @param {...Object} output - message output
|
|
227
231
|
* @memberof Debug */
|
|
228
232
|
export function LOG(...output: any[]): void;
|
|
233
|
+
/** Size to render debug points by default
|
|
234
|
+
* @type {number}
|
|
235
|
+
* @default
|
|
236
|
+
* @memberof Debug */
|
|
237
|
+
export const debugPointSize: number;
|
|
229
238
|
/** Draw a debug rectangle in world space
|
|
230
239
|
* @param {Vector2} pos
|
|
231
240
|
* @param {Vector2} [size=vec2(0)]
|
|
@@ -471,6 +480,11 @@ declare module "littlejsengine" {
|
|
|
471
480
|
* @default
|
|
472
481
|
* @memberof Settings */
|
|
473
482
|
export let glEnable: boolean;
|
|
483
|
+
/** How many sided poly to use when drawing circles and ellipses with WebGL
|
|
484
|
+
* @type {number}
|
|
485
|
+
* @default
|
|
486
|
+
* @memberof Settings */
|
|
487
|
+
export let glCircleSides: number;
|
|
474
488
|
/** Should gamepads be allowed
|
|
475
489
|
* @type {boolean}
|
|
476
490
|
* @default
|
|
@@ -486,6 +500,12 @@ declare module "littlejsengine" {
|
|
|
486
500
|
* @default
|
|
487
501
|
* @memberof Settings */
|
|
488
502
|
export let inputWASDEmulateDirection: boolean;
|
|
503
|
+
/** True if touch input is enabled for mobile devices
|
|
504
|
+
* - Touch events will be routed to mouse events
|
|
505
|
+
* @type {boolean}
|
|
506
|
+
* @default
|
|
507
|
+
* @memberof Settings */
|
|
508
|
+
export let touchInputEnable: boolean;
|
|
489
509
|
/** True if touch gamepad should appear on mobile devices
|
|
490
510
|
* - Supports left analog stick, 4 face buttons and start button (button 9)
|
|
491
511
|
* - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
|
|
@@ -503,6 +523,11 @@ declare module "littlejsengine" {
|
|
|
503
523
|
* @default
|
|
504
524
|
* @memberof Settings */
|
|
505
525
|
export let touchGamepadCenterButtonSize: number;
|
|
526
|
+
/** Number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
|
|
527
|
+
* @type {number}
|
|
528
|
+
* @default
|
|
529
|
+
* @memberof Settings */
|
|
530
|
+
export let touchGamepadButtonCount: number;
|
|
506
531
|
/** True if touch gamepad should be analog stick or false to use if 8 way dpad
|
|
507
532
|
* @type {boolean}
|
|
508
533
|
* @default
|
|
@@ -548,21 +573,6 @@ declare module "littlejsengine" {
|
|
|
548
573
|
* @default
|
|
549
574
|
* @memberof Settings */
|
|
550
575
|
export let soundDefaultTaper: number;
|
|
551
|
-
/** How long to show medals for in seconds
|
|
552
|
-
* @type {number}
|
|
553
|
-
* @default
|
|
554
|
-
* @memberof Settings */
|
|
555
|
-
export let medalDisplayTime: number;
|
|
556
|
-
/** How quickly to slide on/off medals in seconds
|
|
557
|
-
* @type {number}
|
|
558
|
-
* @default
|
|
559
|
-
* @memberof Settings */
|
|
560
|
-
export let medalDisplaySlideTime: number;
|
|
561
|
-
/** Size of medal display
|
|
562
|
-
* @type {Vector2}
|
|
563
|
-
* @default Vector2(640,80)
|
|
564
|
-
* @memberof Settings */
|
|
565
|
-
export let medalDisplaySize: Vector2;
|
|
566
576
|
/** Set position of camera in world space
|
|
567
577
|
* @param {Vector2} pos
|
|
568
578
|
* @memberof Settings */
|
|
@@ -683,6 +693,10 @@ declare module "littlejsengine" {
|
|
|
683
693
|
* @param {number} scale
|
|
684
694
|
* @memberof Settings */
|
|
685
695
|
export function setParticleEmitRateScale(scale: number): void;
|
|
696
|
+
/** Set how many sided polygons to use when drawing circles and ellipses with WebGL
|
|
697
|
+
* @param {number} sides
|
|
698
|
+
* @memberof Settings */
|
|
699
|
+
export function setGLCircleSides(sides: number): void;
|
|
686
700
|
/** Set if touch input is allowed
|
|
687
701
|
* @param {boolean} enable
|
|
688
702
|
* @memberof Settings */
|
|
@@ -745,22 +759,6 @@ declare module "littlejsengine" {
|
|
|
745
759
|
* @param {number} taper
|
|
746
760
|
* @memberof Settings */
|
|
747
761
|
export function setSoundDefaultTaper(taper: number): void;
|
|
748
|
-
/** Set how long to show medals for in seconds
|
|
749
|
-
* @param {number} time
|
|
750
|
-
* @memberof Settings */
|
|
751
|
-
export function setMedalDisplayTime(time: number): void;
|
|
752
|
-
/** Set how quickly to slide on/off medals in seconds
|
|
753
|
-
* @param {number} time
|
|
754
|
-
* @memberof Settings */
|
|
755
|
-
export function setMedalDisplaySlideTime(time: number): void;
|
|
756
|
-
/** Set size of medal display
|
|
757
|
-
* @param {Vector2} size
|
|
758
|
-
* @memberof Settings */
|
|
759
|
-
export function setMedalDisplaySize(size: Vector2): void;
|
|
760
|
-
/** Set to stop medals from being unlockable
|
|
761
|
-
* @param {boolean} preventUnlock
|
|
762
|
-
* @memberof Settings */
|
|
763
|
-
export function setMedalsPreventUnlock(preventUnlock: boolean): void;
|
|
764
762
|
/** Set if watermark with FPS should be shown
|
|
765
763
|
* @param {boolean} show
|
|
766
764
|
* @memberof Debug */
|
|
@@ -823,17 +821,17 @@ declare module "littlejsengine" {
|
|
|
823
821
|
* @param {number} x
|
|
824
822
|
* @return {number}
|
|
825
823
|
* @memberof Math */
|
|
826
|
-
export const sign:
|
|
824
|
+
export const sign: any;
|
|
827
825
|
/** Returns hypotenuse of values passed in
|
|
828
826
|
* @param {...number} values
|
|
829
827
|
* @return {number}
|
|
830
828
|
* @memberof Math */
|
|
831
|
-
export const hypot:
|
|
829
|
+
export const hypot: any;
|
|
832
830
|
/** Returns log2 of value passed in
|
|
833
831
|
* @param {number} x
|
|
834
832
|
* @return {number}
|
|
835
833
|
* @memberof Math */
|
|
836
|
-
export const log2:
|
|
834
|
+
export const log2: any;
|
|
837
835
|
/** Returns sin of value passed in
|
|
838
836
|
* @param {number} x
|
|
839
837
|
* @return {number}
|
|
@@ -930,6 +928,11 @@ declare module "littlejsengine" {
|
|
|
930
928
|
* @return {number}
|
|
931
929
|
* @memberof Math */
|
|
932
930
|
export function nearestPowerOfTwo(value: number): number;
|
|
931
|
+
/** Checks if the value passed in is a power of two
|
|
932
|
+
* @param {number} value
|
|
933
|
+
* @return {boolean}
|
|
934
|
+
* @memberof Math */
|
|
935
|
+
export function isPowerOfTwo(value: number): boolean;
|
|
933
936
|
/** Returns true if two axis aligned bounding boxes are overlapping
|
|
934
937
|
* this can be used for simple collision detection between objects
|
|
935
938
|
* @param {Vector2} posA - Center of box A
|
|
@@ -1229,8 +1232,10 @@ declare module "littlejsengine" {
|
|
|
1229
1232
|
/** Returns a copy of this vector with each axis floored
|
|
1230
1233
|
* @return {Vector2} */
|
|
1231
1234
|
floor(): Vector2;
|
|
1232
|
-
/** Returns a copy of this vector snapped to a grid
|
|
1233
|
-
*
|
|
1235
|
+
/** Returns a copy of this vector snapped to a grid. Note that `grid` is
|
|
1236
|
+
* the number of snap steps per unit (so `grid=2` snaps to halves and
|
|
1237
|
+
* `grid=0.5` snaps to twos), not the cell size.
|
|
1238
|
+
* @param {number} grid - snap steps per unit
|
|
1234
1239
|
* @return {Vector2} */
|
|
1235
1240
|
snap(grid: number): Vector2;
|
|
1236
1241
|
/** Returns new vec2 with modded values
|
|
@@ -1468,13 +1473,15 @@ declare module "littlejsengine" {
|
|
|
1468
1473
|
* @memberof Math */
|
|
1469
1474
|
export function isNumber(n: any): boolean;
|
|
1470
1475
|
/**
|
|
1471
|
-
* Check if
|
|
1476
|
+
* Check if a value is stringifiable — i.e. it has a toString that returns
|
|
1477
|
+
* a string. Use this for ASSERTs and inputs that will be coerced to text;
|
|
1478
|
+
* use `typeof x === 'string'` inline if you need strict-string semantics.
|
|
1472
1479
|
* - Returns true for strings, numbers, and most objects
|
|
1473
1480
|
* - Returns false for null and undefined
|
|
1474
1481
|
* @param {any} s
|
|
1475
1482
|
* @return {boolean}
|
|
1476
1483
|
* @memberof Math */
|
|
1477
|
-
export function
|
|
1484
|
+
export function isStringLike(s: any): boolean;
|
|
1478
1485
|
/**
|
|
1479
1486
|
* Check if object is an array
|
|
1480
1487
|
* @param {any} a
|
|
@@ -1605,8 +1612,9 @@ declare module "littlejsengine" {
|
|
|
1605
1612
|
* Create a TextureInfo, called automatically by the engine
|
|
1606
1613
|
* @param {HTMLImageElement|OffscreenCanvas} image
|
|
1607
1614
|
* @param {boolean} [useWebGL] - Should use WebGL if available?
|
|
1615
|
+
* @param {boolean} [wrap] - Should the texture wrap (REPEAT) or clamp (CLAMP_TO_EDGE)?
|
|
1608
1616
|
*/
|
|
1609
|
-
constructor(image: HTMLImageElement | OffscreenCanvas, useWebGL?: boolean);
|
|
1617
|
+
constructor(image: HTMLImageElement | OffscreenCanvas, useWebGL?: boolean, wrap?: boolean);
|
|
1610
1618
|
/** @property {HTMLImageElement|OffscreenCanvas} - image source */
|
|
1611
1619
|
image: OffscreenCanvas | HTMLImageElement;
|
|
1612
1620
|
/** @property {Vector2} - size of the image */
|
|
@@ -1615,6 +1623,8 @@ declare module "littlejsengine" {
|
|
|
1615
1623
|
sizeInverse: Vector2;
|
|
1616
1624
|
/** @property {WebGLTexture} - WebGL texture */
|
|
1617
1625
|
glTexture: any;
|
|
1626
|
+
/** @property {boolean} - true for REPEAT wrap mode, false for CLAMP_TO_EDGE */
|
|
1627
|
+
wrap: boolean;
|
|
1618
1628
|
/** Creates the WebGL texture, updates if already created */
|
|
1619
1629
|
createWebGLTexture(): void;
|
|
1620
1630
|
/** Destroys the WebGL texture */
|
|
@@ -1622,6 +1632,9 @@ declare module "littlejsengine" {
|
|
|
1622
1632
|
/** Check if the texture is webgl enabled
|
|
1623
1633
|
* @return {boolean} */
|
|
1624
1634
|
hasWebGL(): boolean;
|
|
1635
|
+
/** Set the wrap mode for this texture
|
|
1636
|
+
* @param {boolean} [wrap] - true for REPEAT, false for CLAMP_TO_EDGE */
|
|
1637
|
+
setWrap(wrap?: boolean): void;
|
|
1625
1638
|
}
|
|
1626
1639
|
/**
|
|
1627
1640
|
* LittleJS Drawing System
|
|
@@ -1796,6 +1809,19 @@ declare module "littlejsengine" {
|
|
|
1796
1809
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1797
1810
|
* @memberof Draw */
|
|
1798
1811
|
export function drawPoly(points: Array<Vector2>, color?: Color, lineWidth?: number, lineColor?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1812
|
+
/** Draw colored regular polygon using passed in number of sides
|
|
1813
|
+
* @param {Vector2} pos
|
|
1814
|
+
* @param {Vector2} [size=vec2(1)]
|
|
1815
|
+
* @param {number} [sides]
|
|
1816
|
+
* @param {Color} [color=WHITE]
|
|
1817
|
+
* @param {number} [angle]
|
|
1818
|
+
* @param {number} [lineWidth]
|
|
1819
|
+
* @param {Color} [lineColor=BLACK]
|
|
1820
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
1821
|
+
* @param {boolean} [screenSpace]
|
|
1822
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1823
|
+
* @memberof Draw */
|
|
1824
|
+
export function drawRegularPoly(pos: Vector2, size?: Vector2, sides?: number, color?: Color, lineWidth?: number, lineColor?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1799
1825
|
/** Draw colored ellipse using passed in point
|
|
1800
1826
|
* @param {Vector2} pos
|
|
1801
1827
|
* @param {Vector2} [size=vec2(1)] - Width and height diameter
|
|
@@ -1937,6 +1963,14 @@ declare module "littlejsengine" {
|
|
|
1937
1963
|
* @return {Vector2}
|
|
1938
1964
|
* @memberof Draw */
|
|
1939
1965
|
export function getCameraSize(): Vector2;
|
|
1966
|
+
/** Check if a box, point, or circle is on screen with a circle test
|
|
1967
|
+
* If size is a Vector2, uses the length as diameter
|
|
1968
|
+
* This can be used to cull offscreen objects from render or update
|
|
1969
|
+
* @param {Vector2} pos - world space position
|
|
1970
|
+
* @param {Vector2|number} size - world space size or diameter
|
|
1971
|
+
* @return {boolean}
|
|
1972
|
+
* @memberof Draw */
|
|
1973
|
+
export function isOnScreen(pos: Vector2, size?: Vector2 | number): boolean;
|
|
1940
1974
|
/**
|
|
1941
1975
|
* LittleJS WebGL Interface
|
|
1942
1976
|
* - WebGL2 rendering engine for high-performance graphics
|
|
@@ -1972,6 +2006,12 @@ declare module "littlejsengine" {
|
|
|
1972
2006
|
* @param {WebGLTexture} texture
|
|
1973
2007
|
* @memberof WebGL */
|
|
1974
2008
|
export function glSetTexture(texture: WebGLTexture): void;
|
|
2009
|
+
/** Set the wrap mode (REPEAT or CLAMP_TO_EDGE) on an existing WebGL texture
|
|
2010
|
+
* Flushes the current batch only if the texture is the active one
|
|
2011
|
+
* @param {WebGLTexture} texture
|
|
2012
|
+
* @param {boolean} [wrap] - true for REPEAT, false for CLAMP_TO_EDGE
|
|
2013
|
+
* @memberof WebGL */
|
|
2014
|
+
export function glSetTextureWrap(texture: WebGLTexture, wrap?: boolean): void;
|
|
1975
2015
|
/** Compile WebGL shader of the given type, will throw errors if in debug mode
|
|
1976
2016
|
* @param {string} source
|
|
1977
2017
|
* @param {number} type
|
|
@@ -1987,9 +2027,10 @@ declare module "littlejsengine" {
|
|
|
1987
2027
|
/** Create WebGL texture from an image and init the texture settings
|
|
1988
2028
|
* Restores the active texture when done
|
|
1989
2029
|
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} [image]
|
|
2030
|
+
* @param {boolean} [wrap] - true for REPEAT, false for CLAMP_TO_EDGE
|
|
1990
2031
|
* @return {WebGLTexture}
|
|
1991
2032
|
* @memberof WebGL */
|
|
1992
|
-
export function glCreateTexture(image?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas): WebGLTexture;
|
|
2033
|
+
export function glCreateTexture(image?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas, wrap?: boolean): WebGLTexture;
|
|
1993
2034
|
/** Deletes a WebGL texture
|
|
1994
2035
|
* @param {WebGLTexture} [texture]
|
|
1995
2036
|
* @memberof WebGL */
|
|
@@ -2180,7 +2221,7 @@ declare module "littlejsengine" {
|
|
|
2180
2221
|
* This is useful to disable for html menus so the browser can handle input normally
|
|
2181
2222
|
* @param {boolean} preventDefault
|
|
2182
2223
|
* @memberof Input */
|
|
2183
|
-
export function setInputPreventDefault(preventDefault
|
|
2224
|
+
export function setInputPreventDefault(preventDefault?: boolean): void;
|
|
2184
2225
|
/** Returns true if gamepad button is down
|
|
2185
2226
|
* @param {number} button
|
|
2186
2227
|
* @param {number} [gamepad]
|
|
@@ -2205,6 +2246,11 @@ declare module "littlejsengine" {
|
|
|
2205
2246
|
* @return {Vector2}
|
|
2206
2247
|
* @memberof Input */
|
|
2207
2248
|
export function gamepadStick(stick: number, gamepad?: number): Vector2;
|
|
2249
|
+
/** Returns how many control sticks the passed in gamepad has
|
|
2250
|
+
* @param {number} [gamepad]
|
|
2251
|
+
* @return {number}
|
|
2252
|
+
* @memberof Input */
|
|
2253
|
+
export function gamepadStickCount(gamepad?: number): number;
|
|
2208
2254
|
/** Returns gamepad dpad value
|
|
2209
2255
|
* @param {number} [gamepad]
|
|
2210
2256
|
* @return {Vector2}
|
|
@@ -2269,6 +2315,10 @@ declare module "littlejsengine" {
|
|
|
2269
2315
|
* @default 44100
|
|
2270
2316
|
* @memberof Audio */
|
|
2271
2317
|
export const audioDefaultSampleRate: 44100;
|
|
2318
|
+
/** Check if the audio context is running and available for playback
|
|
2319
|
+
* @return {boolean} - True if the audio context is running
|
|
2320
|
+
* @memberof Audio */
|
|
2321
|
+
export function audioIsRunning(): boolean;
|
|
2272
2322
|
/**
|
|
2273
2323
|
* Sound Object - Stores a sound for later
|
|
2274
2324
|
* - this can be used to load and play wave, mp3, and ogg files
|
|
@@ -3158,16 +3208,6 @@ declare module "littlejsengine" {
|
|
|
3158
3208
|
/** Render the particle, automatically called each frame */
|
|
3159
3209
|
render(): void;
|
|
3160
3210
|
}
|
|
3161
|
-
/**
|
|
3162
|
-
* LittleJS Medal System
|
|
3163
|
-
* - Achievement/trophy system for games
|
|
3164
|
-
* - Medal class with name, description, icon, and unlock tracking
|
|
3165
|
-
* - Automatic saving to local storage
|
|
3166
|
-
* - Visual display queue with slide-in notifications
|
|
3167
|
-
* - Newgrounds API integration for online achievements
|
|
3168
|
-
* - Debug mode to unlock/reset medals during development
|
|
3169
|
-
* @namespace Medals
|
|
3170
|
-
*/
|
|
3171
3211
|
/** List of all medals
|
|
3172
3212
|
* @type {Object}
|
|
3173
3213
|
* @memberof Medals */
|
|
@@ -3183,6 +3223,15 @@ declare module "littlejsengine" {
|
|
|
3183
3223
|
* @param {string} saveName
|
|
3184
3224
|
* @memberof Medals */
|
|
3185
3225
|
export function medalsInit(saveName: string): void;
|
|
3226
|
+
/**
|
|
3227
|
+
* @callback MedalCallbackFunction - Function that processes a medal
|
|
3228
|
+
* @param {Medal} medal
|
|
3229
|
+
* @memberof Medals
|
|
3230
|
+
*/
|
|
3231
|
+
/** Calls a function for each medal
|
|
3232
|
+
* @param {MedalCallbackFunction} callback
|
|
3233
|
+
* @memberof Medals */
|
|
3234
|
+
export function medalsForEach(callback: MedalCallbackFunction): void;
|
|
3186
3235
|
/**
|
|
3187
3236
|
* Medal - Tracks an unlockable medal
|
|
3188
3237
|
* @memberof Medals
|
|
@@ -3229,6 +3278,37 @@ declare module "littlejsengine" {
|
|
|
3229
3278
|
renderIcon(pos: Vector2, size: number): void;
|
|
3230
3279
|
storageKey(): string;
|
|
3231
3280
|
}
|
|
3281
|
+
/** How long to show medals for in seconds
|
|
3282
|
+
* @type {number}
|
|
3283
|
+
* @default
|
|
3284
|
+
* @memberof Settings */
|
|
3285
|
+
export let medalDisplayTime: number;
|
|
3286
|
+
/** How quickly to slide on/off medals in seconds
|
|
3287
|
+
* @type {number}
|
|
3288
|
+
* @default
|
|
3289
|
+
* @memberof Settings */
|
|
3290
|
+
export let medalDisplaySlideTime: number;
|
|
3291
|
+
/** Size of medal display
|
|
3292
|
+
* @type {Vector2}
|
|
3293
|
+
* @default Vector2(640,80)
|
|
3294
|
+
* @memberof Settings */
|
|
3295
|
+
export let medalDisplaySize: Vector2;
|
|
3296
|
+
/** Set how long to show medals for in seconds
|
|
3297
|
+
* @param {number} time
|
|
3298
|
+
* @memberof Settings */
|
|
3299
|
+
export function setMedalDisplayTime(time: number): void;
|
|
3300
|
+
/** Set how quickly to slide on/off medals in seconds
|
|
3301
|
+
* @param {number} time
|
|
3302
|
+
* @memberof Settings */
|
|
3303
|
+
export function setMedalDisplaySlideTime(time: number): void;
|
|
3304
|
+
/** Set size of medal display
|
|
3305
|
+
* @param {Vector2} size
|
|
3306
|
+
* @memberof Settings */
|
|
3307
|
+
export function setMedalDisplaySize(size: Vector2): void;
|
|
3308
|
+
/** Set to stop medals from being unlockable
|
|
3309
|
+
* @param {boolean} preventUnlock
|
|
3310
|
+
* @memberof Settings */
|
|
3311
|
+
export function setMedalsPreventUnlock(preventUnlock: boolean): void;
|
|
3232
3312
|
/**
|
|
3233
3313
|
* LittleJS Newgrounds Plugin
|
|
3234
3314
|
* - NewgroundsMedal extends Medal with Newgrounds API functionality
|
|
@@ -3478,8 +3558,10 @@ declare module "littlejsengine" {
|
|
|
3478
3558
|
lastHoverObject: any;
|
|
3479
3559
|
/** @property {UIObject} - Current confirm menu being shown */
|
|
3480
3560
|
confirmDialog: any;
|
|
3481
|
-
/** @
|
|
3482
|
-
|
|
3561
|
+
/** @private */
|
|
3562
|
+
private _keyInputObject;
|
|
3563
|
+
/** @private */
|
|
3564
|
+
private _onKeyDown;
|
|
3483
3565
|
/** Draw a rectangle to the UI context
|
|
3484
3566
|
* @param {Vector2} pos
|
|
3485
3567
|
* @param {Vector2} size
|
|
@@ -3541,8 +3623,14 @@ declare module "littlejsengine" {
|
|
|
3541
3623
|
* @param {Vector2} pos
|
|
3542
3624
|
* @return {Vector2} */
|
|
3543
3625
|
screenToNative(pos: Vector2): Vector2;
|
|
3626
|
+
set keyInputObject(arg: UIObject);
|
|
3627
|
+
/** Object to send keyboard input to (typically a UITextInput).
|
|
3628
|
+
* The document keydown listener is only attached while this is set,
|
|
3629
|
+
* so games that never use text input pay no event-handling cost.
|
|
3630
|
+
* @type {UIObject} */
|
|
3631
|
+
get keyInputObject(): UIObject;
|
|
3544
3632
|
/** Destroy and remove all objects
|
|
3545
|
-
* @memberof
|
|
3633
|
+
* @memberof UISystem */
|
|
3546
3634
|
destroyObjects(): void;
|
|
3547
3635
|
/** Get all navigable UI objects sorted by navigationIndex
|
|
3548
3636
|
* @return {Array<UIObject>} */
|
|
@@ -3650,6 +3738,10 @@ declare module "littlejsengine" {
|
|
|
3650
3738
|
navigationIndex: any;
|
|
3651
3739
|
/** @property {boolean} - Should this be auto selected by navigation? Must also have valid navigation index. */
|
|
3652
3740
|
navigationAutoSelect: boolean;
|
|
3741
|
+
/** @property {Vector2} - Where on parent (or canvas if no parent) this object is anchored.
|
|
3742
|
+
* Components in [-1, 1]: (0,0)=center, (-1,-1)=top-left, (1,1)=bottom-right.
|
|
3743
|
+
* Also acts as self-pivot — e.g. (1,-1) puts your top-right corner at the anchor point. */
|
|
3744
|
+
anchor: Vector2;
|
|
3653
3745
|
/** Add a child UIObject to this object, returns child for chaining
|
|
3654
3746
|
* @param {UIObject} child
|
|
3655
3747
|
* @return {UIObject} The child object added */
|
|
@@ -3891,6 +3983,37 @@ declare module "littlejsengine" {
|
|
|
3891
3983
|
* @param {number} time - Time in seconds to seek to */
|
|
3892
3984
|
setTime(time: number): void;
|
|
3893
3985
|
}
|
|
3986
|
+
/**
|
|
3987
|
+
* UILayout - A container that auto-arranges children in a vertical list, horizontal list, or grid
|
|
3988
|
+
* - Set columns to 1 for a vertical list (default)
|
|
3989
|
+
* - Set columns to children.length for a horizontal list
|
|
3990
|
+
* - Set columns to N (1 < N < children.length) for a grid with N columns
|
|
3991
|
+
* - Per-child sizing: each row's height = max child.size.y in that row, each column's width = max child.size.x in that column
|
|
3992
|
+
* - Children are positioned centered in their cell
|
|
3993
|
+
* - Container auto-sizes to fit children plus padding
|
|
3994
|
+
* @extends UIObject
|
|
3995
|
+
* @memberof UISystem
|
|
3996
|
+
*/
|
|
3997
|
+
export class UILayout extends UIObject {
|
|
3998
|
+
/** Create a UILayout container that auto-arranges children
|
|
3999
|
+
* @param {Vector2} [pos]
|
|
4000
|
+
* @param {number} [columns=1] - Number of columns (1 = vertical list)
|
|
4001
|
+
* @param {number} [gap=10] - Space between children
|
|
4002
|
+
* @param {number} [padding=10] - Space between container border and children
|
|
4003
|
+
* @param {boolean} [transparent=false] - If true, draws no background, outline, or shadow
|
|
4004
|
+
*/
|
|
4005
|
+
constructor(pos?: Vector2, columns?: number, gap?: number, padding?: number, transparent?: boolean);
|
|
4006
|
+
/** @property {number} - Number of columns in the layout */
|
|
4007
|
+
columns: number;
|
|
4008
|
+
/** @property {number} - Space between children */
|
|
4009
|
+
gap: number;
|
|
4010
|
+
/** @property {number} - Space between container border and children */
|
|
4011
|
+
padding: number;
|
|
4012
|
+
/** Recompute child positions and container size based on per-child sizes.
|
|
4013
|
+
* Called automatically by addChild and removeChild. Call manually if you
|
|
4014
|
+
* mutate a child's size or change columns, gap, or padding. */
|
|
4015
|
+
relayout(): void;
|
|
4016
|
+
}
|
|
3894
4017
|
/**
|
|
3895
4018
|
* LittleJS Box2D Physics Plugin
|
|
3896
4019
|
* - Box2dObject extends EngineObject with Box2D physics
|
|
@@ -4214,13 +4337,25 @@ declare module "littlejsengine" {
|
|
|
4214
4337
|
* @param {Vector2} force
|
|
4215
4338
|
* @param {Vector2} [pos] */
|
|
4216
4339
|
applyForce(force: Vector2, pos?: Vector2): void;
|
|
4217
|
-
/** Apply acceleration to this object
|
|
4340
|
+
/** Apply acceleration to this object (changes velocity by acceleration,
|
|
4341
|
+
* mass-independent — matches EngineObject.applyAcceleration semantics).
|
|
4342
|
+
* Use applyImpulse if you want the mass-dependent velocity change
|
|
4343
|
+
* Δv = impulse / mass, or applyForce for a Newton-style sustained force.
|
|
4218
4344
|
* @param {Vector2} acceleration
|
|
4219
4345
|
* @param {Vector2} [pos] */
|
|
4220
4346
|
applyAcceleration(acceleration: Vector2, pos?: Vector2): void;
|
|
4347
|
+
/** Apply an instantaneous linear impulse. Changes velocity immediately by
|
|
4348
|
+
* impulse / mass (so heavier bodies move less for the same impulse).
|
|
4349
|
+
* @param {Vector2} impulse
|
|
4350
|
+
* @param {Vector2} [pos] */
|
|
4351
|
+
applyImpulse(impulse: Vector2, pos?: Vector2): void;
|
|
4221
4352
|
/** Apply torque to this object
|
|
4222
4353
|
* @param {number} torque */
|
|
4223
4354
|
applyTorque(torque: number): void;
|
|
4355
|
+
/** Apply an instantaneous angular impulse. Changes angular velocity by
|
|
4356
|
+
* impulse / inertia immediately.
|
|
4357
|
+
* @param {number} impulse */
|
|
4358
|
+
applyAngularImpulse(impulse: number): void;
|
|
4224
4359
|
/** Check if this object has any fixtures
|
|
4225
4360
|
* @return {boolean} */
|
|
4226
4361
|
hasFixtures(): boolean;
|
|
@@ -5071,4 +5206,168 @@ declare module "littlejsengine" {
|
|
|
5071
5206
|
function PIECEWISE(...fns: ((arg0: number) => number)[]): (arg0: number) => number;
|
|
5072
5207
|
function BEZIER(x1: number, y1: number, x2: number, y2: number): (arg0: number) => number;
|
|
5073
5208
|
}
|
|
5209
|
+
/** Grid pathfinder using A* with two optional smoothing passes.
|
|
5210
|
+
* @memberof PathFinding
|
|
5211
|
+
* @example
|
|
5212
|
+
* // Tile-layer driven (most common):
|
|
5213
|
+
* const pf = new PathFinder(myTileCollisionLayer);
|
|
5214
|
+
* const path = pf.findPath(player.pos, mousePos);
|
|
5215
|
+
*
|
|
5216
|
+
* // Bare grid with custom walkability:
|
|
5217
|
+
* const pf = new PathFinder(vec2(50, 50));
|
|
5218
|
+
* pf.isWalkable = (x, y) => myGrid[y*50 + x] === 0;
|
|
5219
|
+
*/
|
|
5220
|
+
export class PathFinder {
|
|
5221
|
+
/** @param {TileCollisionLayer|Vector2} source - Either a TileCollisionLayer
|
|
5222
|
+
* (size and walkability auto-derived) or a Vector2 grid size (user
|
|
5223
|
+
* overrides isWalkable). */
|
|
5224
|
+
constructor(source: TileCollisionLayer | Vector2);
|
|
5225
|
+
size: any;
|
|
5226
|
+
tileLayer: Vector2 | TileCollisionLayer;
|
|
5227
|
+
heuristicWeight: number;
|
|
5228
|
+
maxLoop: number;
|
|
5229
|
+
smoothPath: boolean;
|
|
5230
|
+
debug: boolean;
|
|
5231
|
+
debugTime: number;
|
|
5232
|
+
nodes: any[];
|
|
5233
|
+
collisionScratch: Vector2;
|
|
5234
|
+
/** Default walkability: if a tile layer was provided, returns true when the
|
|
5235
|
+
* cell has no solid collision data; otherwise returns true. Override on
|
|
5236
|
+
* the instance or via a subclass.
|
|
5237
|
+
* @param {number} x - Tile x
|
|
5238
|
+
* @param {number} y - Tile y
|
|
5239
|
+
* @returns {boolean} */
|
|
5240
|
+
isWalkable(x: number, y: number): boolean;
|
|
5241
|
+
/** Default extra cost for stepping on a cell. Returns 0 (free) by default.
|
|
5242
|
+
* Override to add cost-weighted terrain (mud, swamp, etc).
|
|
5243
|
+
* @param {number} x - Tile x
|
|
5244
|
+
* @param {number} y - Tile y
|
|
5245
|
+
* @returns {number} */
|
|
5246
|
+
getCost(x: number, y: number): number;
|
|
5247
|
+
/** Get the node at tile coords, or null if out of bounds.
|
|
5248
|
+
* @param {number} x
|
|
5249
|
+
* @param {number} y
|
|
5250
|
+
* @returns {PathFinderNode|null} */
|
|
5251
|
+
getNode(x: number, y: number): PathFinderNode | null;
|
|
5252
|
+
/** Convert a world-space position to integer tile coords (no clamping).
|
|
5253
|
+
* @param {Vector2} worldPos
|
|
5254
|
+
* @returns {Vector2}
|
|
5255
|
+
* @memberof PathFinding */
|
|
5256
|
+
worldToTile(worldPos: Vector2): Vector2;
|
|
5257
|
+
/** Convert integer tile coords to the world-space center of that tile.
|
|
5258
|
+
* @param {number} x
|
|
5259
|
+
* @param {number} y
|
|
5260
|
+
* @returns {Vector2}
|
|
5261
|
+
* @memberof PathFinding */
|
|
5262
|
+
tileToWorld(x: number, y: number): Vector2;
|
|
5263
|
+
/** Reset all nodes and re-populate walkable / cost / posWorld from the
|
|
5264
|
+
* current isWalkable / getCost overrides. Called at the start of
|
|
5265
|
+
* findPath; exposed so tests and tooling can drive it directly.
|
|
5266
|
+
* @private */
|
|
5267
|
+
private buildNodeData;
|
|
5268
|
+
/** Core A* search loop. Expects buildNodeData() to have been called first.
|
|
5269
|
+
* Marks node.parent for path reconstruction. Returns true if endNode was
|
|
5270
|
+
* reached; false on disconnected goal or maxLoop exhaustion.
|
|
5271
|
+
* @param {PathFinderNode} startNode
|
|
5272
|
+
* @param {PathFinderNode} endNode
|
|
5273
|
+
* @returns {boolean}
|
|
5274
|
+
* @private */
|
|
5275
|
+
private aStarSearch;
|
|
5276
|
+
/** Find the clear (walkable, zero-cost) node closest to the given world
|
|
5277
|
+
* position. Spirals outward in expanding boxes until a clear node is
|
|
5278
|
+
* found or the search range is exhausted. Useful for snapping a click
|
|
5279
|
+
* or NPC spawn position to the nearest open tile.
|
|
5280
|
+
*
|
|
5281
|
+
* By default, calls `buildNodeData()` first so it works correctly on a
|
|
5282
|
+
* fresh PathFinder. If you're calling it many times in a row with
|
|
5283
|
+
* unchanged walkability, pass `rebuild=false` and call `buildNodeData()`
|
|
5284
|
+
* once externally to avoid redundant work.
|
|
5285
|
+
* @param {Vector2} worldPos
|
|
5286
|
+
* @param {number} [searchRange=10] - Max box-radius in tiles
|
|
5287
|
+
* @param {boolean} [rebuild=true] - Whether to call buildNodeData first
|
|
5288
|
+
* @returns {PathFinderNode|null}
|
|
5289
|
+
* @memberof PathFinding */
|
|
5290
|
+
getNearestClearNode(worldPos: Vector2, searchRange?: number, rebuild?: boolean): PathFinderNode | null;
|
|
5291
|
+
/** Smooth a node path by removing redundant turns and tightening corners
|
|
5292
|
+
* where a grid-aligned diagonal is clear. Modifies the path in place.
|
|
5293
|
+
* Stays on the grid — does not introduce off-tile-center points.
|
|
5294
|
+
* Port of ShortenPath() in pathFinding.cpp.
|
|
5295
|
+
* @param {PathFinderNode[]} path
|
|
5296
|
+
* @private */
|
|
5297
|
+
private smoothPathCorners;
|
|
5298
|
+
/** Smooth a node path via line-of-sight ("string pulling"). Walks the
|
|
5299
|
+
* input path collapsing runs of nodes into straight segments whenever
|
|
5300
|
+
* isLineClear permits, so the result can leave grid centers and cut
|
|
5301
|
+
* cleanly across open spaces.
|
|
5302
|
+
*
|
|
5303
|
+
* Bails (leaves the path unchanged) if any node has nonzero cost — a
|
|
5304
|
+
* straight geometric shortcut can't be trusted to be the lowest-cost
|
|
5305
|
+
* route when cost-weighted terrain is in play.
|
|
5306
|
+
*
|
|
5307
|
+
* Port of ShortenPath2() in pathFinding.cpp.
|
|
5308
|
+
* @param {PathFinderNode[]} path
|
|
5309
|
+
* @private */
|
|
5310
|
+
private smoothPathStringPull;
|
|
5311
|
+
/** Lookup helper: true when the node at tile coords (x, y) is in-bounds
|
|
5312
|
+
* and clear (walkable, zero-cost). Used by isLineClear's hot path.
|
|
5313
|
+
* @param {number} x
|
|
5314
|
+
* @param {number} y
|
|
5315
|
+
* @returns {boolean}
|
|
5316
|
+
* @private */
|
|
5317
|
+
private isNodeClear;
|
|
5318
|
+
/** Check that the line between two tile-coord endpoints stays entirely
|
|
5319
|
+
* inside walkable, zero-cost cells. Stricter than just sampling along
|
|
5320
|
+
* the line — it also checks the diagonal-corner-adjacent cells so the
|
|
5321
|
+
* line can never "scrape past" a wall corner.
|
|
5322
|
+
*
|
|
5323
|
+
* Both endpoints must themselves be clear (asserted in debug). Port of
|
|
5324
|
+
* CheckLine() in pathFinding.cpp.
|
|
5325
|
+
* @param {Vector2} startPos - Tile coords
|
|
5326
|
+
* @param {Vector2} endPos - Tile coords
|
|
5327
|
+
* @returns {boolean}
|
|
5328
|
+
* @private */
|
|
5329
|
+
private isLineClear;
|
|
5330
|
+
/** Find a path from startPos to endPos in world space. Returns an array
|
|
5331
|
+
* of world-space Vector2 points; empty array if no path exists.
|
|
5332
|
+
*
|
|
5333
|
+
* Start and end are snapped to the nearest walkable tile via
|
|
5334
|
+
* getNearestClearNode. Intermediate points are tile centers unless the
|
|
5335
|
+
* string-pulling smoothing pass moves them off-grid.
|
|
5336
|
+
* @param {Vector2} startPos - World-space start
|
|
5337
|
+
* @param {Vector2} endPos - World-space end
|
|
5338
|
+
* @returns {Vector2[]}
|
|
5339
|
+
* @memberof PathFinding */
|
|
5340
|
+
findPath(startPos: Vector2, endPos: Vector2): Vector2[];
|
|
5341
|
+
}
|
|
5342
|
+
/** A single grid cell tracked by the pathfinder. Allocated once per cell at
|
|
5343
|
+
* PathFinder construction; reset (not reallocated) at the start of every
|
|
5344
|
+
* findPath call.
|
|
5345
|
+
* @memberof PathFinding */
|
|
5346
|
+
export class PathFinderNode {
|
|
5347
|
+
/** @param {number} x - Tile x
|
|
5348
|
+
* @param {number} y - Tile y */
|
|
5349
|
+
constructor(x: number, y: number);
|
|
5350
|
+
/** @property {Vector2} - Tile coords (integer) */
|
|
5351
|
+
pos: Vector2;
|
|
5352
|
+
/** @property {Vector2} - World-space center of this tile (set by buildNodeData) */
|
|
5353
|
+
posWorld: Vector2;
|
|
5354
|
+
/** @property {boolean} - True if this cell is passable (cleared each findPath call) */
|
|
5355
|
+
walkable: boolean;
|
|
5356
|
+
/** @property {number} - Extra cost added to A* G-score for stepping on this cell */
|
|
5357
|
+
cost: number;
|
|
5358
|
+
/** @property {number} - A* G-score: actual cost from start to this node */
|
|
5359
|
+
g: number;
|
|
5360
|
+
/** @property {number} - A* F-score: G + heuristic */
|
|
5361
|
+
f: number;
|
|
5362
|
+
/** @property {PathFinderNode|null} - Parent for path reconstruction */
|
|
5363
|
+
parent: any;
|
|
5364
|
+
/** @property {boolean} - In the A* open list */
|
|
5365
|
+
isOpen: boolean;
|
|
5366
|
+
/** @property {boolean} - In the A* closed list */
|
|
5367
|
+
isClosed: boolean;
|
|
5368
|
+
/** Reset per-search state (called at the start of buildNodeData). */
|
|
5369
|
+
reset(): void;
|
|
5370
|
+
/** True if walkable and not blocked by cost. */
|
|
5371
|
+
isClear(): boolean;
|
|
5372
|
+
}
|
|
5074
5373
|
}
|