littlejsengine 1.22.0 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COPYRIGHT.txt +65 -38
- package/EDITOR.md +359 -0
- package/README.md +12 -7
- package/REFERENCE.md +2314 -0
- package/dist/littlejs.d.ts +640 -100
- package/dist/littlejs.esm.js +3596 -1444
- package/dist/littlejs.esm.min.js +3 -3
- package/dist/littlejs.js +3583 -1444
- package/dist/littlejs.min.js +2 -2
- package/dist/littlejs.release.js +2106 -1355
- package/package.json +4 -3
- package/plugins/gltf.js +29 -13
- package/plugins/lightSystem.js +8 -6
- package/plugins/parallax.js +174 -0
- package/plugins/particleEffects.js +37 -22
- package/plugins/pluginExport.js +8 -0
- package/plugins/postProcess.js +5 -2
- package/plugins/render3d.js +59 -21
- package/plugins/render3dEditor.js +1058 -118
- package/plugins/render3dExtras.js +82 -21
- package/plugins/render3dLevel.js +328 -8
- package/plugins/textureSheet.js +1 -0
- package/plugins/tweenSystem.js +39 -34
- package/plugins/uiSystem.js +7 -3
- package/plugins/zzfxm.js +161 -159
- package/src/engine.js +1 -1
- package/src/engineAudio.js +17 -3
- package/src/engineBuild.mjs +18 -2
- package/src/engineDraw.js +26 -10
- package/src/engineEditor.js +515 -52
- package/src/engineExport.js +5 -0
- package/src/engineInput.js +48 -6
- package/src/engineObject.js +675 -675
- package/src/engineRelease.js +17 -2
- package/src/engineSettings.js +14 -0
- package/src/engineTileLayer.js +2 -1
- package/src/engineUtilities.js +291 -291
- package/src/engineWebGL.js +12 -3
package/dist/littlejs.d.ts
CHANGED
|
@@ -216,6 +216,200 @@ declare module "littlejsengine" {
|
|
|
216
216
|
* - What the game does when the level editor paints a tile
|
|
217
217
|
*/
|
|
218
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
|
+
};
|
|
219
413
|
/**
|
|
220
414
|
* LittleJS - The Tiny Fast JavaScript Game Engine
|
|
221
415
|
* MIT License - Copyright 2021 Frank Force
|
|
@@ -453,7 +647,234 @@ declare module "littlejsengine" {
|
|
|
453
647
|
/** The level editor, levelEditor.open() to edit the level, levelEditor.close() to play on with the changes
|
|
454
648
|
* @type {LevelEditor}
|
|
455
649
|
* @memberof Editor */
|
|
456
|
-
export
|
|
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; it may be async
|
|
820
|
+
* @param {string} text
|
|
821
|
+
* @param {string} fileName
|
|
822
|
+
* @return {boolean|void|Promise<boolean|void>} */
|
|
823
|
+
onSave(text: string, fileName: string): boolean | void | Promise<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;
|
|
457
878
|
/** Asserts if the expression is false, does nothing in release builds
|
|
458
879
|
* Halts execution if the assert fails and throws an error
|
|
459
880
|
* @param {*} assert - any value, the assert fails when it is falsy
|
|
@@ -806,6 +1227,14 @@ declare module "littlejsengine" {
|
|
|
806
1227
|
* @default
|
|
807
1228
|
* @memberof Settings */
|
|
808
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;
|
|
809
1238
|
/** Size of center button if touch gamepad should have start button in the center
|
|
810
1239
|
* - Prevents activating when pressed near virtual stick or face buttons
|
|
811
1240
|
* - When the game is paused, any touch will press the button
|
|
@@ -1096,6 +1525,10 @@ declare module "littlejsengine" {
|
|
|
1096
1525
|
* @param {boolean} passthrough
|
|
1097
1526
|
* @memberof Settings */
|
|
1098
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;
|
|
1099
1532
|
/** Set if touch gamepad should have start button in the center
|
|
1100
1533
|
* - Set size to enable the center button
|
|
1101
1534
|
* - When the game is paused, any touch will press the button
|
|
@@ -2267,6 +2700,11 @@ declare module "littlejsengine" {
|
|
|
2267
2700
|
/** The clip showing now
|
|
2268
2701
|
* @return {SpriteAnimation} */
|
|
2269
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;
|
|
2270
2708
|
/** The tile of the frame showing now
|
|
2271
2709
|
* @return {TileInfo} */
|
|
2272
2710
|
get tileInfo(): TileInfo;
|
|
@@ -2998,6 +3436,12 @@ declare module "littlejsengine" {
|
|
|
2998
3436
|
* @type {number}
|
|
2999
3437
|
* @memberof Input */
|
|
3000
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;
|
|
3001
3445
|
/** True if mouse was inside the document window, set to false when mouse leaves
|
|
3002
3446
|
* @type {boolean}
|
|
3003
3447
|
* @memberof Input */
|
|
@@ -3203,10 +3647,13 @@ declare module "littlejsengine" {
|
|
|
3203
3647
|
* @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
|
|
3204
3648
|
*/
|
|
3205
3649
|
constructor(asset?: string | URL | any[], randomness?: number, range?: number, taper?: number, onloadCallback?: SoundLoadCallback);
|
|
3206
|
-
|
|
3207
|
-
range: number;
|
|
3650
|
+
loadedPercent: number;
|
|
3651
|
+
set range(arg: number);
|
|
3652
|
+
/** World space max range of sound, 0 for no limit; a range that is set is the sound's own, in 3D too
|
|
3653
|
+
* @type {number} */
|
|
3654
|
+
get range(): number;
|
|
3208
3655
|
/** @property {boolean} - No range was given, so it got soundDefaultRange; played in 3D such a sound is heard
|
|
3209
|
-
* to render3D.soundDefaultRange instead, which is further */
|
|
3656
|
+
* to render3D.soundDefaultRange instead, which is further; setting range makes it false */
|
|
3210
3657
|
rangeIsDefault: boolean;
|
|
3211
3658
|
/** @property {number} - At what percentage of range should it start tapering */
|
|
3212
3659
|
taper: number;
|
|
@@ -3223,9 +3670,6 @@ declare module "littlejsengine" {
|
|
|
3223
3670
|
/** @ignore
|
|
3224
3671
|
* @type {Array<Array<number>|Float32Array>|undefined} */
|
|
3225
3672
|
_sampleChannels: Array<Array<number> | Float32Array> | undefined;
|
|
3226
|
-
/** @property {number} - Percentage of this sound currently loaded, sounds
|
|
3227
|
-
* fetched from a url stay at 0 until decoding completes */
|
|
3228
|
-
loadedPercent: number;
|
|
3229
3673
|
/** @property {SoundLoadCallback|undefined} - function to call when sound is loaded
|
|
3230
3674
|
* @type {SoundLoadCallback|undefined} */
|
|
3231
3675
|
onloadCallback: SoundLoadCallback | undefined;
|
|
@@ -3241,6 +3685,7 @@ declare module "littlejsengine" {
|
|
|
3241
3685
|
* playing a sound detaches the buffer's own channel arrays.
|
|
3242
3686
|
* @return {Array<Array<number>|Float32Array>|undefined} */
|
|
3243
3687
|
get sampleChannels(): (number[] | Float32Array)[];
|
|
3688
|
+
rangeValue: number;
|
|
3244
3689
|
/** Move this sound's samples into an audio buffer that every play can share
|
|
3245
3690
|
* Does nothing if there is already a buffer or no samples to build one from */
|
|
3246
3691
|
buildSampleBuffer(): void;
|
|
@@ -4871,6 +5316,8 @@ declare module "littlejsengine" {
|
|
|
4871
5316
|
}
|
|
4872
5317
|
/**
|
|
4873
5318
|
* LittleJS ZzFXM Plugin
|
|
5319
|
+
* - A port of ZzFXM, the Zuper Zmall Zound Zynth music player, by Keith Clark and Frank Force, MIT licensed,
|
|
5320
|
+
* https://github.com/keithclark/ZzFXM; its notice is in COPYRIGHT.txt
|
|
4874
5321
|
* @namespace ZzFXM
|
|
4875
5322
|
*/
|
|
4876
5323
|
/**
|
|
@@ -5304,8 +5751,7 @@ declare module "littlejsengine" {
|
|
|
5304
5751
|
* To end typing in a field, call its stopEditing(), which also fires its onChange and release sound
|
|
5305
5752
|
* @type {UIObject|undefined} */
|
|
5306
5753
|
get keyInputObject(): UIObject;
|
|
5307
|
-
/** Destroy and remove all objects
|
|
5308
|
-
* @memberof UISystem */
|
|
5754
|
+
/** Destroy and remove all objects */
|
|
5309
5755
|
destroyObjects(): void;
|
|
5310
5756
|
/** Get all navigable UI objects sorted by navigationIndex
|
|
5311
5757
|
* @return {Array<UIObject>} */
|
|
@@ -7146,6 +7592,78 @@ declare module "littlejsengine" {
|
|
|
7146
7592
|
* @return {Scene|undefined}
|
|
7147
7593
|
* @memberof SceneSystem */
|
|
7148
7594
|
export function getScene(): Scene | undefined;
|
|
7595
|
+
/**
|
|
7596
|
+
* LittleJS Parallax Plugin
|
|
7597
|
+
* - A background layer that follows the camera by a part of its movement, so it looks far away
|
|
7598
|
+
* - Repeats across the view, so a level of any width has a background
|
|
7599
|
+
* - Draws mountains by default, or anything a game draws into it
|
|
7600
|
+
* @namespace Parallax
|
|
7601
|
+
*/
|
|
7602
|
+
/**
|
|
7603
|
+
* A background layer with parallax: an image that follows the camera by a part of its movement and repeats across
|
|
7604
|
+
* the view, drawn once into a canvas by a function, mountains when none is given
|
|
7605
|
+
* - A far layer has a parallax near 1 and a low renderOrder, a near one a smaller parallax and a higher renderOrder
|
|
7606
|
+
* - The image should meet itself at its left and right edges to repeat without a seam, as the mountains do
|
|
7607
|
+
* @memberof Parallax
|
|
7608
|
+
* @extends CanvasLayer
|
|
7609
|
+
* @example
|
|
7610
|
+
* // three ranges of mountains, the far ones lighter and slower
|
|
7611
|
+
* for (let i = 3; i--;)
|
|
7612
|
+
* new ParallaxLayer(vec2(0, i*2), vec2(40, 20), .9 - i*.2, -1e3 + i,
|
|
7613
|
+
* parallaxMountains(hsl(.6, .3, .7 - i*.2), hsl(.6, .5, .2), i));
|
|
7614
|
+
*
|
|
7615
|
+
* // or draw your own image into the layer
|
|
7616
|
+
* new ParallaxLayer(vec2(), vec2(40, 20), .5, -1e3, (context, size)=>
|
|
7617
|
+
* {
|
|
7618
|
+
* context.fillStyle = '#fff';
|
|
7619
|
+
* context.fillRect(size.x/2 - 20, size.y/2 - 20, 40, 40);
|
|
7620
|
+
* });
|
|
7621
|
+
*/
|
|
7622
|
+
export class ParallaxLayer extends CanvasLayer {
|
|
7623
|
+
/** Create a parallax layer and draw its image
|
|
7624
|
+
* @param {Vector2} [pos] - Where the middle of the image is in the world when the camera is there too
|
|
7625
|
+
* @param {Vector2} [size] - World size of one copy of the image
|
|
7626
|
+
* @param {number|Vector2} [parallax] - How much of the camera's movement it follows, 0 stays with the world
|
|
7627
|
+
* and 1 with the screen, a Vector2 to follow x and y by different amounts
|
|
7628
|
+
* @param {number} [renderOrder] - Low to draw behind the game, far layers lowest
|
|
7629
|
+
* @param {function(OffscreenCanvasRenderingContext2D, Vector2, ParallaxLayer): void} [drawFunction] - Draws
|
|
7630
|
+
* the image, given the canvas context, its size in pixels and the layer; mountains when not given
|
|
7631
|
+
* @param {Vector2} [canvasSize] - Size of the image in pixels */
|
|
7632
|
+
constructor(pos?: Vector2, size?: Vector2, parallax?: number | Vector2, renderOrder?: number, drawFunction?: (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2, arg2: ParallaxLayer) => void, canvasSize?: Vector2);
|
|
7633
|
+
/** @property {Vector2} - How much of the camera's movement it follows on each axis, 0 stays with the world
|
|
7634
|
+
* and 1 with the screen */
|
|
7635
|
+
parallax: Vector2;
|
|
7636
|
+
/** @property {boolean} - Repeat the image across the view, left and right */
|
|
7637
|
+
wrapX: boolean;
|
|
7638
|
+
/** @property {boolean} - Repeat the image up and down the view */
|
|
7639
|
+
wrapY: boolean;
|
|
7640
|
+
/** @property {number} - How much the camera's zoom changes its size on the screen: 1 like the world, 0 not
|
|
7641
|
+
* at all, the same on the screen at any zoom as it is at zoomScale */
|
|
7642
|
+
zoomFollow: number;
|
|
7643
|
+
/** @property {number} - The camera scale its size is given for, used when zoomFollow is under 1 */
|
|
7644
|
+
zoomScale: number;
|
|
7645
|
+
/** @property {function(OffscreenCanvasRenderingContext2D, Vector2, ParallaxLayer): void} - Draws the
|
|
7646
|
+
* image, redraw() after changing it */
|
|
7647
|
+
drawFunction: (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2, arg2: ParallaxLayer) => void;
|
|
7648
|
+
/** Draw the image again with drawFunction, after changing it or what it draws from */
|
|
7649
|
+
redraw(): void;
|
|
7650
|
+
zoomFactor(): number;
|
|
7651
|
+
/** World size one copy of the image is drawn at now, its size unless zoomFollow is under 1
|
|
7652
|
+
* @return {Vector2} */
|
|
7653
|
+
getDrawSize(): Vector2;
|
|
7654
|
+
/** Where each copy of the image is drawn now, in the world: one place, or with wrapping every place that
|
|
7655
|
+
* shows in the view
|
|
7656
|
+
* @return {Array<Vector2>} */
|
|
7657
|
+
getDrawPositions(): Array<Vector2>;
|
|
7658
|
+
}
|
|
7659
|
+
/** A draw function for a ParallaxLayer: a range of mountains across the image, shaded from the color of their
|
|
7660
|
+
* peaks down to the color of their feet, that repeats with no seam
|
|
7661
|
+
* @param {Color} [topColor] - Color at the peaks
|
|
7662
|
+
* @param {Color} [bottomColor] - Color at the bottom of the image
|
|
7663
|
+
* @param {number} [seed] - The same seed gives the same mountains, random when not given
|
|
7664
|
+
* @return {function(OffscreenCanvasRenderingContext2D, Vector2): void}
|
|
7665
|
+
* @memberof Parallax */
|
|
7666
|
+
export function parallaxMountains(topColor?: Color, bottomColor?: Color, seed?: number): (arg0: OffscreenCanvasRenderingContext2D, arg1: Vector2) => void;
|
|
7149
7667
|
/** Grid pathfinder using A* with two optional smoothing passes.
|
|
7150
7668
|
* @memberof PathFinding
|
|
7151
7669
|
* @example
|
|
@@ -8043,6 +8561,7 @@ declare module "littlejsengine" {
|
|
|
8043
8561
|
/** @type {TextureInfo|undefined} */
|
|
8044
8562
|
streamTileInfo: TextureInfo | undefined;
|
|
8045
8563
|
streamState: any;
|
|
8564
|
+
streamUnlit: boolean;
|
|
8046
8565
|
/** @type {Mesh|undefined} */
|
|
8047
8566
|
capture: Mesh | undefined;
|
|
8048
8567
|
/** @type {Array<{distance: number, state: Object, draw: function(): void}>|undefined} */
|
|
@@ -9319,7 +9838,7 @@ declare module "littlejsengine" {
|
|
|
9319
9838
|
* - intensity multiplies the color, above 1 for a light brighter than white
|
|
9320
9839
|
* - radius is a world distance, so scale3D does not change it
|
|
9321
9840
|
* - An alpha, an intensity or a radius of 0 switches it off, and a light that is off takes none of those slots
|
|
9322
|
-
* - Draws nothing
|
|
9841
|
+
* - Draws nothing but its glow, when it has one; add a small emissive mesh if the lamp itself should be seen
|
|
9323
9842
|
* @extends EngineObject3D
|
|
9324
9843
|
* @memberof Render3D
|
|
9325
9844
|
* @example
|
|
@@ -9357,7 +9876,7 @@ declare module "littlejsengine" {
|
|
|
9357
9876
|
* - It shines from its position toward the origin, like a three.js DirectionalLight: only the direction to it
|
|
9358
9877
|
* counts, so moving it or its parent swings the light around; parent it to a sun in the sky and it follows
|
|
9359
9878
|
* - It cannot sit on the origin, since that leaves no direction
|
|
9360
|
-
* -
|
|
9879
|
+
* - It casts no shadow: the sun, render3D.sunDirection, does, or a spotlight set as render3D.shadowLight
|
|
9361
9880
|
* @extends Light3D
|
|
9362
9881
|
* @memberof Render3D
|
|
9363
9882
|
* @example
|
|
@@ -9575,6 +10094,9 @@ declare module "littlejsengine" {
|
|
|
9575
10094
|
trailData: Float32Array | undefined;
|
|
9576
10095
|
/** @property {number} - Trail points kept per particle, from trailTime */
|
|
9577
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;
|
|
9578
10100
|
/** @property {Particle3DCallback|undefined} - Called with each particle as it is made
|
|
9579
10101
|
* @type {Particle3DCallback|undefined} */
|
|
9580
10102
|
particleCreateCallback: Particle3DCallback | undefined;
|
|
@@ -9598,7 +10120,7 @@ declare module "littlejsengine" {
|
|
|
9598
10120
|
/** Spawn one particle now */
|
|
9599
10121
|
emitParticle(): void;
|
|
9600
10122
|
particleCall(callback: any, k: any, level: any, pos: any): any;
|
|
9601
|
-
particleCollide(k: any, x: any, y: any, z: any):
|
|
10123
|
+
particleCollide(k: any, x: any, y: any, z: any): boolean;
|
|
9602
10124
|
}
|
|
9603
10125
|
/**
|
|
9604
10126
|
* Trail3D - A ribbon through where the object has been, thinning and fading with age
|
|
@@ -9689,6 +10211,11 @@ declare module "littlejsengine" {
|
|
|
9689
10211
|
color: Color;
|
|
9690
10212
|
shape: string;
|
|
9691
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;
|
|
9692
10219
|
/** @property {boolean} - Fade out when something is between the camera and the sun */
|
|
9693
10220
|
occlusion: boolean;
|
|
9694
10221
|
/** @property {number} - Seconds the flare takes to fade out or in when the sun is hidden or shows again */
|
|
@@ -9712,7 +10239,13 @@ declare module "littlejsengine" {
|
|
|
9712
10239
|
color: Color;
|
|
9713
10240
|
shape: string;
|
|
9714
10241
|
}>;
|
|
9715
|
-
|
|
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
|
|
9716
10249
|
* @return {Vector2|undefined} */
|
|
9717
10250
|
getSunScreenPos(): Vector2 | undefined;
|
|
9718
10251
|
/** The parts of the flare as they are drawn now: each one's place on the screen, its size in pixels and its
|
|
@@ -9724,7 +10257,8 @@ declare module "littlejsengine" {
|
|
|
9724
10257
|
color: Color;
|
|
9725
10258
|
shape: string;
|
|
9726
10259
|
}>;
|
|
9727
|
-
/** Is something between the camera and the sun: the level, or an object that is not see
|
|
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
|
|
9728
10262
|
* @return {boolean} */
|
|
9729
10263
|
isSunHidden(): boolean;
|
|
9730
10264
|
}
|
|
@@ -10062,7 +10596,10 @@ declare module "littlejsengine" {
|
|
|
10062
10596
|
* returned, see level3DVoxelSetup for its sheet
|
|
10063
10597
|
* - A level may hold a terrain, in a terrain block: pos, its center, size, its size in the world along x and z,
|
|
10064
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
|
|
10065
|
-
* is made a HeightMap, returned with what else was made
|
|
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
|
|
10066
10603
|
* - A level may set the scene too, in a scene block beside its objects: sky, three colors for straight up, the
|
|
10067
10604
|
* horizon and straight down, ambient, how much of them lights the scene, .5 when not given, sunDirection and
|
|
10068
10605
|
* sunColor, fog, its start and end, fogColor, the horizon color when not given, and shadows; what the block
|
|
@@ -10071,9 +10608,85 @@ declare module "littlejsengine" {
|
|
|
10071
10608
|
* @return {Array<any>} - What each object's type made, a function that made nothing is left out
|
|
10072
10609
|
* @memberof Level3D */
|
|
10073
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
|
+
}
|
|
10074
10686
|
/** How a level's block map is made: the sheet its blocks show tiles of, and a function to set it up
|
|
10075
10687
|
* - A level's voxels block makes a VoxelMap when the level loads, with texture 0 and the default tile size unless
|
|
10076
|
-
* a sheet is given here; a block's type shows that tile of the sheet on every face
|
|
10688
|
+
* a sheet is given here; a block's type shows that tile of the sheet on every face; a game that has loaded no
|
|
10689
|
+
* image gets plain blocks, a color for each type
|
|
10077
10690
|
* - setup is called with each map a level makes, to give block types their own faces or make them see-through
|
|
10078
10691
|
* - Call it before level3DLoad; with no arguments the defaults are back
|
|
10079
10692
|
* @param {TileInfo} [tileInfo] - The sheet's first tile, as for a VoxelMap
|
|
@@ -10389,31 +11002,23 @@ declare module "littlejsengine" {
|
|
|
10389
11002
|
* - Attach it to an object with addChild to follow it
|
|
10390
11003
|
* @param {string|Object} nameOrEffect - A built-in or added effect's name, or an effect
|
|
10391
11004
|
* @param {Vector2} [pos]
|
|
10392
|
-
* @param {Object} [options]
|
|
10393
|
-
*
|
|
10394
|
-
*
|
|
10395
|
-
*
|
|
10396
|
-
*
|
|
10397
|
-
*
|
|
10398
|
-
* tinted by its colors
|
|
10399
|
-
*
|
|
10400
|
-
* the effect's own for this play
|
|
11005
|
+
* @param {Object} [options] - What to change for this play, each left out when not wanted:
|
|
11006
|
+
* scale grows the whole effect, the built-ins fit a one unit object at 1;
|
|
11007
|
+
* hue turns its colors around the color wheel, 1 is all the way;
|
|
11008
|
+
* saturation multiplies its saturation, 0 is grey;
|
|
11009
|
+
* angle is its direction, 0 is up, the effect's own angle when not given;
|
|
11010
|
+
* tileInfo, a TileInfo or a TextureInfo, is the game's own art to draw with in place of the effect's shape,
|
|
11011
|
+
* tinted by its colors, a whole texture drawn as one tile;
|
|
11012
|
+
* and any effect setting by its name, emitTime, emitRate, speed and the rest, replaces the effect's own
|
|
10401
11013
|
* @return {ParticleEmitter|undefined} - undefined when there is no such effect
|
|
10402
11014
|
* @memberof ParticleEffects */
|
|
10403
|
-
export function particleEffect(nameOrEffect: string | any, pos?: Vector2, options?:
|
|
10404
|
-
scale?: number;
|
|
10405
|
-
hue?: number;
|
|
10406
|
-
saturation?: number;
|
|
10407
|
-
angle?: number;
|
|
10408
|
-
tileInfo?: TileInfo | TextureInfo;
|
|
10409
|
-
settings?: any;
|
|
10410
|
-
}): ParticleEmitter | undefined;
|
|
11015
|
+
export function particleEffect(nameOrEffect: string | any, pos?: Vector2, options?: any): ParticleEmitter | undefined;
|
|
10411
11016
|
/** Play an effect in 3D: a ParticleEmitter3D set to it, placed, scaled and recolored
|
|
10412
11017
|
* - The same effect data as particleEffect, so the look carries across: a circle spawn area becomes a sphere and a
|
|
10413
11018
|
* rectangle a box as deep as it is wide, both flat across the way it emits with options.flatten, a disc or a
|
|
10414
11019
|
* sheet; a trail becomes a streak of the same length, and the settings the 3D emitter lacks (particleConeAngle,
|
|
10415
|
-
* randomColorLinear, velocityInheritance, localSpace) are left out; the stick behavior becomes the
|
|
10416
|
-
* particle lands
|
|
11020
|
+
* randomColorLinear, velocityInheritance, localSpace) are left out; the stick behavior becomes the emitter's
|
|
11021
|
+
* stick, its grip where a particle lands
|
|
10417
11022
|
* @param {string|Object} nameOrEffect - A built-in or added effect's name, or an effect
|
|
10418
11023
|
* @param {Vector3} [pos3D]
|
|
10419
11024
|
* @param {Object} [options] - scale, hue, saturation, angle, tileInfo and any setting as particleEffect; angle turns it
|
|
@@ -10453,69 +11058,4 @@ declare module "littlejsengine" {
|
|
|
10453
11058
|
* @param {string} [description]
|
|
10454
11059
|
* @memberof ParticleEffects */
|
|
10455
11060
|
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;
|
|
10456
|
-
/**
|
|
10457
|
-
* LittleJS Level Editor
|
|
10458
|
-
* - Paint the game's tile layers while it is paused, then keep playing with the changes
|
|
10459
|
-
* - Press 0 while the debug overlay is open to edit, 0 again to play, or call levelEditor.open() and close()
|
|
10460
|
-
* - Edits the Tiled map the game loaded, saves it back as Tiled JSON, and autosaves every change
|
|
10461
|
-
* - Debug builds only, the release build has stubs for its names in engineRelease.js and none of its code
|
|
10462
|
-
* @namespace Editor
|
|
10463
|
-
*/
|
|
10464
|
-
/**
|
|
10465
|
-
* @callback EditorPlayFromCallback - Puts the player at a world position, for the level editor's Play from mouse
|
|
10466
|
-
* @param {Vector2} pos - Where to start playing
|
|
10467
|
-
* @memberof Editor
|
|
10468
|
-
*/
|
|
10469
|
-
/**
|
|
10470
|
-
* @callback EditorRestartCallback - Rebuilds the level from the map the level editor changed
|
|
10471
|
-
* @memberof Editor
|
|
10472
|
-
*/
|
|
10473
|
-
/**
|
|
10474
|
-
* @callback EditorTileCallback - What the game does when the level editor paints a tile
|
|
10475
|
-
* @param {TileLayer} layer - The layer painted
|
|
10476
|
-
* @param {Vector2} pos - The cell's position in the layer
|
|
10477
|
-
* @param {number|undefined} tile - The tile painted, undefined when erased
|
|
10478
|
-
* @memberof Editor
|
|
10479
|
-
*/
|
|
10480
|
-
/**
|
|
10481
|
-
* The level editor, open it to pause the game and edit its level, close it to play on with the changes
|
|
10482
|
-
* - One of it, levelEditor, 0 on the debug overlay opens and closes it too
|
|
10483
|
-
* - In release builds levelEditor is a stub that never opens, and its hooks are never called
|
|
10484
|
-
* @memberof Editor
|
|
10485
|
-
* @example
|
|
10486
|
-
* levelEditor.onRestart = ()=> loadLevel(); // adds a Restart button that rebuilds the level
|
|
10487
|
-
* levelEditor.onTile = (layer, pos, tile)=> layer.setCollisionData(pos, tile === ladderTile ? -1 : tile ? 1 : 0);
|
|
10488
|
-
*/
|
|
10489
|
-
class LevelEditor {
|
|
10490
|
-
/** @property {EditorTileCallback|undefined} - What the game does when the editor paints a tile, like
|
|
10491
|
-
* setting its collision or its look the way the game does when it loads the level; without one, the
|
|
10492
|
-
* collision layer gets collision 1 where there is a tile
|
|
10493
|
-
* @type {EditorTileCallback|undefined} */
|
|
10494
|
-
onTile: EditorTileCallback | undefined;
|
|
10495
|
-
/** @property {Function|undefined} - Rebuild the level from the map the editor changed, a Restart button
|
|
10496
|
-
* calls it after switching to play; without one there is no Restart button
|
|
10497
|
-
* @type {EditorRestartCallback|undefined} */
|
|
10498
|
-
onRestart: EditorRestartCallback | undefined;
|
|
10499
|
-
/** @property {Function|undefined} - Put the player at a world position; with it, the editor's Advanced
|
|
10500
|
-
* section has Play from mouse, which starts play there, Escape at the mouse and Play at the view center
|
|
10501
|
-
* @type {EditorPlayFromCallback|undefined} */
|
|
10502
|
-
onPlayFrom: EditorPlayFromCallback | undefined;
|
|
10503
|
-
/** @property {Array<number>|undefined} - The tiles the palette shows, in its order, for a sheet that also holds
|
|
10504
|
-
* sprites and art that are not level tiles; undefined shows every tile of the sheet
|
|
10505
|
-
* @type {Array<number>|undefined} */
|
|
10506
|
-
paletteTiles: Array<number> | undefined;
|
|
10507
|
-
/** @property {boolean|undefined} - Which level editor opens: true the 3D one, false the 2D one, undefined the
|
|
10508
|
-
* 3D one when a level was loaded with level3DLoad and there is a Render3DPlugin
|
|
10509
|
-
* @type {boolean|undefined} */
|
|
10510
|
-
use3D: boolean | undefined;
|
|
10511
|
-
/** True while the editor is open, the game is paused under it
|
|
10512
|
-
* @return {boolean} */
|
|
10513
|
-
get isOpen(): boolean;
|
|
10514
|
-
/** Open the editor, pausing the game; until close(), Escape (the debug key) switches between playing and editing */
|
|
10515
|
-
open(): void;
|
|
10516
|
-
/** Close the editor and end its session, the game carries on with the changes and Escape opens the debug
|
|
10517
|
-
* overlay again */
|
|
10518
|
-
close(): void;
|
|
10519
|
-
}
|
|
10520
|
-
export {};
|
|
10521
11061
|
}
|