littlejsengine 1.21.0 → 1.23.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.
@@ -121,6 +121,32 @@ declare module "littlejsengine" {
121
121
  */
122
122
  renderPost?: () => void;
123
123
  };
124
+ /**
125
+ * The draw state's values, behind render3D's accessors, and the rgb emissiveMapColor had when it was set
126
+ */
127
+ export type Render3DDrawState = {
128
+ blend: boolean;
129
+ additive: boolean;
130
+ depthTest: boolean;
131
+ depthWrite: boolean;
132
+ cullBackFaces: boolean;
133
+ mirrored: boolean;
134
+ lighting: boolean;
135
+ emissive: number;
136
+ receiveShadow: boolean;
137
+ specular: number;
138
+ pixelated: boolean;
139
+ shader: Shader | undefined;
140
+ normalMap: TextureInfo | undefined;
141
+ normalScale: number;
142
+ shininess: number;
143
+ reflectivity: number;
144
+ emissiveMap: TextureInfo | undefined;
145
+ emissiveMapColor: Color;
146
+ emissiveR: number;
147
+ emissiveG: number;
148
+ emissiveB: number;
149
+ };
124
150
  /**
125
151
  * A particle as a ParticleEmitter3D's callbacks see it: one object the emitter reuses, set from the particle for each
126
152
  * call and written back after it, so copy what you keep
@@ -146,6 +172,11 @@ declare module "littlejsengine" {
146
172
  * - Seconds it lives
147
173
  */
148
174
  lifeTime: number;
175
+ /**
176
+ * - How much the emitter grows its effect, from its scale3D and its parents', as the 2D
177
+ * particle's scale
178
+ */
179
+ scale: number;
149
180
  /**
150
181
  * - Set by destroy
151
182
  */
@@ -185,6 +216,200 @@ declare module "littlejsengine" {
185
216
  * - What the game does when the level editor paints a tile
186
217
  */
187
218
  export type EditorTileCallback = (layer: TileLayer, pos: Vector2, tile: number | undefined) => any;
219
+ /**
220
+ * - What the level editor gives the callbacks of a tool of the game's own
221
+ */
222
+ export type EditorToolAt = {
223
+ /**
224
+ * - Where the mouse is in the level: a Vector2 in the 2D editor; in the 3D one a Vector3 on
225
+ * the level or the ground, undefined when the mouse is over the panel
226
+ */
227
+ pos: any;
228
+ /**
229
+ * - 2D: the tile cell under the mouse on the selected tile layer
230
+ */
231
+ cell: Vector2 | undefined;
232
+ /**
233
+ * - 3D: the mouse's Ray3D
234
+ */
235
+ ray: any;
236
+ /**
237
+ * - Is Shift held
238
+ */
239
+ shift: boolean;
240
+ /**
241
+ * - Is Ctrl held
242
+ */
243
+ ctrl: boolean;
244
+ };
245
+ /**
246
+ * - A tool of the game's own for the level editor, see LevelEditor.addTool
247
+ */
248
+ export type EditorTool = {
249
+ /**
250
+ * - The key that picks it, as addKey spells one
251
+ */
252
+ key?: string;
253
+ /**
254
+ * - The hint line while it is on
255
+ */
256
+ hint?: string;
257
+ /**
258
+ * - The left button went down in the level; returning false
259
+ * says the press was not the tool's
260
+ */
261
+ onPress?: (arg0: EditorToolAt) => any;
262
+ /**
263
+ * - Each frame it is held
264
+ */
265
+ onDrag?: (arg0: EditorToolAt) => any;
266
+ /**
267
+ * - It was let go
268
+ */
269
+ onRelease?: (arg0: EditorToolAt) => any;
270
+ /**
271
+ * - Each frame the tool is on, to draw its cursor or preview
272
+ */
273
+ onDraw?: (arg0: EditorToolAt) => any;
274
+ };
275
+ /**
276
+ * - The 2D level editor's edit functions, levelEditor.edit2D
277
+ */
278
+ export type EditorEdit2D = {
279
+ /**
280
+ * - The Tiled map of the selected layer
281
+ */
282
+ map: any | undefined;
283
+ /**
284
+ * - The selected tile layer, undefined on an object layer
285
+ */
286
+ layer: TileLayer | undefined;
287
+ /**
288
+ * - A copy of the selected object layer's objects, as Tiled has them
289
+ */
290
+ objects: Array<any>;
291
+ /**
292
+ * - The cell under the mouse on the selected tile layer
293
+ */
294
+ hover: Vector2 | undefined;
295
+ /**
296
+ * - The selected objects' ids
297
+ */
298
+ selection: Set<number>;
299
+ /**
300
+ * - Set a cell of the selected tile layer
301
+ * to a tile index, -1 erases, with a direction 0 to 3 and a mirror; false off the layer or with none
302
+ */
303
+ paint: (arg0: Vector2, arg1: number, ...args: any[]) => boolean;
304
+ /**
305
+ * - Edit a copy of the selected object
306
+ * layer's objects; false when nothing changed
307
+ */
308
+ changeObjects: (arg0: (arg0: Array<any>) => void) => boolean;
309
+ /**
310
+ * - End the edit: one undo step, and the autosave
311
+ */
312
+ strokeEnd: () => void;
313
+ /**
314
+ * - Take the edit being made back
315
+ */
316
+ strokeCancel: () => void;
317
+ /**
318
+ * - Many paints with one redraw a layer
319
+ */
320
+ bulk: (arg0: () => void) => void;
321
+ /**
322
+ * - Undo, or redo with true
323
+ */
324
+ undo: (...args: any[]) => any;
325
+ /**
326
+ * - The map as the text Save writes
327
+ */
328
+ toJSON: () => string;
329
+ };
330
+ /**
331
+ * - The 3D level editor's edit functions, levelEditor.edit3D; a position, a
332
+ * rotation and a scale are Vector3, the rotation in degrees
333
+ */
334
+ export type EditorEdit3D = {
335
+ /**
336
+ * - The level object being edited
337
+ */
338
+ level: any | undefined;
339
+ /**
340
+ * - Its objects, the list in the level: read it, edit through change
341
+ */
342
+ objects: Array<any>;
343
+ /**
344
+ * - The selected objects' ids
345
+ */
346
+ selection: Set<number>;
347
+ /**
348
+ * - The selected objects
349
+ */
350
+ selected: () => Array<any>;
351
+ /**
352
+ * - What the game made for an object's id
353
+ */
354
+ made: (arg0: number) => any;
355
+ /**
356
+ * - Edit a copy of the object list; false
357
+ * when nothing changed
358
+ */
359
+ change: (arg0: (arg0: Array<any>) => void) => boolean;
360
+ /**
361
+ * - Edit the level's scene, voxels, terrain
362
+ * or prefabs block
363
+ */
364
+ changePart: (arg0: string, arg1: (arg0: any) => any) => boolean;
365
+ /**
366
+ * - End the edit: one undo step, and the autosave
367
+ */
368
+ strokeEnd: () => void;
369
+ /**
370
+ * - Take the edit being made back
371
+ */
372
+ strokeCancel: () => void;
373
+ /**
374
+ * - Add an object of a type at a position, selected;
375
+ * its id, undefined when there is no such type or the level can not be edited
376
+ */
377
+ place: (arg0: string, arg1: any) => number | undefined;
378
+ /**
379
+ * - Write a place, a rotation and a scale on an
380
+ * object of the list given to change; one left out is kept
381
+ */
382
+ setTransform: (arg0: any, ...args: any[]) => void;
383
+ /**
384
+ * - Write a property on an object of the list given
385
+ * to change, left out of the file when it is the type's default
386
+ */
387
+ setProperty: (arg0: any, arg1: string, arg2: any) => void;
388
+ /**
389
+ * - An object's position
390
+ */
391
+ pos: (arg0: any) => any;
392
+ /**
393
+ * - Its rotation, in degrees
394
+ */
395
+ rotation: (arg0: any) => any;
396
+ /**
397
+ * - Its scale
398
+ */
399
+ scale: (arg0: any) => any;
400
+ /**
401
+ * - Where the mouse is on the level or the ground, undefined over the panel
402
+ */
403
+ mousePoint: () => any;
404
+ /**
405
+ * - Undo, or redo with true
406
+ */
407
+ undo: (...args: any[]) => boolean;
408
+ /**
409
+ * - The level as the text Save writes
410
+ */
411
+ toJSON: () => string;
412
+ };
188
413
  /**
189
414
  * LittleJS - The Tiny Fast JavaScript Game Engine
190
415
  * MIT License - Copyright 2021 Frank Force
@@ -422,7 +647,234 @@ declare module "littlejsengine" {
422
647
  /** The level editor, levelEditor.open() to edit the level, levelEditor.close() to play on with the changes
423
648
  * @type {LevelEditor}
424
649
  * @memberof Editor */
425
- export const levelEditor: LevelEditor;
650
+ export let levelEditor: LevelEditor;
651
+ /**
652
+ * LittleJS Level Editor
653
+ * - Paint the game's tile layers while it is paused, then keep playing with the changes
654
+ * - Press 0 while the debug overlay is open to edit, 0 again to play, or call levelEditor.open() and close()
655
+ * - Edits the Tiled map the game loaded, saves it back as Tiled JSON, and autosaves every change
656
+ * - Debug builds only, the release build has stubs for its names in engineRelease.js and none of its code
657
+ * @namespace Editor
658
+ */
659
+ /**
660
+ * @callback EditorPlayFromCallback - Puts the player at a world position, for the level editor's Play from mouse
661
+ * @param {Vector2} pos - Where to start playing
662
+ * @memberof Editor
663
+ */
664
+ /**
665
+ * @callback EditorRestartCallback - Rebuilds the level from the map the level editor changed
666
+ * @memberof Editor
667
+ */
668
+ /**
669
+ * @callback EditorTileCallback - What the game does when the level editor paints a tile
670
+ * @param {TileLayer} layer - The layer painted
671
+ * @param {Vector2} pos - The cell's position in the layer
672
+ * @param {number|undefined} tile - The tile painted, undefined when erased
673
+ * @memberof Editor
674
+ */
675
+ /**
676
+ * @typedef {Object} EditorToolAt - What the level editor gives the callbacks of a tool of the game's own
677
+ * @property {any} pos - Where the mouse is in the level: a Vector2 in the 2D editor; in the 3D one a Vector3 on
678
+ * the level or the ground, undefined when the mouse is over the panel
679
+ * @property {Vector2|undefined} cell - 2D: the tile cell under the mouse on the selected tile layer
680
+ * @property {any} ray - 3D: the mouse's Ray3D
681
+ * @property {boolean} shift - Is Shift held
682
+ * @property {boolean} ctrl - Is Ctrl held
683
+ * @memberof Editor
684
+ */
685
+ /**
686
+ * @typedef {Object} EditorTool - A tool of the game's own for the level editor, see LevelEditor.addTool
687
+ * @property {string} [key] - The key that picks it, as addKey spells one
688
+ * @property {string} [hint] - The hint line while it is on
689
+ * @property {function(EditorToolAt): any} [onPress] - The left button went down in the level; returning false
690
+ * says the press was not the tool's
691
+ * @property {function(EditorToolAt): any} [onDrag] - Each frame it is held
692
+ * @property {function(EditorToolAt): any} [onRelease] - It was let go
693
+ * @property {function(EditorToolAt): any} [onDraw] - Each frame the tool is on, to draw its cursor or preview
694
+ * @memberof Editor
695
+ */
696
+ /**
697
+ * @typedef {Object} EditorEdit2D - The 2D level editor's edit functions, levelEditor.edit2D
698
+ * @property {Object|undefined} map - The Tiled map of the selected layer
699
+ * @property {TileLayer|undefined} layer - The selected tile layer, undefined on an object layer
700
+ * @property {Array<Object>} objects - A copy of the selected object layer's objects, as Tiled has them
701
+ * @property {Vector2|undefined} hover - The cell under the mouse on the selected tile layer
702
+ * @property {Set<number>} selection - The selected objects' ids
703
+ * @property {function(Vector2, number, ...any): boolean} paint - Set a cell of the selected tile layer
704
+ * to a tile index, -1 erases, with a direction 0 to 3 and a mirror; false off the layer or with none
705
+ * @property {function(function(Array<Object>): void): boolean} changeObjects - Edit a copy of the selected object
706
+ * layer's objects; false when nothing changed
707
+ * @property {function(): void} strokeEnd - End the edit: one undo step, and the autosave
708
+ * @property {function(): void} strokeCancel - Take the edit being made back
709
+ * @property {function(function(): void): void} bulk - Many paints with one redraw a layer
710
+ * @property {function(...any): any} undo - Undo, or redo with true
711
+ * @property {function(): string} toJSON - The map as the text Save writes
712
+ * @memberof Editor
713
+ */
714
+ /**
715
+ * @typedef {Object} EditorEdit3D - The 3D level editor's edit functions, levelEditor.edit3D; a position, a
716
+ * rotation and a scale are Vector3, the rotation in degrees
717
+ * @property {Object|undefined} level - The level object being edited
718
+ * @property {Array<Object>} objects - Its objects, the list in the level: read it, edit through change
719
+ * @property {Set<number>} selection - The selected objects' ids
720
+ * @property {function(): Array<Object>} selected - The selected objects
721
+ * @property {function(number): any} made - What the game made for an object's id
722
+ * @property {function(function(Array<Object>): void): boolean} change - Edit a copy of the object list; false
723
+ * when nothing changed
724
+ * @property {function(string, function(any): any): boolean} changePart - Edit the level's scene, voxels, terrain
725
+ * or prefabs block
726
+ * @property {function(): void} strokeEnd - End the edit: one undo step, and the autosave
727
+ * @property {function(): void} strokeCancel - Take the edit being made back
728
+ * @property {function(string, any): number|undefined} place - Add an object of a type at a position, selected;
729
+ * its id, undefined when there is no such type or the level can not be edited
730
+ * @property {function(Object, ...any): void} setTransform - Write a place, a rotation and a scale on an
731
+ * object of the list given to change; one left out is kept
732
+ * @property {function(Object, string, any): void} setProperty - Write a property on an object of the list given
733
+ * to change, left out of the file when it is the type's default
734
+ * @property {function(Object): any} pos - An object's position
735
+ * @property {function(Object): any} rotation - Its rotation, in degrees
736
+ * @property {function(Object): any} scale - Its scale
737
+ * @property {function(): any} mousePoint - Where the mouse is on the level or the ground, undefined over the panel
738
+ * @property {function(...any): boolean} undo - Undo, or redo with true
739
+ * @property {function(): string} toJSON - The level as the text Save writes
740
+ * @memberof Editor
741
+ */
742
+ /**
743
+ * The level editor, open it to pause the game and edit its level, close it to play on with the changes
744
+ * - One of it, levelEditor, 0 on the debug overlay opens and closes it too
745
+ * - A game makes it its own: it sets the hooks, adds keys, panel buttons and tools, or extends this class and
746
+ * gives its own with setLevelEditor; the same calls work in the 2D editor and the 3D one, see EDITOR.md
747
+ * - In release builds LevelEditor is a stub that never opens: what a game adds is taken and never called
748
+ * @memberof Editor
749
+ * @example
750
+ * levelEditor.onRestart = ()=> loadLevel(); // adds a Restart button that rebuilds the level
751
+ * levelEditor.onTile = (layer, pos, tile)=> layer.setCollisionData(pos, tile === ladderTile ? -1 : tile ? 1 : 0);
752
+ * levelEditor.addKey('k', ()=> clearEnemies(), 'K: clear the enemies');
753
+ *
754
+ * // or as a class of the game's own
755
+ * class MyEditor extends LevelEditor
756
+ * {
757
+ * onRestart() { loadLevel(); }
758
+ * onDraw() { drawSpawnZones(); }
759
+ * }
760
+ * setLevelEditor(new MyEditor);
761
+ */
762
+ export class LevelEditor {
763
+ /** @property {Array<number>|undefined} - The tiles the palette shows, in its order, for a sheet that also holds
764
+ * sprites and art that are not level tiles; undefined shows every tile of the sheet
765
+ * @type {Array<number>|undefined} */
766
+ paletteTiles: Array<number> | undefined;
767
+ /** @property {boolean|undefined} - Which level editor opens: true the 3D one, false the 2D one, undefined the
768
+ * 3D one when a level was loaded with level3DLoad and there is a Render3DPlugin
769
+ * @type {boolean|undefined} */
770
+ use3D: boolean | undefined;
771
+ /** @property {string|undefined} - The tool of the game's own that is on, one added with addTool, undefined
772
+ * while a tool of the editor's is
773
+ * @type {string|undefined} */
774
+ tool: string | undefined;
775
+ /** @type {Object<string, {action: function(boolean): any, help: string|undefined, warned: boolean}>} */
776
+ keys: {
777
+ [x: string]: {
778
+ action: (arg0: boolean) => any;
779
+ help: string | undefined;
780
+ warned: boolean;
781
+ };
782
+ };
783
+ /** @type {Array<{label: string, onClick: Function, title: string}>} */
784
+ buttons: Array<{
785
+ label: string;
786
+ onClick: Function;
787
+ title: string;
788
+ }>;
789
+ /** @type {Object<string, EditorTool>} */
790
+ tools: {
791
+ [x: string]: EditorTool;
792
+ };
793
+ /** What the game does when the 2D editor paints a tile, like setting its collision or its look the way the
794
+ * game does when it loads the level; set it or override it, without one the collision layer gets collision 1
795
+ * where there is a tile
796
+ * @param {TileLayer} layer - The layer painted
797
+ * @param {Vector2} pos - The cell's position in the layer
798
+ * @param {number|undefined} tile - The tile painted, undefined when erased */
799
+ onTile(layer: TileLayer, pos: Vector2, tile: number | undefined): void;
800
+ /** Rebuild the level from what the editor changed; set it or override it and the editor has a Restart button,
801
+ * which calls it after switching to play */
802
+ onRestart(): void;
803
+ /** Put the player at a position, a Vector2 in the 2D editor and a Vector3 in the 3D one; set it or override it
804
+ * and the editor has Play from mouse, which starts play there
805
+ * @param {any} pos */
806
+ onPlayFrom(pos: any): void;
807
+ /** Called when the editor opens, to set or override */
808
+ onOpen(): void;
809
+ /** Called when the editor closes and the game plays on, to set or override */
810
+ onClose(): void;
811
+ /** Called each frame while the editor is open, to set or override */
812
+ onUpdate(): void;
813
+ /** Called while the editor draws the level, to draw overlays of the game's own in it, to set or override */
814
+ onDraw(): void;
815
+ /** Called once when the editor's panel is made, with a box in it for the game's own controls, to set or override
816
+ * @param {HTMLElement} element */
817
+ onPanel(element: HTMLElement): void;
818
+ /** Called by Save with the text of the file and its name; return true when the game kept it itself, and the
819
+ * editor writes no file, to set or override
820
+ * @param {string} text
821
+ * @param {string} fileName
822
+ * @return {boolean|void} */
823
+ onSave(text: string, fileName: string): boolean | void;
824
+ /** True while the editor is open, the game is paused under it
825
+ * @return {boolean} */
826
+ get isOpen(): boolean;
827
+ /** True when the editor in use is the 3D one, as use3D says or since a 3D level was loaded
828
+ * @return {boolean} */
829
+ get is3D(): boolean;
830
+ /** The 2D editor's edit functions, for a key, a button or a tool of the game's own: map, the Tiled map; layer,
831
+ * the selected TileLayer; objects, a copy of the selected object layer's; hover, the cell under the mouse;
832
+ * selection, the selected objects' ids; paint(cell, tile, direction, mirror), a tile index, -1 erases;
833
+ * changeObjects((list)=> ...); strokeEnd() and strokeCancel(); bulk(()=> ...); undo(redo); toJSON()
834
+ * @return {EditorEdit2D} */
835
+ get edit2D(): EditorEdit2D;
836
+ /** The 3D editor's edit functions, undefined without the 3D plugins: level; objects; selection, a Set of ids;
837
+ * selected(); made(id); change((list)=> ...); changePart(name, (part)=> ...); strokeEnd() and strokeCancel();
838
+ * place(type, pos3D); setTransform(object, pos3D, rotationDegrees, scale3D); setProperty(object, name, value);
839
+ * pos(object), rotation(object) and scale(object); mousePoint(); undo(redo); toJSON()
840
+ * @return {EditorEdit3D|undefined} */
841
+ get edit3D(): EditorEdit3D;
842
+ /** Add a key of the game's own to the editor, the 2D and the 3D one
843
+ * - Escape and 0 are the editor's own, to play and to exit, and Ctrl is the one modifier: Shift is given to
844
+ * the action
845
+ * @param {string} key - A letter or digit, 'k', or a key's name in any case, 'Delete', 'F2', 'Enter', 'Space';
846
+ * 'ctrl+k' with Ctrl or Cmd
847
+ * @param {function(boolean): any} action - Called with whether Shift is held; returning false says it did
848
+ * nothing, and the key is left to the browser
849
+ * @param {string} [helpLine] - A line for the editor's help */
850
+ addKey(key: string, action: (arg0: boolean) => any, helpLine?: string): void;
851
+ /** Add a button of the game's own to the editor's panel
852
+ * @param {string} label
853
+ * @param {Function} onClick
854
+ * @param {string} [title] - What it says when the mouse is over it */
855
+ addButton(label: string, onClick: Function, title?: string): void;
856
+ /** Add a tool of the game's own: a button in the panel by its name, and while it is on the left button in the
857
+ * level is its, not the editor's own tools'
858
+ * - Each callback is given {pos, cell, ray, shift, ctrl}: pos is where the mouse is in the level, a Vector2 in
859
+ * 2D and a Vector3 on the level or the ground in 3D; cell is the tile under it in 2D; ray is the mouse's
860
+ * in 3D
861
+ * - What the callbacks change through edit2D or edit3D is one undo: the editor ends the stroke at the release,
862
+ * and takes it back when the right button or Escape ends the press
863
+ * @param {string} name
864
+ * @param {EditorTool} tool - {key, hint, onPress, onDrag, onRelease, onDraw}, each optional; onPress returning
865
+ * false says the press was not the tool's */
866
+ addTool(name: string, tool: EditorTool): void;
867
+ /** Open the editor, pausing the game; until close(), Escape (the debug key) switches between playing and editing */
868
+ open(): any;
869
+ /** Close the editor and end its session, the game carries on with the changes and Escape opens the debug
870
+ * overlay again */
871
+ close(): any;
872
+ }
873
+ /** Make a level editor of the game's own the one in use: an instance of a class that extends LevelEditor, with
874
+ * the game's hooks as its methods; set it before the editor opens
875
+ * @param {LevelEditor} editor
876
+ * @memberof Editor */
877
+ export function setLevelEditor(editor: LevelEditor): void;
426
878
  /** Asserts if the expression is false, does nothing in release builds
427
879
  * Halts execution if the assert fails and throws an error
428
880
  * @param {*} assert - any value, the assert fails when it is falsy
@@ -775,6 +1227,14 @@ declare module "littlejsengine" {
775
1227
  * @default
776
1228
  * @memberof Settings */
777
1229
  export let touchGamepadPassthrough: boolean;
1230
+ /** True if a pinch of two fingers turns the mouse wheel: touchPinch is added to mouseWheel, so what zooms with
1231
+ * the wheel zooms with a pinch, the mouse is between the two fingers, and a second finger lets go of the button
1232
+ * the first pressed, since a pinch is not a drag; turn it off for a game with its own use for two fingers, the
1233
+ * first finger stays the mouse and touchPinch can still be read
1234
+ * @type {boolean}
1235
+ * @default
1236
+ * @memberof Settings */
1237
+ export let touchPinchWheel: boolean;
778
1238
  /** Size of center button if touch gamepad should have start button in the center
779
1239
  * - Prevents activating when pressed near virtual stick or face buttons
780
1240
  * - When the game is paused, any touch will press the button
@@ -1065,6 +1525,10 @@ declare module "littlejsengine" {
1065
1525
  * @param {boolean} passthrough
1066
1526
  * @memberof Settings */
1067
1527
  export function setTouchGamepadPassthrough(passthrough: boolean): void;
1528
+ /** Set if a pinch of two fingers turns the mouse wheel
1529
+ * @param {boolean} enable
1530
+ * @memberof Settings */
1531
+ export function setTouchPinchWheel(enable: boolean): void;
1068
1532
  /** Set if touch gamepad should have start button in the center
1069
1533
  * - Set size to enable the center button
1070
1534
  * - When the game is paused, any touch will press the button
@@ -2086,8 +2550,9 @@ declare module "littlejsengine" {
2086
2550
  * @param {boolean} [useWebGL] - Should use WebGL if available?
2087
2551
  * @param {boolean|Array<number>} [wrap] - Should the texture wrap (REPEAT) or clamp (CLAMP_TO_EDGE)? Or the WebGL
2088
2552
  * modes across and down, like [gl.CLAMP_TO_EDGE, gl.MIRRORED_REPEAT], as a glTF sampler gives them
2553
+ * @param {boolean} [pixelated] - Hard edged or smooth for this texture alone, undefined follows tilesPixelated
2089
2554
  */
2090
- constructor(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, useWebGL?: boolean, wrap?: boolean | Array<number>);
2555
+ constructor(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, useWebGL?: boolean, wrap?: boolean | Array<number>, pixelated?: boolean);
2091
2556
  /** @property {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} - image source */
2092
2557
  image: OffscreenCanvas | ImageBitmap | HTMLCanvasElement | HTMLImageElement;
2093
2558
  /** @property {Vector2} - size of the image */
@@ -2101,6 +2566,10 @@ declare module "littlejsengine" {
2101
2566
  * across and down
2102
2567
  * @type {boolean|Array<number>} */
2103
2568
  wrap: boolean | Array<number>;
2569
+ /** @property {boolean|undefined} - Hard edged or smooth for this texture alone, a soft glow in a pixel art
2570
+ * game or pixel art in a smooth one; undefined follows tilesPixelated
2571
+ * @type {boolean|undefined} */
2572
+ pixelated: boolean | undefined;
2104
2573
  /** Creates the WebGL texture, updates if already created */
2105
2574
  createWebGLTexture(): void;
2106
2575
  /** Destroys the WebGL texture */
@@ -2112,6 +2581,10 @@ declare module "littlejsengine" {
2112
2581
  * @param {boolean|Array<number>} [wrap] - true for REPEAT, false for CLAMP_TO_EDGE, or the WebGL modes across
2113
2582
  * and down */
2114
2583
  setWrap(wrap?: boolean | Array<number>): void;
2584
+ /** Make this texture hard edged or smooth on its own, whatever tilesPixelated says for the rest; it is made again
2585
+ * with the new filtering
2586
+ * @param {boolean} [pixelated] - undefined follows tilesPixelated again */
2587
+ setPixelated(pixelated?: boolean): void;
2115
2588
  }
2116
2589
  /** Load a texture at a specific index after engineInit, the images passed to engineInit load this way
2117
2590
  * @param {number} textureIndex - Index to store the texture at, an unused one
@@ -2227,6 +2700,11 @@ declare module "littlejsengine" {
2227
2700
  /** The clip showing now
2228
2701
  * @return {SpriteAnimation} */
2229
2702
  get clip(): SpriteAnimation;
2703
+ /** The clip showing now, once a clip that has ended has called its onEnd: the callback may switch clips, and a
2704
+ * read gives the clip it switched to, not the one that ended
2705
+ * @return {SpriteAnimation}
2706
+ * @ignore */
2707
+ get settledClip(): SpriteAnimation;
2230
2708
  /** The tile of the frame showing now
2231
2709
  * @return {TileInfo} */
2232
2710
  get tileInfo(): TileInfo;
@@ -2759,9 +3237,10 @@ declare module "littlejsengine" {
2759
3237
  * Restores the active texture when done
2760
3238
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} [image]
2761
3239
  * @param {boolean|Array<number>} [wrap] - true for REPEAT, false for CLAMP_TO_EDGE, or the WebGL modes across and down
3240
+ * @param {boolean} [pixelated] - Hard edged or smooth, undefined follows tilesPixelated
2762
3241
  * @return {WebGLTexture}
2763
3242
  * @memberof WebGL */
2764
- export function glCreateTexture(image?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, wrap?: boolean | Array<number>): WebGLTexture;
3243
+ export function glCreateTexture(image?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, wrap?: boolean | Array<number>, pixelated?: boolean): WebGLTexture;
2765
3244
  /** Deletes a WebGL texture
2766
3245
  * @param {WebGLTexture} [texture]
2767
3246
  * @memberof WebGL */
@@ -2769,8 +3248,9 @@ declare module "littlejsengine" {
2769
3248
  /** Set WebGL texture data from an image, restores the active texture when done
2770
3249
  * @param {WebGLTexture} texture
2771
3250
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image
3251
+ * @param {boolean} [pixelated] - Hard edged or smooth, undefined follows tilesPixelated
2772
3252
  * @memberof WebGL */
2773
- export function glSetTextureData(texture: WebGLTexture, image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap): void;
3253
+ export function glSetTextureData(texture: WebGLTexture, image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, pixelated?: boolean): void;
2774
3254
  /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
2775
3255
  * @memberof WebGL */
2776
3256
  export function glFlush(): void;
@@ -2783,6 +3263,17 @@ declare module "littlejsengine" {
2783
3263
  * @param {boolean} [antialias]
2784
3264
  * @memberof WebGL */
2785
3265
  export function glSetAntialias(antialias?: boolean): void;
3266
+ /** The largest texture this device makes, in pixels across, 0 until WebGL starts; at least 2048 with WebGL2
3267
+ * @type {number}
3268
+ * @memberof WebGL */
3269
+ export let glMaxTextureSize: number;
3270
+ /** A texture size this device can make: the size asked for, or the largest it supports when that is smaller
3271
+ * - The engine sizes the textures it makes itself through this, the shadow maps and the like, so a size a device
3272
+ * does not have falls back instead of failing
3273
+ * @param {number} size - Pixels across
3274
+ * @return {number}
3275
+ * @memberof WebGL */
3276
+ export function glClampTextureSize(size: number): number;
2786
3277
  /** Add a sprite to the gl draw list, used by all gl draw functions
2787
3278
  * @param {number} x
2788
3279
  * @param {number} y
@@ -2945,6 +3436,12 @@ declare module "littlejsengine" {
2945
3436
  * @type {number}
2946
3437
  * @memberof Input */
2947
3438
  export let mouseWheel: number;
3439
+ /** Touch pinch delta this frame, in the mouse wheel's units: two fingers moving apart are negative, as the wheel
3440
+ * turned up is, and moving together positive, 1 for every 50 pixels; added to mouseWheel while touchPinchWheel
3441
+ * is on, so a game that zooms with the wheel zooms with a pinch
3442
+ * @type {number}
3443
+ * @memberof Input */
3444
+ export let touchPinch: number;
2948
3445
  /** True if mouse was inside the document window, set to false when mouse leaves
2949
3446
  * @type {boolean}
2950
3447
  * @memberof Input */
@@ -3150,8 +3647,13 @@ declare module "littlejsengine" {
3150
3647
  * @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
3151
3648
  */
3152
3649
  constructor(asset?: string | URL | any[], randomness?: number, range?: number, taper?: number, onloadCallback?: SoundLoadCallback);
3153
- /** @property {number} - World space max range of sound */
3154
- range: number;
3650
+ set range(arg: number);
3651
+ /** World space max range of sound, 0 for no limit; a range that is set is the sound's own, in 3D too
3652
+ * @type {number} */
3653
+ get range(): number;
3654
+ /** @property {boolean} - No range was given, so it got soundDefaultRange; played in 3D such a sound is heard
3655
+ * to render3D.soundDefaultRange instead, which is further; setting range makes it false */
3656
+ rangeIsDefault: boolean;
3155
3657
  /** @property {number} - At what percentage of range should it start tapering */
3156
3658
  taper: number;
3157
3659
  /** @property {number} - How much to randomize frequency each time sound plays
@@ -3185,6 +3687,7 @@ declare module "littlejsengine" {
3185
3687
  * playing a sound detaches the buffer's own channel arrays.
3186
3688
  * @return {Array<Array<number>|Float32Array>|undefined} */
3187
3689
  get sampleChannels(): (number[] | Float32Array)[];
3690
+ rangeValue: number;
3188
3691
  /** Move this sound's samples into an audio buffer that every play can share
3189
3692
  * Does nothing if there is already a buffer or no samples to build one from */
3190
3693
  buildSampleBuffer(): void;
@@ -3435,9 +3938,9 @@ declare module "littlejsengine" {
3435
3938
  * @param {number} [decay] - Decay time, how long to reach sustain after attack (seconds)
3436
3939
  * @param {number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
3437
3940
  * @param {number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
3438
- * @return {Array} - Array of audio samples
3941
+ * @return {Float32Array} - The audio samples
3439
3942
  * @memberof Audio */
3440
- export function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number, filter?: number): any[];
3943
+ export function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number, filter?: number): Float32Array;
3441
3944
  /**
3442
3945
  * LittleJS Object System
3443
3946
  * - EngineObject is the base class for all game objects
@@ -4119,6 +4622,13 @@ declare module "littlejsengine" {
4119
4622
  localSpace: boolean;
4120
4623
  /** @property {number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
4121
4624
  trailScale: number;
4625
+ /** @property {number} - Grows the whole effect as each particle is born: the spawn area, the particles' sizes,
4626
+ * speed and fall, so it looks the same only bigger; 1 is as made, and a particle keeps the scale it was born
4627
+ * with, so a change never moves the ones already out */
4628
+ scale: number;
4629
+ /** @property {number} - The effect's own fall, added to each particle's velocity y every frame, on top of the
4630
+ * world's gravity times gravityScale; an effect that sets its own looks the same in any game */
4631
+ gravity: number;
4122
4632
  /** @property {ParticleCallback|undefined} - Callback when particle is created
4123
4633
  * @type {ParticleCallback|undefined} */
4124
4634
  particleCreateCallback: ParticleCallback | undefined;
@@ -4169,6 +4679,8 @@ declare module "littlejsengine" {
4169
4679
  constructor(emitter: ParticleEmitter, pos: Vector2, angle: number, colorStart: Color, colorEnd: Color, lifeTime: number, sizeStart: number, sizeEnd: number, velocity?: Vector2, angleVelocity?: number);
4170
4680
  /** @property {ParticleEmitter} - The emitter this particle came from */
4171
4681
  emitter: ParticleEmitter;
4682
+ /** @property {number} - The emitter's scale when it was made, which grows its fall */
4683
+ scale: number;
4172
4684
  /** @property {Vector2} - Position, world space or local to the emitter when localSpace is set */
4173
4685
  pos: Vector2;
4174
4686
  /** @property {number} - Angle in radians */
@@ -4487,6 +4999,8 @@ declare module "littlejsengine" {
4487
4999
  * new PostProcessPlugin(shaderCode);
4488
5000
  */
4489
5001
  constructor(shaderCode?: string, includeMainCanvas?: boolean, feedbackTexture?: boolean);
5002
+ /** @property {string} - The shadertoy style mainImage code it shades with, see setShaderCode */
5003
+ shaderCode: string;
4490
5004
  /** @property {WebGLProgram|undefined} - Shader for post processing
4491
5005
  * @type {WebGLProgram|undefined} */
4492
5006
  shader: WebGLProgram | undefined;
@@ -4499,6 +5013,10 @@ declare module "littlejsengine" {
4499
5013
  /** @property {WebGLVertexArrayObject|undefined} - Vertex array object
4500
5014
  * @type {WebGLVertexArrayObject|undefined} */
4501
5015
  vao: WebGLVertexArrayObject | undefined;
5016
+ /** Shade with new code from the next frame on, to switch effects while the game runs; the shader is made again
5017
+ * @param {string} [shaderCode] - Shadertoy style mainImage code, postProcessEffects builds it; none passes the
5018
+ * frame through */
5019
+ setShaderCode(shaderCode?: string): void;
4502
5020
  }
4503
5021
  /**
4504
5022
  * Set up post processing with a bloom effect, so bright colors and lights glow
@@ -4523,6 +5041,98 @@ declare module "littlejsengine" {
4523
5041
  * @memberof PostProcess
4524
5042
  */
4525
5043
  export function postProcessBloomShader(threshold?: number, strength?: number, size?: number): string;
5044
+ /**
5045
+ * Join effects into one post process shader, in the order given, for PostProcessPlugin or setShaderCode
5046
+ * - Each effect is a piece of shader code on c, the pixel's color, and uv, where it is on the screen from 0 to 1;
5047
+ * your own code is a piece too, a line of GLSL or many, dropped in where you put it
5048
+ * - Put the ones that bend the picture or sample it first: postProcessCurve, postProcessChromatic, postProcessGlow
5049
+ * @param {...string} effects - The pieces, from the effect functions or your own code
5050
+ * @return {string} - Shadertoy style mainImage code
5051
+ * @example
5052
+ * new PostProcessPlugin(postProcessEffects(
5053
+ * postProcessScanlines(.5), postProcessVignette(), 'c.rgb *= vec3(1, .9, .8);'));
5054
+ * @memberof PostProcess
5055
+ */
5056
+ export function postProcessEffects(...effects: string[]): string;
5057
+ /**
5058
+ * Bright parts glow, the bloom as an effect to join with others; postProcessBloom sets up bloom on its own
5059
+ * @param {number} [threshold] - Brightness where the glow starts, 0 is everything and 1 is only pure white
5060
+ * @param {number} [strength] - How much glow to add
5061
+ * @param {number} [size] - How far the glow spreads in pixels, which also sets how many samples it takes
5062
+ * @return {string}
5063
+ * @memberof PostProcess
5064
+ */
5065
+ export function postProcessGlow(threshold?: number, strength?: number, size?: number): string;
5066
+ /**
5067
+ * Scan lines across the screen, like an old TV
5068
+ * @param {number} [strength] - How dark the lines are, and how bright between them
5069
+ * @param {number} [spacing] - Pixels from one line to the next
5070
+ * @return {string}
5071
+ * @memberof PostProcess
5072
+ */
5073
+ export function postProcessScanlines(strength?: number, spacing?: number): string;
5074
+ /**
5075
+ * Static noise over the picture, changing every frame
5076
+ * @param {number} [strength] - How bright the static is
5077
+ * @param {number} [size] - Size of a speck in pixels
5078
+ * @return {string}
5079
+ * @memberof PostProcess
5080
+ */
5081
+ export function postProcessNoise(strength?: number, size?: number): string;
5082
+ /**
5083
+ * Darken toward the edges and corners
5084
+ * @param {number} [strength] - How dark the corners get, 1 is black
5085
+ * @param {number} [falloff] - How far in it reaches, low darkens most of the screen, high only the corners
5086
+ * @return {string}
5087
+ * @memberof PostProcess
5088
+ */
5089
+ export function postProcessVignette(strength?: number, falloff?: number): string;
5090
+ /**
5091
+ * Bend the picture like the bulged glass of an old TV, black past the corners; put it first
5092
+ * @param {number} [strength] - How much it bends
5093
+ * @return {string}
5094
+ * @memberof PostProcess
5095
+ */
5096
+ export function postProcessCurve(strength?: number): string;
5097
+ /**
5098
+ * Split red and blue apart toward the edges, like a cheap lens; put it before what shades the picture
5099
+ * @param {number} [strength] - How far apart at the edge, as a part of the screen
5100
+ * @return {string}
5101
+ * @memberof PostProcess
5102
+ */
5103
+ export function postProcessChromatic(strength?: number): string;
5104
+ /**
5105
+ * Draw lines where the 3D depth jumps, around objects and along their creases; needs render3D.depthTexture on
5106
+ * @param {Color} [color] - The lines' color, its alpha how strong they are
5107
+ * @param {number} [thickness] - How wide the lines are in pixels
5108
+ * @param {number} [threshold] - How big a jump makes a line, as a part of the distance, lower draws more
5109
+ * @return {string}
5110
+ * @memberof PostProcess
5111
+ */
5112
+ export function postProcessOutline(color?: Color, thickness?: number, threshold?: number): string;
5113
+ /**
5114
+ * The look of an old TV, as one effect to use alone or join with others: static noise, scan lines, a soft glow and
5115
+ * a vignette, and a bulged screen when curve is set; any setting at 0 leaves that part out
5116
+ * @param {Object} [settings]
5117
+ * @param {number} [settings.noise] - Static noise strength
5118
+ * @param {number} [settings.scanlines] - Scan line strength
5119
+ * @param {number} [settings.scanlineSpacing] - Pixels from one scan line to the next
5120
+ * @param {number} [settings.glow] - Soft glow strength
5121
+ * @param {number} [settings.vignette] - Vignette strength
5122
+ * @param {number} [settings.curve] - How much the screen bulges, 0 by default for flat
5123
+ * @return {string}
5124
+ * @example
5125
+ * new PostProcessPlugin(postProcessEffects(postProcessTV({scanlines: .4, curve: .1})));
5126
+ * @memberof PostProcess
5127
+ */
5128
+ export function postProcessTV({ noise, scanlines, scanlineSpacing, glow, vignette, curve }?: {
5129
+ noise?: number;
5130
+ scanlines?: number;
5131
+ scanlineSpacing?: number;
5132
+ glow?: number;
5133
+ vignette?: number;
5134
+ curve?: number;
5135
+ }): string;
4526
5136
  /**
4527
5137
  * LittleJS Light System Plugin
4528
5138
  * - Adds 2D dynamic lighting to the scene
@@ -4545,6 +5155,8 @@ declare module "littlejsengine" {
4545
5155
  * shadow map through renderShadow(), which calls render() by default; obj.castShadow = false keeps it
4546
5156
  * out (a floor TileLayer, a background), a draw's alpha sets how much light it blocks, and
4547
5157
  * setShadowTransparent lets its color tint the light
5158
+ * - Set light.glow for a soft hazy glow over a light, like a lamp at night; it is added over the lit scene after the
5159
+ * lightmap, so it shows in the dark and sits in front of everything there
4548
5160
  * - Must be constructed BEFORE PostProcessPlugin so post-process sees lit pixels
4549
5161
  * @namespace LightSystem
4550
5162
  */
@@ -4642,6 +5254,9 @@ declare module "littlejsengine" {
4642
5254
  shadowMapWorldSize: number;
4643
5255
  shadowMapSizeAllocated: number;
4644
5256
  shadowTextureSizeAllocated: number;
5257
+ /** Bring the sizes of the textures it makes down to what the device can make: shadowMapSize, shadowTextureSize
5258
+ * and a textureSize given by hand; called before they are made, so a size too big falls back instead of failing */
5259
+ clampTextureSizes(): void;
4645
5260
  /** Draw a single Light's falloff blob into the currently bound lightmap.
4646
5261
  * Called by Light.renderLight() during the plugin's render pass.
4647
5262
  * @param {Light} light */
@@ -4689,6 +5304,17 @@ declare module "littlejsengine" {
4689
5304
  * or torch that holds it, or the player carrying it, does not block it; it has to reach past that object's
4690
5305
  * corners, about half its diagonal and a little more, or dark rays run out from them */
4691
5306
  shadowCore: number;
5307
+ /** @property {number} - Size across of a soft hazy glow drawn over the light, like a lamp at night, 0 for
5308
+ * none; it is added over the lit scene, in front of everything there */
5309
+ glow: number;
5310
+ /** @property {number} - How fast the glow fades from its middle: 1 by default, .5 a wide haze, 2 a tight
5311
+ * bright core */
5312
+ glowFalloff: number;
5313
+ /** @type {TileInfo|undefined} */
5314
+ glowTileInfo: TileInfo | undefined;
5315
+ /** Draw this light's glow, soft and round, its glow size across and in its color, added over the lit scene;
5316
+ * called by LightSystemPlugin after the lightmap is applied */
5317
+ renderGlow(): void;
4692
5318
  }
4693
5319
  /**
4694
5320
  * LittleJS ZzFXM Plugin
@@ -6967,6 +7593,78 @@ declare module "littlejsengine" {
6967
7593
  * @return {Scene|undefined}
6968
7594
  * @memberof SceneSystem */
6969
7595
  export function getScene(): Scene | undefined;
7596
+ /**
7597
+ * LittleJS Parallax Plugin
7598
+ * - A background layer that follows the camera by a part of its movement, so it looks far away
7599
+ * - Repeats across the view, so a level of any width has a background
7600
+ * - Draws mountains by default, or anything a game draws into it
7601
+ * @namespace Parallax
7602
+ */
7603
+ /**
7604
+ * A background layer with parallax: an image that follows the camera by a part of its movement and repeats across
7605
+ * the view, drawn once into a canvas by a function, mountains when none is given
7606
+ * - A far layer has a parallax near 1 and a low renderOrder, a near one a smaller parallax and a higher renderOrder
7607
+ * - The image should meet itself at its left and right edges to repeat without a seam, as the mountains do
7608
+ * @memberof Parallax
7609
+ * @extends CanvasLayer
7610
+ * @example
7611
+ * // three ranges of mountains, the far ones lighter and slower
7612
+ * for (let i = 3; i--;)
7613
+ * new ParallaxLayer(vec2(0, i*2), vec2(40, 20), .9 - i*.2, -1e3 + i,
7614
+ * parallaxMountains(hsl(.6, .3, .7 - i*.2), hsl(.6, .5, .2), i));
7615
+ *
7616
+ * // or draw your own image into the layer
7617
+ * new ParallaxLayer(vec2(), vec2(40, 20), .5, -1e3, (context, size)=>
7618
+ * {
7619
+ * context.fillStyle = '#fff';
7620
+ * context.fillRect(size.x/2 - 20, size.y/2 - 20, 40, 40);
7621
+ * });
7622
+ */
7623
+ export class ParallaxLayer extends CanvasLayer {
7624
+ /** Create a parallax layer and draw its image
7625
+ * @param {Vector2} [pos] - Where the middle of the image is in the world when the camera is there too
7626
+ * @param {Vector2} [size] - World size of one copy of the image
7627
+ * @param {number|Vector2} [parallax] - How much of the camera's movement it follows, 0 stays with the world
7628
+ * and 1 with the screen, a Vector2 to follow x and y by different amounts
7629
+ * @param {number} [renderOrder] - Low to draw behind the game, far layers lowest
7630
+ * @param {function(OffscreenCanvasRenderingContext2D, Vector2, ParallaxLayer): void} [drawFunction] - Draws
7631
+ * the image, given the canvas context, its size in pixels and the layer; mountains when not given
7632
+ * @param {Vector2} [canvasSize] - Size of the image in pixels */
7633
+ constructor(pos?: Vector2, size?: Vector2, parallax?: number | Vector2, renderOrder?: number, drawFunction?: (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2, arg2: ParallaxLayer) => void, canvasSize?: Vector2);
7634
+ /** @property {Vector2} - How much of the camera's movement it follows on each axis, 0 stays with the world
7635
+ * and 1 with the screen */
7636
+ parallax: Vector2;
7637
+ /** @property {boolean} - Repeat the image across the view, left and right */
7638
+ wrapX: boolean;
7639
+ /** @property {boolean} - Repeat the image up and down the view */
7640
+ wrapY: boolean;
7641
+ /** @property {number} - How much the camera's zoom changes its size on the screen: 1 like the world, 0 not
7642
+ * at all, the same on the screen at any zoom as it is at zoomScale */
7643
+ zoomFollow: number;
7644
+ /** @property {number} - The camera scale its size is given for, used when zoomFollow is under 1 */
7645
+ zoomScale: number;
7646
+ /** @property {function(OffscreenCanvasRenderingContext2D, Vector2, ParallaxLayer): void} - Draws the
7647
+ * image, redraw() after changing it */
7648
+ drawFunction: (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2, arg2: ParallaxLayer) => void;
7649
+ /** Draw the image again with drawFunction, after changing it or what it draws from */
7650
+ redraw(): void;
7651
+ zoomFactor(): number;
7652
+ /** World size one copy of the image is drawn at now, its size unless zoomFollow is under 1
7653
+ * @return {Vector2} */
7654
+ getDrawSize(): Vector2;
7655
+ /** Where each copy of the image is drawn now, in the world: one place, or with wrapping every place that
7656
+ * shows in the view
7657
+ * @return {Array<Vector2>} */
7658
+ getDrawPositions(): Array<Vector2>;
7659
+ }
7660
+ /** A draw function for a ParallaxLayer: a range of mountains across the image, shaded from the color of their
7661
+ * peaks down to the color of their feet, that repeats with no seam
7662
+ * @param {Color} [topColor] - Color at the peaks
7663
+ * @param {Color} [bottomColor] - Color at the bottom of the image
7664
+ * @param {number} [seed] - The same seed gives the same mountains, random when not given
7665
+ * @return {function(OffscreenCanvasRenderingContext2D, Vector2): void}
7666
+ * @memberof Parallax */
7667
+ export function parallaxMountains(topColor?: Color, bottomColor?: Color, seed?: number): (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2) => void;
6970
7668
  /** Grid pathfinder using A* with two optional smoothing passes.
6971
7669
  * @memberof PathFinding
6972
7670
  * @example
@@ -7686,6 +8384,10 @@ declare module "littlejsengine" {
7686
8384
  * new EngineObject3D(vec3(), buildBox());
7687
8385
  */
7688
8386
  export class Render3DPlugin {
8387
+ /** @type {Render3DDrawState} */
8388
+ drawState: Render3DDrawState;
8389
+ /** @property {number} - Goes up when a draw state field changes, so a batch sees at a glance that none did */
8390
+ stateVersion: number;
7689
8391
  /** @property {Camera3D} - The camera */
7690
8392
  camera: Camera3D;
7691
8393
  /** @property {Vector3} - Direction toward the sun, where its light comes from, like a directional Light3D;
@@ -7724,8 +8426,16 @@ declare module "littlejsengine" {
7724
8426
  depthTexture: boolean;
7725
8427
  /** @property {boolean} - Cast real shadows from the sun, off by default and free when off */
7726
8428
  shadows: boolean;
8429
+ /** @property {number} - How far a sound played with playSound is heard when it was made with no range of
8430
+ * its own, in world units; further than the 2D soundDefaultRange, a 3D world is bigger */
8431
+ soundDefaultRange: number;
7727
8432
  /** @property {number} - Size of the shadow map in pixels, bigger is sharper and slower */
7728
8433
  shadowMapSize: number;
8434
+ /** @property {Light3D|undefined} - A spotlight, a Light3D with a coneAngle, to cast the shadows in place
8435
+ * of the sun, a flashlight in the dark: the shadow map looks down its cone, as far as its radius, and the
8436
+ * sun still lights the scene but casts none; undefined for the sun, as is a light that is off or has no cone
8437
+ * @type {Light3D|undefined} */
8438
+ shadowLight: Light3D | undefined;
7729
8439
  /** @property {number} - World size the shadow map covers around shadowCenter, smaller is sharper; it is a
7730
8440
  * square facing the light, so it turns as the light does, and about 1.5 times an area's width covers it from
7731
8441
  * any angle */
@@ -7737,46 +8447,6 @@ declare module "littlejsengine" {
7737
8447
  shadowBias: number;
7738
8448
  /** @property {number} - How much to blur the shadow edges */
7739
8449
  shadowSoftness: number;
7740
- /** @property {boolean} - Apply lighting, when false draws plain vertex color times texture and casts no shadow;
7741
- * off for billboards, lines, ribbons and soft discs, an object sets emissive instead */
7742
- lighting: boolean;
7743
- /** @property {number} - How much a surface lights itself, set per object by its emissive */
7744
- emissive: number;
7745
- /** @property {boolean} - Additive blending instead of alpha, in the transparent stage */
7746
- additive: boolean;
7747
- /** @property {boolean} - Test against the depth buffer, reset to true before each object and callback; a draw
7748
- * with it off goes over what was drawn before it and under what is drawn after, by render order, which
7749
- * ends the batch of meshes before it, so one per object costs a draw per object */
7750
- depthTest: boolean;
7751
- /** @property {boolean} - Write to the depth buffer, owned by the stages: on for opaque, off for transparent */
7752
- depthWrite: boolean;
7753
- cullBackFaces: boolean;
7754
- mirrored: boolean;
7755
- /** @property {number} - Strength of the highlight where the sun and the Light3D objects reflect, 0 is none and
7756
- * 1 adds a light's full color at its brightest; shininess sets its size */
7757
- specular: number;
7758
- /** @property {number} - The highlight's exponent, how small and sharp it is: 4 is broad like rubber, 100 sharp
7759
- * like polished metal; set from each object's shininess */
7760
- shininess: number;
7761
- /** @property {TextureInfo|undefined} - Normal map for the next draws, set from each object's normalMap
7762
- * @type {TextureInfo|undefined} */
7763
- normalMap: TextureInfo | undefined;
7764
- /** @property {number} - How strongly the normal map bends the surface, set from each object's normalScale */
7765
- normalScale: number;
7766
- /** @property {number} - How much the surface reflects the sky, 0 to 1, set from each object's reflectivity */
7767
- reflectivity: number;
7768
- /** @property {TextureInfo|undefined} - Emissive map for the next draws, set from each object's emissiveMap
7769
- * @type {TextureInfo|undefined} */
7770
- emissiveMap: TextureInfo | undefined;
7771
- /** @property {Color} - Multiplies the emissive map, set from each object's emissiveMapColor */
7772
- emissiveMapColor: Color;
7773
- /** @property {Shader|undefined} - Custom Shader for the next draws, set from each object's shader; undefined
7774
- * draws with the plugin's own
7775
- * @type {Shader|undefined} */
7776
- shader: Shader | undefined;
7777
- /** @property {boolean} - Darken by the shadow map when shadows are on, turn it off for things that should stay
7778
- * lit inside a shadow */
7779
- receiveShadow: boolean;
7780
8450
  /** @property {Function|undefined} - Draw solid world here, it runs again for shadows so only draw in it
7781
8451
  * @type {Function|undefined} */
7782
8452
  onRenderOpaque: Function | undefined;
@@ -7798,9 +8468,6 @@ declare module "littlejsengine" {
7798
8468
  /** @property {boolean} - Sample textures through mipmaps so they do not shimmer in the distance, false uses
7799
8469
  * each texture's own filtering like 2D */
7800
8470
  mipmaps: boolean;
7801
- /** @property {boolean} - Draw state: keep texture pixels hard edged, no mipmaps and no blending between them,
7802
- * set per object by pixelated */
7803
- pixelated: boolean;
7804
8471
  /** @property {number} - Anisotropic filtering for textures seen at an angle, 1 to 16, 1 is off; needs mipmaps */
7805
8472
  anisotropy: number;
7806
8473
  /** @property {Mesh} - A box of size 1 that drawBox uses, for any object that is a box; set the object's scale3D
@@ -7835,7 +8502,6 @@ declare module "littlejsengine" {
7835
8502
  /** @property {Vector3} - Camera forward axis this frame */
7836
8503
  cameraForward: Vector3;
7837
8504
  cameraBack: Vector3;
7838
- blend: boolean;
7839
8505
  /** @type {Array<Array<number>>} */
7840
8506
  frustumPlanes: Array<Array<number>>;
7841
8507
  /** @type {Array<Array<number>>} */
@@ -7877,6 +8543,9 @@ declare module "littlejsengine" {
7877
8543
  passIsDefault: boolean;
7878
8544
  lightPositions: Float32Array;
7879
8545
  lightColors: Float32Array;
8546
+ lightCones: Float32Array;
8547
+ shadowLightIndex: number;
8548
+ shadowDepthBias: number;
7880
8549
  /** @type {WebGLBuffer|undefined} */
7881
8550
  streamBuffer: WebGLBuffer | undefined;
7882
8551
  /** @type {Array<WebGLBuffer>} */
@@ -7901,6 +8570,89 @@ declare module "littlejsengine" {
7901
8570
  state: any;
7902
8571
  draw: () => void;
7903
8572
  }> | undefined;
8573
+ set lighting(arg: boolean);
8574
+ /** Apply lighting, when false draws plain vertex color times texture and casts no shadow;
8575
+ * off for billboards, lines, ribbons and soft discs, an object sets emissive instead
8576
+ * @return {boolean} */
8577
+ get lighting(): boolean;
8578
+ set emissive(arg: number);
8579
+ /** How much a surface lights itself, set per object by its emissive
8580
+ * @return {number} */
8581
+ get emissive(): number;
8582
+ set additive(arg: boolean);
8583
+ /** Additive blending instead of alpha, in the transparent stage
8584
+ * @return {boolean} */
8585
+ get additive(): boolean;
8586
+ set depthTest(arg: boolean);
8587
+ /** Test against the depth buffer, reset to true before each object and callback; a draw
8588
+ * with it off goes over what was drawn before it and under what is drawn after, by render order, which
8589
+ * ends the batch of meshes before it, so one per object costs a draw per object
8590
+ * @return {boolean} */
8591
+ get depthTest(): boolean;
8592
+ set depthWrite(arg: boolean);
8593
+ /** Write to the depth buffer, owned by the stages: on for opaque, off for transparent
8594
+ * @return {boolean} */
8595
+ get depthWrite(): boolean;
8596
+ set cullBackFaces(arg: boolean);
8597
+ /** Skip back faces, set by drawMesh from each mesh: off for strips so they show from
8598
+ * both sides
8599
+ * @return {boolean} */
8600
+ get cullBackFaces(): boolean;
8601
+ set mirrored(arg: boolean);
8602
+ /** The transform mirrors the draw, so the other winding is the front, set by drawMesh
8603
+ * from each transform
8604
+ * @return {boolean} */
8605
+ get mirrored(): boolean;
8606
+ set specular(arg: number);
8607
+ /** Strength of the highlight where the sun and the Light3D objects reflect, 0 is none and
8608
+ * 1 adds a light's full color at its brightest; shininess sets its size
8609
+ * @return {number} */
8610
+ get specular(): number;
8611
+ set shininess(arg: number);
8612
+ /** The highlight's exponent, how small and sharp it is: 4 is broad like rubber, 100 sharp
8613
+ * like polished metal; set from each object's shininess
8614
+ * @return {number} */
8615
+ get shininess(): number;
8616
+ set normalMap(arg: TextureInfo);
8617
+ /** Normal map for the next draws, set from each object's normalMap
8618
+ * @return {TextureInfo|undefined} */
8619
+ get normalMap(): TextureInfo;
8620
+ set normalScale(arg: number);
8621
+ /** How strongly the normal map bends the surface, set from each object's normalScale
8622
+ * @return {number} */
8623
+ get normalScale(): number;
8624
+ set reflectivity(arg: number);
8625
+ /** How much the surface reflects the sky, 0 to 1, set from each object's reflectivity
8626
+ * @return {number} */
8627
+ get reflectivity(): number;
8628
+ set emissiveMap(arg: TextureInfo);
8629
+ /** Emissive map for the next draws, set from each object's emissiveMap
8630
+ * @return {TextureInfo|undefined} */
8631
+ get emissiveMap(): TextureInfo;
8632
+ set emissiveMapColor(arg: Color);
8633
+ /** Multiplies the emissive map, set from each object's emissiveMapColor; compared by its rgb, so a Color
8634
+ * changed in place is seen when it is set again, and undefined is white
8635
+ * @return {Color} */
8636
+ get emissiveMapColor(): Color;
8637
+ set shader(arg: Shader);
8638
+ /** Custom Shader for the next draws, set from each object's shader; undefined draws
8639
+ * with the plugin's own
8640
+ * @return {Shader|undefined} */
8641
+ get shader(): Shader;
8642
+ set receiveShadow(arg: boolean);
8643
+ /** Darken by the shadow map when shadows are on, turn it off for things that should
8644
+ * stay lit inside a shadow
8645
+ * @return {boolean} */
8646
+ get receiveShadow(): boolean;
8647
+ set pixelated(arg: boolean);
8648
+ /** Keep texture pixels hard edged, no mipmaps and no blending between them, set per
8649
+ * object by pixelated
8650
+ * @return {boolean} */
8651
+ get pixelated(): boolean;
8652
+ set blend(arg: boolean);
8653
+ /** Blending on, set by the stages
8654
+ * @return {boolean} */
8655
+ get blend(): boolean;
7904
8656
  /** Rebuild the view and projection matrices from the camera, called automatically each frame
7905
8657
  * @param {number} [aspect] - Width over height, defaults to the main canvas */
7906
8658
  updateMatrices(aspect?: number): void;
@@ -7941,7 +8693,8 @@ declare module "littlejsengine" {
7941
8693
  distance: number;
7942
8694
  } | undefined;
7943
8695
  /** Play a sound at a 3D position, quieter with distance from the camera and panned by its side, like Sound.play
7944
- * with a 2D position
8696
+ * with a 2D position; a sound made with no range of its own is heard to soundDefaultRange, 100, and one given
8697
+ * a range keeps it
7945
8698
  * @param {Sound} sound
7946
8699
  * @param {Vector3} pos3D
7947
8700
  * @param {number} [volume]
@@ -8532,20 +9285,24 @@ declare module "littlejsengine" {
8532
9285
  * InstancedMesh3D - Many copies of one mesh drawn as one call, with their transforms kept on the GPU
8533
9286
  * - For big sets that mostly stay put: an instance costs nothing per frame until it changes, so a hundred thousand
8534
9287
  * trees cost what one tree does; objects and drawMesh batch by themselves too, but rebuild their batch every frame
8535
- * - setMatrixAt and setColorAt change one instance, and only the changed range uploads before the next draw
9288
+ * - setTransformAt, setMatrixAt and setColorAt change one instance, and only the changed range uploads before the
9289
+ * next draw; the matrices and the colors are kept apart, so moving instances uploads 64 bytes each
9290
+ * - For many instances moving every frame, setTransforms places a run of them from arrays of positions, rotations
9291
+ * and scales in one loop, the fastest way; or write matrixData directly and call markDirtyRange
8536
9292
  * - The instances are in world space; the object's own pos3D, rotation3D and scale3D do not move them
8537
- * - The whole set is culled by one bounding sphere around the origin, and casts and receives shadows like any object
9293
+ * - The whole set is culled by one bounding sphere around the origin, worked out when culling reads it, or set by hand
9294
+ * with radius; it casts and receives shadows like any object
8538
9295
  * - The object's flags cover the whole set, one emissive, one tileInfo, one shader; only the colors are per instance
8539
9296
  * - A mirrored instance, one with a negative scale, shows its inside unless the mesh is doubleSided
8540
9297
  * - A transparent set draws in one go in the transparent stage, its instances are not sorted against each other;
8541
9298
  * the set sorts against other transparent draws by the object's position, so put pos3D at its middle
8542
- * - pick, the raycast and the collect helpers do not see the instances, test them yourself from instanceData
9299
+ * - pick, the raycast and the collect helpers do not see the instances, test them yourself from matrixData
8543
9300
  * @extends EngineObject3D
8544
9301
  * @memberof Render3D
8545
9302
  * @example
8546
9303
  * const forest = new InstancedMesh3D(treeMesh, 1000);
8547
9304
  * for (let i = 0; i < 1000; ++i)
8548
- * forest.setMatrixAt(i, buildMatrix(randomGroundPos(), vec3(0, rand(2*PI), 0)));
9305
+ * forest.setTransformAt(i, randomGroundPos(), vec3(0, rand(2*PI), 0));
8549
9306
  */
8550
9307
  export class InstancedMesh3D extends EngineObject3D {
8551
9308
  /** Create a set of instances of a mesh, each at the origin in the object's color until it is set
@@ -8558,21 +9315,53 @@ declare module "littlejsengine" {
8558
9315
  count: number;
8559
9316
  /** @property {number} - How many instances it was made with */
8560
9317
  maxCount: number;
8561
- /** @property {Float32Array} - The per instance values the shader reads, 24 floats each: the matrix, the color
8562
- * and the uv rect; edit it directly and call markDirty for the instances changed */
8563
- instanceData: Float32Array;
8564
- /** @property {number} - Radius of the sphere around the origin that holds every instance set so far, for
8565
- * culling; from the farthest instance and the largest scale, and the mesh's size when it draws */
8566
- radius: number;
8567
- reach: number;
8568
- maxScale: number;
8569
- /** @property {number} - First instance to upload before the next draw */
9318
+ /** @property {Float32Array} - Each instance's matrix, 16 floats, what moving them uploads; edit it directly and
9319
+ * call markDirty for the instances changed */
9320
+ matrixData: Float32Array;
9321
+ /** @property {Float32Array} - Each instance's color and uv rect, 8 floats, uploaded only when they change; edit
9322
+ * it directly and call markColorDirty for the instances changed */
9323
+ colorData: Float32Array;
9324
+ /** @property {number} - First instance whose matrix uploads before the next draw */
8570
9325
  dirtyStart: number;
8571
- /** @property {number} - One past the last instance to upload, so nothing uploads when it is not past dirtyStart */
9326
+ /** @property {number} - One past the last instance whose matrix uploads, nothing when it is not past dirtyStart */
8572
9327
  dirtyEnd: number;
9328
+ /** @property {number} - First instance whose color uploads before the next draw */
9329
+ colorDirtyStart: number;
9330
+ /** @property {number} - One past the last instance whose color uploads */
9331
+ colorDirtyEnd: number;
9332
+ reachSquared: number;
9333
+ scaleSquared: number;
9334
+ boundsStart: number;
9335
+ boundsEnd: number;
9336
+ /** @type {number|undefined} */
9337
+ fixedRadius: number | undefined;
8573
9338
  buffer: WebGLBuffer;
9339
+ /** @type {WebGLBuffer|undefined} */
9340
+ colorBuffer: WebGLBuffer | undefined;
8574
9341
  bufferGeneration: number;
8575
9342
  uvTileInfo: TileInfo | TextureInfo;
9343
+ /** Place an instance by its position, rotation and scale, what buildMatrix takes, written straight in with no
9344
+ * matrix made; in world space
9345
+ * @param {number} i
9346
+ * @param {Vector3} [pos]
9347
+ * @param {Vector3} [rotation] - Euler angles in radians
9348
+ * @param {Vector3} [scale] */
9349
+ setTransformAt(i: number, pos?: Vector3, rotation?: Vector3, scale?: Vector3): void;
9350
+ /** Place a run of instances from arrays indexed by instance, plain or typed, as a game keeps them: each is placed
9351
+ * as setTransformAt places it, all in one loop with nothing made, the fastest way to move many every frame;
9352
+ * in world space
9353
+ * @param {number} start - First instance
9354
+ * @param {number} count - How many
9355
+ * @param {ArrayLike<number>} x - Positions
9356
+ * @param {ArrayLike<number>} y
9357
+ * @param {ArrayLike<number>} z
9358
+ * @param {ArrayLike<number>} [rx] - Euler angles in radians, all three or none for upright
9359
+ * @param {ArrayLike<number>} [ry]
9360
+ * @param {ArrayLike<number>} [rz]
9361
+ * @param {ArrayLike<number>} [sx] - Scales, all three or none for 1
9362
+ * @param {ArrayLike<number>} [sy]
9363
+ * @param {ArrayLike<number>} [sz] */
9364
+ setTransforms(start: number, count: number, x: ArrayLike<number>, y: ArrayLike<number>, z: ArrayLike<number>, rx?: ArrayLike<number>, ry?: ArrayLike<number>, rz?: ArrayLike<number>, sx?: ArrayLike<number>, sy?: ArrayLike<number>, sz?: ArrayLike<number>): void;
8576
9365
  /** Place an instance, in world space
8577
9366
  * @param {number} i
8578
9367
  * @param {Matrix4} matrix */
@@ -8585,10 +9374,26 @@ declare module "littlejsengine" {
8585
9374
  * @param {number} i
8586
9375
  * @param {Color} color */
8587
9376
  setColorAt(i: number, color: Color): void;
8588
- /** Note that an instance changed, so it uploads before the next draw and the bounds hold it; setMatrixAt and
8589
- * setColorAt call this, and so must an edit made straight to instanceData
9377
+ /** Note that an instance's matrix changed, so it uploads before the next draw and the bounds take it in when
9378
+ * they are read; setTransformAt and setMatrixAt call this, and so must an edit made straight to matrixData
8590
9379
  * @param {number} i */
8591
9380
  markDirty(i: number): void;
9381
+ /** Note that a run of instances' matrices changed, for code that writes matrixData directly, the lowest level
9382
+ * way to move many: they upload before the next draw and the bounds take them in when they are read
9383
+ * @param {number} start - First instance
9384
+ * @param {number} end - One past the last */
9385
+ markDirtyRange(start: number, end: number): void;
9386
+ /** Note that an instance's color changed, so it uploads before the next draw; setColorAt calls this, and so must
9387
+ * an edit made straight to colorData
9388
+ * @param {number} i */
9389
+ markColorDirty(i: number): void;
9390
+ set radius(arg: number);
9391
+ /** Radius of the sphere around the origin that holds every instance set so far, for culling: the farthest
9392
+ * instance, and the mesh's size at the largest scale; it only grows, and takes in the instances set since it
9393
+ * was last read, so with frustum culling off it is never worked out. Set it to fix the sphere, which a big set
9394
+ * that is culled can use to skip that work, and set it to undefined to go back to the bounds
9395
+ * @return {number} */
9396
+ get radius(): number;
8592
9397
  }
8593
9398
  /**
8594
9399
  * Spin a flat outline around the Y axis to make a round shape, like a vase or a wheel
@@ -9024,13 +9829,16 @@ declare module "littlejsengine" {
9024
9829
  /**
9025
9830
  * Light3D - A light that is an EngineObject3D, so it can move, follow a parent or be destroyed like anything else
9026
9831
  * - A point light: it lights what is near it and fades out by its radius, DirectionalLight3D shines from far away
9027
- * - Only the sun, render3D.sunDirection, casts shadows; these light and make highlights without one
9832
+ * - A coneAngle makes it a spotlight: it shines along its own forward, turned by rotation3D or by what it is
9833
+ * attached to, inside the cone, fading over the part of it coneSoftness says
9834
+ * - The sun, render3D.sunDirection, casts the shadows; a spotlight can cast them in its place, see
9835
+ * render3D.shadowLight; the other lights light and make highlights without one
9028
9836
  * - Only the 8 lights nearest the camera are used each frame
9029
9837
  * - radius is where the light fades out, and it fades fast, so a small radius wants a higher intensity
9030
9838
  * - intensity multiplies the color, above 1 for a light brighter than white
9031
9839
  * - radius is a world distance, so scale3D does not change it
9032
9840
  * - An alpha, an intensity or a radius of 0 switches it off, and a light that is off takes none of those slots
9033
- * - Draws nothing itself, add a glow with drawSoftDisc or a small emissive mesh if it should be seen
9841
+ * - Draws nothing but its glow, when it has one; add a small emissive mesh if the lamp itself should be seen
9034
9842
  * @extends EngineObject3D
9035
9843
  * @memberof Render3D
9036
9844
  * @example
@@ -9050,6 +9858,12 @@ declare module "littlejsengine" {
9050
9858
  /** @property {boolean} - Shine from far away, from its position toward the origin, instead of out from its
9051
9859
  * position with a falloff; DirectionalLight3D sets it */
9052
9860
  directional: boolean;
9861
+ /** @property {number} - Makes it a spotlight: the angle in radians from its forward out to the edge of its
9862
+ * cone, so the beam is twice this across; 0 for a light that shines every way */
9863
+ coneAngle: number;
9864
+ /** @property {number} - How much of the cone is its fading edge: 0 a hard edge, .2 by default, the outer
9865
+ * fifth, 1 fading all the way from the middle of the beam */
9866
+ coneSoftness: number;
9053
9867
  /** @property {number} - Size of a soft hazy glow drawn over the light, like a lamp at night, 0 for none; it
9054
9868
  * is added onto what is behind it, and what is in front of the light hides it */
9055
9869
  glow: number;
@@ -9062,7 +9876,7 @@ declare module "littlejsengine" {
9062
9876
  * - It shines from its position toward the origin, like a three.js DirectionalLight: only the direction to it
9063
9877
  * counts, so moving it or its parent swings the light around; parent it to a sun in the sky and it follows
9064
9878
  * - It cannot sit on the origin, since that leaves no direction
9065
- * - Like every Light3D it casts no shadow, only the sun, render3D.sunDirection, does
9879
+ * - It casts no shadow: the sun, render3D.sunDirection, does, or a spotlight set as render3D.shadowLight
9066
9880
  * @extends Light3D
9067
9881
  * @memberof Render3D
9068
9882
  * @example
@@ -9167,6 +9981,8 @@ declare module "littlejsengine" {
9167
9981
  * @property {Vector3} velocity - How far it moves each frame
9168
9982
  * @property {number} age - Seconds it has lived
9169
9983
  * @property {number} lifeTime - Seconds it lives
9984
+ * @property {number} scale - How much the emitter grows its effect, from its scale3D and its parents', as the 2D
9985
+ * particle's scale
9170
9986
  * @property {boolean} destroyed - Set by destroy
9171
9987
  * @property {function(): void} destroy - End it this update, the destroy callback gets it
9172
9988
  * @memberof Render3D
@@ -9193,8 +10009,9 @@ declare module "littlejsengine" {
9193
10009
  * - emitConeAngle spreads them, PI sprays in every direction
9194
10010
  * - Speeds are per frame and sizes are world units, the same as the 2D emitter
9195
10011
  * - scale3D, its own or a parent's, grows the whole effect: the spawn area, the sizes, the speed and the fall
9196
- * - gravity here is its own number added to velocity y each frame: it is neither the engine's 2D
9197
- * gravity nor render3D.gravity, so an effect keeps its own fall wherever it is used
10012
+ * - gravity here is its own number added to velocity y each frame, so an effect keeps its own fall wherever it is
10013
+ * used, the same as the 2D emitter's gravity; gravityScale adds a share of render3D.gravity on top, as the 2D
10014
+ * emitter's gravityScale adds the engine's gravity
9198
10015
  * - An emitter with an emitTime destroys itself once its last particle is gone, like the 2D emitter
9199
10016
  * - Callbacks as the 2D emitter's: particleCreateCallback, particleUpdateCallback, particleCollideCallback and
9200
10017
  * particleDestroyCallback, each given a Particle3D, one object the emitter reuses for every particle and call
@@ -9223,14 +10040,17 @@ declare module "littlejsengine" {
9223
10040
  * @param {number} [sizeEnd] - Particle size at end of life
9224
10041
  * @param {number} [speed] - Spawn speed in world units per frame
9225
10042
  * @param {number} [damping] - Per frame velocity multiplier, 1 is none
9226
- * @param {number} [gravity] - Per frame change to velocity y, negative pulls down; its own number,
9227
- * not render3D.gravity, so the 2D emitter's gravityScale has no equivalent here
10043
+ * @param {number} [gravity] - Per frame change to velocity y, negative pulls down; its own number, and
10044
+ * gravityScale adds a share of render3D.gravity on top
9228
10045
  * @param {number} [fadeRate] - Fraction of life spent fading, half in and half out
9229
10046
  * @param {number} [randomness] - Extra randomness applied to speed, size and life
9230
10047
  * @param {boolean} [additive] - Additive blending */
9231
10048
  constructor(pos3D?: Vector3, emitSize?: number | Vector3, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileInfo?: TileInfo | TextureInfo, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, damping?: number, gravity?: number, fadeRate?: number, randomness?: number, additive?: boolean);
9232
10049
  /** @property {number|Vector3} - Spawn area, a number for a sphere diameter or a vec3 for a box */
9233
10050
  emitSize: number | Vector3;
10051
+ /** @property {boolean} - Flatten the spawn area across the way it emits, its own up: a sphere becomes a disc
10052
+ * and a box a flat rectangle, for rain from a sheet of sky or flames from a patch of ground */
10053
+ emitFlat: boolean;
9234
10054
  /** @property {number} - How long to keep emitting, 0 is forever */
9235
10055
  emitTime: number;
9236
10056
  /** @property {number} - Particles per second, 0 does not emit */
@@ -9274,6 +10094,9 @@ declare module "littlejsengine" {
9274
10094
  trailData: Float32Array | undefined;
9275
10095
  /** @property {number} - Trail points kept per particle, from trailTime */
9276
10096
  trailMax: number;
10097
+ /** @property {number} - How much a particle grips where it lands, 0 to 1: its speed along the surface is
10098
+ * cut by this much on each hit, on top of the friction, 1 stops it there */
10099
+ stick: number;
9277
10100
  /** @property {Particle3DCallback|undefined} - Called with each particle as it is made
9278
10101
  * @type {Particle3DCallback|undefined} */
9279
10102
  particleCreateCallback: Particle3DCallback | undefined;
@@ -9297,7 +10120,7 @@ declare module "littlejsengine" {
9297
10120
  /** Spawn one particle now */
9298
10121
  emitParticle(): void;
9299
10122
  particleCall(callback: any, k: any, level: any, pos: any): any;
9300
- particleCollide(k: any, x: any, y: any, z: any): void;
10123
+ particleCollide(k: any, x: any, y: any, z: any): boolean;
9301
10124
  }
9302
10125
  /**
9303
10126
  * Trail3D - A ribbon through where the object has been, thinning and fading with age
@@ -9342,6 +10165,103 @@ declare module "littlejsengine" {
9342
10165
  clear(): void;
9343
10166
  worldPos3D: Vector3;
9344
10167
  }
10168
+ /**
10169
+ * LensFlare3D - The sun's lens flare, the old kind: a glow at the sun and a row of discs and rings of different
10170
+ * sizes along the line from the sun through the middle of the screen
10171
+ * - Make one and it shows, over the 3D scene and under what the game draws after, a HUD; destroy it to take it away
10172
+ * - It follows render3D.sunDirection, and fades out as the sun leaves the screen or goes behind something
10173
+ * - flareSize, count, intensity and saturation set its look, seed picks another arrangement, and its color tints it,
10174
+ * with the sun's own color; or give it elements of your own
10175
+ * - visible is how much of the sun shows, 0 to 1, eased over fadeTime, there for a game to read
10176
+ * - What hides the sun is found with a ray from the camera, against the level and every object that is not see
10177
+ * through, each as the box around its mesh, see render3D.pick; turn it off with occlusion
10178
+ * - It needs WebGL, and it draws nothing in the shadow of renderAfter2D
10179
+ * @extends EngineObject3D
10180
+ * @memberof Render3D
10181
+ * @example
10182
+ * new LensFlare3D; // the sun flares
10183
+ * new LensFlare3D(1.5, 10, .7, 0); // bigger, 10 ghosts, dimmer, all one color
10184
+ */
10185
+ export class LensFlare3D extends EngineObject3D {
10186
+ /** Create the sun's lens flare
10187
+ * @param {number} [size] - Scales every part of it, 1 by default
10188
+ * @param {number} [count] - How many ghosts there are along the line, besides the glow at the sun
10189
+ * @param {number} [intensity] - How bright it is
10190
+ * @param {number} [saturation] - How colorful the ghosts are, 0 for all the flare's own color, 1 a rainbow
10191
+ * @param {Color} [color] - Tints the whole flare, with the sun's color */
10192
+ constructor(size?: number, count?: number, intensity?: number, saturation?: number, color?: Color);
10193
+ /** @property {number} - Scales every part of the flare */
10194
+ flareSize: number;
10195
+ /** @property {number} - How many ghosts there are along the line, besides the glow at the sun */
10196
+ count: number;
10197
+ /** @property {number} - How bright it is */
10198
+ intensity: number;
10199
+ /** @property {number} - How colorful the ghosts are, 0 for all the flare's own color, 1 a rainbow */
10200
+ saturation: number;
10201
+ /** @property {number} - Picks the arrangement of the ghosts, another seed is another flare */
10202
+ seed: number;
10203
+ /** @property {Array<{at: number, size: number, color: Color, shape: string}>|undefined} - The parts of the
10204
+ * flare, to set your own in place of the ones made from count, seed and saturation: at is where along the
10205
+ * line, 0 the sun, 1 the middle of the screen, 2 as far past it; size is across, as a part of the screen's
10206
+ * height; shape is glow, disc or ring
10207
+ * @type {Array<{at: number, size: number, color: Color, shape: string}>|undefined} */
10208
+ elements: {
10209
+ at: number;
10210
+ size: number;
10211
+ color: Color;
10212
+ shape: string;
10213
+ }[];
10214
+ /** @property {Light3D|undefined} - A light the flare is of in place of the sun, a lamp or a spotlight: the
10215
+ * flare is at the light and in its color, smaller from farther than the light reaches, hidden by what is
10216
+ * in front of the light, and a spotlight's shows from inside its beam only
10217
+ * @type {Light3D|undefined} */
10218
+ light: Light3D | undefined;
10219
+ /** @property {boolean} - Fade out when something is between the camera and the sun */
10220
+ occlusion: boolean;
10221
+ /** @property {number} - Seconds the flare takes to fade out or in when the sun is hidden or shows again */
10222
+ fadeTime: number;
10223
+ /** @property {number} - How much of the sun shows, 0 hidden or behind the camera to 1 in plain view, eased */
10224
+ visible: number;
10225
+ madeKey: string;
10226
+ /** @type {Array<{at: number, size: number, color: Color, shape: string}>} */
10227
+ made: {
10228
+ at: number;
10229
+ size: number;
10230
+ color: Color;
10231
+ shape: string;
10232
+ }[];
10233
+ /** The parts of the flare: the elements set by hand, or the ones made from count, seed and saturation, a glow
10234
+ * and a core at the sun and the ghosts, made again when one of those changes
10235
+ * @return {Array<{at: number, size: number, color: Color, shape: string}>} */
10236
+ getElements(): Array<{
10237
+ at: number;
10238
+ size: number;
10239
+ color: Color;
10240
+ shape: string;
10241
+ }>;
10242
+ flareSource(): {
10243
+ direction: Vector3;
10244
+ distance: number;
10245
+ pos: Vector3;
10246
+ };
10247
+ /** Where the sun, or the flare's light, is on the screen, in pixels like mousePosScreen, undefined when it is
10248
+ * behind the camera
10249
+ * @return {Vector2|undefined} */
10250
+ getSunScreenPos(): Vector2 | undefined;
10251
+ /** The parts of the flare as they are drawn now: each one's place on the screen, its size in pixels and its
10252
+ * color, dimmed by how much of the sun shows; empty when there is nothing to draw
10253
+ * @return {Array<{pos: Vector2, size: number, color: Color, shape: string}>} */
10254
+ getScreenElements(): Array<{
10255
+ pos: Vector2;
10256
+ size: number;
10257
+ color: Color;
10258
+ shape: string;
10259
+ }>;
10260
+ /** Is something between the camera and the sun, or the flare's light: the level, or an object that is not see
10261
+ * through
10262
+ * @return {boolean} */
10263
+ isSunHidden(): boolean;
10264
+ }
9345
10265
  /**
9346
10266
  * Collect the EngineObject3D objects whose boxes overlap a sphere or a box, the 3D twin of engineObjectsCollect
9347
10267
  * - Each object is its size3D box at its world position, turned as it is turned; lights, emitters and trails have no
@@ -9671,10 +10591,109 @@ declare module "littlejsengine" {
9671
10591
  * - What a file written by hand gets wrong uses the default: a value that is not of its default's type
9672
10592
  * - An object its type can not make is skipped with an error in debug builds, where asserts throw, and the rest
9673
10593
  * of the level is made
10594
+ * - A level may hold a map of blocks, in a voxels block: pos, its corner, size, its cells along x, y and z, and
10595
+ * blocks, runs of a count and a type along x, then y, then z; it is made a VoxelMap, the first of what is
10596
+ * returned, see level3DVoxelSetup for its sheet
10597
+ * - A level may hold a terrain, in a terrain block: pos, its center, size, its size in the world along x and z,
10598
+ * height, how tall a full height is, color, and heights, rows of 0 to 1 from -z to +z, each from -x to +x; it
10599
+ * is made a HeightMap, returned with what else was made; paint, when it has it, colors its samples: colors, a
10600
+ * list, and cells, runs of a count and a color along the rows, 0 for the terrain's own and 1 the list's first
10601
+ * - A level may hold prefabs of its own, in a prefabs block, each by its name as level3DAddPrefab takes it; they
10602
+ * are added before its objects are made, one the game added itself keeps its place
10603
+ * - A level may set the scene too, in a scene block beside its objects: sky, three colors for straight up, the
10604
+ * horizon and straight down, ambient, how much of them lights the scene, .5 when not given, sunDirection and
10605
+ * sunColor, fog, its start and end, fogColor, the horizon color when not given, and shadows; what the block
10606
+ * leaves out stays as the game set it, and a level with no block changes nothing
9674
10607
  * @param {Object} level - The level, the level editor edits this same object
9675
10608
  * @return {Array<any>} - What each object's type made, a function that made nothing is left out
9676
10609
  * @memberof Level3D */
9677
10610
  export function level3DLoad(level: any): Array<any>;
10611
+ /** Add a prefab: a small level, its objects placed about its own origin, to place many times under one name
10612
+ * - It is a type from then on: a level's object of that type, the level editor's Place list and level3DSpawn make
10613
+ * an instance, a Prefab3D; an instance is made of the prefab as it is then, so the level editor, where a prefab
10614
+ * changes, makes its instances again
10615
+ * - The prefab is a level as the level editor saves it, {objects: [...]}, so the editor is the prefab editor too;
10616
+ * only its objects are used, and they may be of other prefabs
10617
+ * - With attached true in it the parts are children of the instance and move with it as one body, without
10618
+ * collision of their own, a prefab inside it too; its handle is at the middle of the box around them and its
10619
+ * size3D is that box, so setCollision makes the body solid where it is seen; otherwise each part is an object of its own in the world and collides as one placed
10620
+ * by hand does
10621
+ * - Adding a name again replaces it
10622
+ * @param {string} name - The type its instances have in a level
10623
+ * @param {Object} prefab - {objects, attached}
10624
+ * @memberof Level3D
10625
+ * @example
10626
+ * level3DAddPrefab('Tower', {objects: [{type: 'Box', pos: [0, 1, 0], scale: [2, 2, 2]},
10627
+ * {type: 'Cylinder', pos: [0, 3, 0]}]});
10628
+ * level3DLoad({objects: [{type: 'Tower', pos: [5, 0, 5]}, {type: 'Tower', pos: [-5, 0, 5], rotation: [0, 45, 0]}]}); */
10629
+ export function level3DAddPrefab(name: string, prefab: any): void;
10630
+ /** Load a prefab from a file the level editor saved and add it
10631
+ * @param {string} name - The type its instances have in a level
10632
+ * @param {string} url
10633
+ * @return {Promise<void>}
10634
+ * @memberof Level3D */
10635
+ export function level3DLoadPrefab(name: string, url: string): Promise<void>;
10636
+ /** Make one object of a type added with level3DAddType, level3DAddMesh or level3DAddPrefab, from code, with no
10637
+ * level: a prefab's instance, or a plain type
10638
+ * @param {string} type - The type's name
10639
+ * @param {Vector3} [pos3D]
10640
+ * @param {Vector3} [rotation3D] - In radians, as an object has it
10641
+ * @param {Vector3} [scale3D] - Times the scale the type makes it with
10642
+ * @param {Object} [properties] - Over the type's defaults
10643
+ * @return {any} - What the type made, a Prefab3D for a prefab, undefined when there is no such type
10644
+ * @memberof Level3D
10645
+ * @example
10646
+ * level3DAddPrefab('House', await fetchJSON('house.json'));
10647
+ * level3DSpawn('House', vec3(10, 0, 0), vec3(0, PI/2, 0)); */
10648
+ export function level3DSpawn(type: string, pos3D?: Vector3, rotation3D?: Vector3, scale3D?: Vector3, properties?: any): any;
10649
+ /**
10650
+ * An instance of a prefab, what a prefab's type makes: a handle with no shape of its own, and its parts, what the
10651
+ * prefab's objects made
10652
+ * - Parts of a prefab that is not attached are objects of their own in the world: moving, turning or sizing the
10653
+ * handle puts them where it now says with its next update, or call placeParts; destroying it destroys them
10654
+ * - Parts of an attached prefab are its children and move with it as one body
10655
+ * @extends EngineObject3D
10656
+ * @memberof Level3D
10657
+ */
10658
+ export class Prefab3D extends EngineObject3D {
10659
+ /** Create an instance of a prefab, made by its type: place one with a level or level3DSpawn
10660
+ * @param {Vector3} [pos3D]
10661
+ * @param {string} [prefabName] - A prefab added with level3DAddPrefab */
10662
+ constructor(pos3D?: Vector3, prefabName?: string);
10663
+ /** @property {string} - The prefab it is an instance of */
10664
+ prefabName: string;
10665
+ /** @property {boolean} - Are its parts its children, moving with it as one body */
10666
+ attached: boolean;
10667
+ /** @property {Array<any>} - What the prefab's objects made, in the prefab's order */
10668
+ parts: any[];
10669
+ /** @property {Vector3} - From the prefab's origin to the handle, in the prefab's own space: nothing for
10670
+ * separate parts, and for an attached prefab the middle of the box around its parts, where its handle
10671
+ * is, as an object's place is the middle of its body */
10672
+ originOffset: Vector3;
10673
+ partObjects: any[];
10674
+ partsPlaced: string;
10675
+ partsMade: boolean;
10676
+ /** Put the instance with its prefab's origin at a place, turned and sized as the handle is: where a level's
10677
+ * object or level3DSpawn says it goes; the handle of an attached prefab is then at the middle of its body
10678
+ * @param {Vector3} pos3D */
10679
+ placeAt(pos3D: Vector3): void;
10680
+ /** Put the parts where the handle is now, making them the first time; called by the handle's update when it
10681
+ * has moved, turned or changed size */
10682
+ placeParts(): void;
10683
+ placeKey(): string;
10684
+ makeParts(): void;
10685
+ }
10686
+ /** How a level's block map is made: the sheet its blocks show tiles of, and a function to set it up
10687
+ * - A level's voxels block makes a VoxelMap when the level loads, with texture 0 and the default tile size unless
10688
+ * a sheet is given here; a block's type shows that tile of the sheet on every face
10689
+ * - setup is called with each map a level makes, to give block types their own faces or make them see-through
10690
+ * - Call it before level3DLoad; with no arguments the defaults are back
10691
+ * @param {TileInfo} [tileInfo] - The sheet's first tile, as for a VoxelMap
10692
+ * @param {function(VoxelMap): void} [setup]
10693
+ * @example
10694
+ * level3DVoxelSetup(tile(0, 16, 1), (map)=> map.setBlockType(1, {top: 0, side: 1, bottom: 2})); // grass
10695
+ * @memberof Level3D */
10696
+ export function level3DVoxelSetup(tileInfo?: TileInfo, setup?: (arg0: VoxelMap) => void): void;
9678
10697
  /**
9679
10698
  * LittleJS Three.js Plugin
9680
10699
  * - Renders a three.js scene on a canvas behind the LittleJS canvases
@@ -9876,68 +10895,166 @@ declare module "littlejsengine" {
9876
10895
  * @memberof TextureSheets */
9877
10896
  export function spritesReady(): Promise<any>;
9878
10897
  /**
9879
- * LittleJS Level Editor
9880
- * - Paint the game's tile layers while it is paused, then keep playing with the changes
9881
- * - Press 0 while the debug overlay is open to edit, 0 again to play, or call levelEditor.open() and close()
9882
- * - Edits the Tiled map the game loaded, saves it back as Tiled JSON, and autosaves every change
9883
- * - Debug builds only, the release build has stubs for its names in engineRelease.js and none of its code
9884
- * @namespace Editor
9885
- */
9886
- /**
9887
- * @callback EditorPlayFromCallback - Puts the player at a world position, for the level editor's Play from mouse
9888
- * @param {Vector2} pos - Where to start playing
9889
- * @memberof Editor
9890
- */
9891
- /**
9892
- * @callback EditorRestartCallback - Rebuilds the level from the map the level editor changed
9893
- * @memberof Editor
9894
- */
9895
- /**
9896
- * @callback EditorTileCallback - What the game does when the level editor paints a tile
9897
- * @param {TileLayer} layer - The layer painted
9898
- * @param {Vector2} pos - The cell's position in the layer
9899
- * @param {number|undefined} tile - The tile painted, undefined when erased
9900
- * @memberof Editor
9901
- */
9902
- /**
9903
- * The level editor, open it to pause the game and edit its level, close it to play on with the changes
9904
- * - One of it, levelEditor, 0 on the debug overlay opens and closes it too
9905
- * - In release builds levelEditor is a stub that never opens, and its hooks are never called
9906
- * @memberof Editor
9907
- * @example
9908
- * levelEditor.onRestart = ()=> loadLevel(); // adds a Restart button that rebuilds the level
9909
- * levelEditor.onTile = (layer, pos, tile)=> layer.setCollisionData(pos, tile === ladderTile ? -1 : tile ? 1 : 0);
9910
- */
9911
- class LevelEditor {
9912
- /** @property {EditorTileCallback|undefined} - What the game does when the editor paints a tile, like
9913
- * setting its collision or its look the way the game does when it loads the level; without one, the
9914
- * collision layer gets collision 1 where there is a tile
9915
- * @type {EditorTileCallback|undefined} */
9916
- onTile: EditorTileCallback | undefined;
9917
- /** @property {Function|undefined} - Rebuild the level from the map the editor changed, a Restart button
9918
- * calls it after switching to play; without one there is no Restart button
9919
- * @type {EditorRestartCallback|undefined} */
9920
- onRestart: EditorRestartCallback | undefined;
9921
- /** @property {Function|undefined} - Put the player at a world position; with it, the editor's Advanced
9922
- * section has Play from mouse, which starts play there, Escape at the mouse and Play at the view center
9923
- * @type {EditorPlayFromCallback|undefined} */
9924
- onPlayFrom: EditorPlayFromCallback | undefined;
9925
- /** @property {Array<number>|undefined} - The tiles the palette shows, in its order, for a sheet that also holds
9926
- * sprites and art that are not level tiles; undefined shows every tile of the sheet
9927
- * @type {Array<number>|undefined} */
9928
- paletteTiles: Array<number> | undefined;
9929
- /** @property {boolean|undefined} - Which level editor opens: true the 3D one, false the 2D one, undefined the
9930
- * 3D one when a level was loaded with level3DLoad and there is a Render3DPlugin
9931
- * @type {boolean|undefined} */
9932
- use3D: boolean | undefined;
9933
- /** True while the editor is open, the game is paused under it
9934
- * @return {boolean} */
9935
- get isOpen(): boolean;
9936
- /** Open the editor, pausing the game; until close(), Escape (the debug key) switches between playing and editing */
9937
- open(): void;
9938
- /** Close the editor and end its session, the game carries on with the changes and Escape opens the debug
9939
- * overlay again */
9940
- close(): void;
9941
- }
9942
- export {};
10898
+ * LittleJS Particle Effects Plugin
10899
+ * - Ready made particle effects in one line, particleEffect('fire', pos), and particleEffect3D for 3D
10900
+ * - Every built-in effect is tuned around a one unit emitter; options.scale grows it to fit, options.hue and
10901
+ * options.saturation recolor it
10902
+ * - Effects are plain data, {name, settings, behaviors}, the format the particle designer saves: load a library the
10903
+ * designer saved with particleEffectsLoad and play its effects by name
10904
+ * - The built-in effects draw with a sheet of shapes the plugin draws itself, so they need no image
10905
+ * @namespace ParticleEffects
10906
+ */
10907
+ /** The groups the settings are in, in order
10908
+ * @type {Array<string>}
10909
+ * @memberof ParticleEffects */
10910
+ export const particleEffectGroups: Array<string>;
10911
+ /** Every setting an effect has: its name, kind (number, checkbox, color or shape), default, the range the designer's
10912
+ * slider covers (min, max, step), the hard limits a typed value is clamped to, and whether it is set after the
10913
+ * emitter is made rather than passed to its constructor (extra)
10914
+ * @type {Array<{group:string, name:string, kind:string, value:any, min:number, max:number, step:number,
10915
+ * description:string, hardMin:number, hardMax:number, extra:boolean}>}
10916
+ * @memberof ParticleEffects */
10917
+ export const particleEffectSettings: Array<{
10918
+ group: string;
10919
+ name: string;
10920
+ kind: string;
10921
+ value: any;
10922
+ min: number;
10923
+ max: number;
10924
+ step: number;
10925
+ description: string;
10926
+ hardMin: number;
10927
+ hardMax: number;
10928
+ extra: boolean;
10929
+ }>;
10930
+ /** The behaviors an effect can use, each a push applied to every particle every update, with a 2D and a 3D version
10931
+ * @type {Array<{name:string, update:(Function|undefined), update3D:(Function|undefined), min:number, max:number,
10932
+ * value:number, description:string}>}
10933
+ * @memberof ParticleEffects */
10934
+ export const particleEffectBehaviors: Array<{
10935
+ name: string;
10936
+ update: (Function | undefined);
10937
+ update3D: (Function | undefined);
10938
+ min: number;
10939
+ max: number;
10940
+ value: number;
10941
+ description: string;
10942
+ }>;
10943
+ /** Names of the shapes the plugin draws, for an effect's shape setting
10944
+ * @type {Array<string>}
10945
+ * @memberof ParticleEffects */
10946
+ export const particleEffectShapes: Array<string>;
10947
+ /** Any input into a whole effect: missing fields take their defaults, bad ones are dropped or clamped
10948
+ * @param {Object} [raw] - {name, settings, behaviors}, from a library file, the designer or code
10949
+ * @return {{name:string, settings:Object, behaviors:Array<{name:string, strength:number}>}}
10950
+ * @memberof ParticleEffects */
10951
+ export function particleEffectSanitize(raw?: any): {
10952
+ name: string;
10953
+ settings: any;
10954
+ behaviors: {
10955
+ name: string;
10956
+ strength: number;
10957
+ }[];
10958
+ };
10959
+ /** A copy of an effect with its four colors turned around the color wheel and their saturation scaled; lightness and
10960
+ * alpha stay, and grey and white have no hue to turn
10961
+ * @param {Object} effect
10962
+ * @param {number} [hue] - How far around the wheel, 1 is all the way
10963
+ * @param {number} [saturation] - Multiplies the saturation, 0 is grey, clamped to 1
10964
+ * @return {Object}
10965
+ * @memberof ParticleEffects */
10966
+ export function particleEffectRecolor(effect: any, hue?: number, saturation?: number): any;
10967
+ /** Add effects to play by name, sanitized; one with the name of an effect already there replaces it
10968
+ * @param {Array<Object>|Object} effects
10969
+ * @memberof ParticleEffects */
10970
+ export function particleEffectsAdd(effects: Array<any> | any): void;
10971
+ /** The effect with a name, any case, undefined if there is none
10972
+ * @param {string} name
10973
+ * @return {Object|undefined}
10974
+ * @memberof ParticleEffects */
10975
+ export function particleEffectsGet(name: string): any | undefined;
10976
+ /** A library file, or one effect, into sanitized effects; throws on bad input
10977
+ * @param {string} text
10978
+ * @return {Array<Object>}
10979
+ * @memberof ParticleEffects */
10980
+ export function particleEffectsParse(text: string): Array<any>;
10981
+ /** The text of a library file with these effects, what particleEffectsLoad and the designer read
10982
+ * @param {Array<Object>} effects
10983
+ * @return {string}
10984
+ * @memberof ParticleEffects */
10985
+ export function particleEffectsText(effects: Array<any>): string;
10986
+ /** Load a library file the particle designer saved and add its effects
10987
+ * @param {string} url
10988
+ * @return {Promise<Array<Object>>} - The effects it had
10989
+ * @memberof ParticleEffects */
10990
+ export function particleEffectsLoad(url: string): Promise<Array<any>>;
10991
+ /** The tile of a built-in shape, on a sheet the plugin draws once; undefined headless, without a canvas or without
10992
+ * WebGL, where an effect draws untextured squares
10993
+ * @param {string} name - One of particleEffectShapes
10994
+ * @return {TileInfo|undefined}
10995
+ * @memberof ParticleEffects */
10996
+ export function particleEffectShapeTile(name: string): TileInfo | undefined;
10997
+ /** Play an effect: a 2D emitter set to it, placed, scaled and recolored
10998
+ * - A continuous effect (fire, a torch) goes until destroyed or given an emitTime, a one-shot ends itself
10999
+ * - Any setting in the options replaces the effect's own for this play: {emitTime: .5} for a burst of a continuous
11000
+ * effect, {emitTime: 0, emitRate: 30} to keep a one-shot going, or speed, particleTime and the rest
11001
+ * - Attach it to an object with addChild to follow it
11002
+ * @param {string|Object} nameOrEffect - A built-in or added effect's name, or an effect
11003
+ * @param {Vector2} [pos]
11004
+ * @param {Object} [options] - What to change for this play, each left out when not wanted:
11005
+ * scale grows the whole effect, the built-ins fit a one unit object at 1;
11006
+ * hue turns its colors around the color wheel, 1 is all the way;
11007
+ * saturation multiplies its saturation, 0 is grey;
11008
+ * angle is its direction, 0 is up, the effect's own angle when not given;
11009
+ * tileInfo, a TileInfo or a TextureInfo, is the game's own art to draw with in place of the effect's shape,
11010
+ * tinted by its colors, a whole texture drawn as one tile;
11011
+ * and any effect setting by its name, emitTime, emitRate, speed and the rest, replaces the effect's own
11012
+ * @return {ParticleEmitter|undefined} - undefined when there is no such effect
11013
+ * @memberof ParticleEffects */
11014
+ export function particleEffect(nameOrEffect: string | any, pos?: Vector2, options?: any): ParticleEmitter | undefined;
11015
+ /** Play an effect in 3D: a ParticleEmitter3D set to it, placed, scaled and recolored
11016
+ * - The same effect data as particleEffect, so the look carries across: a circle spawn area becomes a sphere and a
11017
+ * rectangle a box as deep as it is wide, both flat across the way it emits with options.flatten, a disc or a
11018
+ * sheet; a trail becomes a streak of the same length, and the settings the 3D emitter lacks (particleConeAngle,
11019
+ * randomColorLinear, velocityInheritance, localSpace) are left out; the stick behavior becomes the emitter's
11020
+ * stick, its grip where a particle lands
11021
+ * @param {string|Object} nameOrEffect - A built-in or added effect's name, or an effect
11022
+ * @param {Vector3} [pos3D]
11023
+ * @param {Object} [options] - scale, hue, saturation, angle, tileInfo and any setting as particleEffect; angle turns it
11024
+ * about z, so 0 is up; flatten makes the spawn area flat across the way it emits
11025
+ * @return {ParticleEmitter3D|undefined} - undefined when there is no such effect
11026
+ * @memberof ParticleEffects */
11027
+ export function particleEffect3D(nameOrEffect: string | any, pos3D?: Vector3, options?: any): ParticleEmitter3D | undefined;
11028
+ /** The names of the built-in effects, in the order a gallery shows them
11029
+ * @type {Array<string>}
11030
+ * @memberof ParticleEffects */
11031
+ export const particleEffectsBuiltIn: Array<string>;
11032
+ /** Set a 2D emitter to an effect, live, so a running one keeps its particles
11033
+ * @param {ParticleEmitter} emitter
11034
+ * @param {Object} effect
11035
+ * @memberof ParticleEffects */
11036
+ export function particleEffectApply(emitter: ParticleEmitter, effect: any): void;
11037
+ /** Set a 3D emitter to an effect, live, so a running one keeps its particles; its place, scale and flatten stay
11038
+ * @param {ParticleEmitter3D} emitter
11039
+ * @param {Object} effect
11040
+ * @memberof ParticleEffects */
11041
+ export function particleEffectApply3D(emitter: ParticleEmitter3D, effect: any): void;
11042
+ /** An effect with a 2D emitter's settings, to save, build again, or build in 3D with particleEffect3D; its tile is
11043
+ * left out, since a hand made emitter's tile is its own texture and not one an effect can name, and so is its
11044
+ * scale, which an effect does not keep: pass it again with options.scale
11045
+ * @param {ParticleEmitter} emitter
11046
+ * @param {string} [name]
11047
+ * @return {Object}
11048
+ * @memberof ParticleEffects */
11049
+ export function particleEffectFromEmitter(emitter: ParticleEmitter, name?: string): any;
11050
+ /** Add a behavior effects can use by name, or replace one
11051
+ * @param {string} name
11052
+ * @param {function(Particle, number): void} update - Pushes a 2D particle, given the strength
11053
+ * @param {function(Particle3D, number): void} [update3D] - The same for a 3D particle, none leaves 3D alone
11054
+ * @param {number} [min] - Strength range the designer offers
11055
+ * @param {number} [max]
11056
+ * @param {number} [value] - Strength when first added
11057
+ * @param {string} [description]
11058
+ * @memberof ParticleEffects */
11059
+ export function particleEffectsAddBehavior(name: string, update: (arg0: Particle, arg1: number) => void, update3D?: (arg0: Particle3D, arg1: number) => void, min?: number, max?: number, value?: number, description?: string): void;
9943
11060
  }