littlejsengine 1.23.1 → 1.24.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.
@@ -194,6 +194,36 @@ declare module "littlejsengine" {
194
194
  * - Decides whether a particle stops where it hits the level, a filter as in 2D
195
195
  */
196
196
  export type Particle3DCollideCallback = (particle: Particle3D, level: EngineObject3D, pos: Vector3) => boolean | void;
197
+ /**
198
+ * A part of a lens flare
199
+ */
200
+ export type LensFlareElement = {
201
+ /**
202
+ * - Where along the line: 0 the sun, 1 the middle of the screen, 2 as far past it
203
+ */
204
+ at: number;
205
+ /**
206
+ * - How big across, as a part of the screen's height, a vector for a part wider
207
+ * than it is tall
208
+ */
209
+ size: number | Vector2;
210
+ /**
211
+ * - Its color, the alpha how bright
212
+ */
213
+ color: Color;
214
+ /**
215
+ * - glow, disc, ring, hex, streak or star, a glow when left out
216
+ */
217
+ shape?: string;
218
+ /**
219
+ * - A tile of the game's own to draw in place of a shape, best white on clear
220
+ */
221
+ tileInfo?: TileInfo;
222
+ /**
223
+ * - How far it is turned, in radians
224
+ */
225
+ angle?: number;
226
+ };
197
227
  /**
198
228
  * What VoxelMap.raycast finds: how far along the ray, the block's cell and type, and the normal of the face it comes in
199
229
  * through
@@ -3579,7 +3609,7 @@ declare module "littlejsengine" {
3579
3609
  * - 2D spatial audio based on camera position with distance-based falloff
3580
3610
  * - Sound instance management (pause, resume, stop)
3581
3611
  * - Speech synthesis for text-to-speech
3582
- * - Music playback with ZzFXM support
3612
+ * - Music playback from audio files, looping by default
3583
3613
  * - Web Audio API integration with master gain control
3584
3614
  * - Sounds and the master bus can route through effects, see the audio effects plugin
3585
3615
  * @namespace Audio
@@ -4239,6 +4269,10 @@ declare module "littlejsengine" {
4239
4269
  * Load tile layers from exported data
4240
4270
  * - Tiled maps come in as they are, flipped and turned tiles included, from one tileset image (a second tileset's
4241
4271
  * tiles continue its numbering), finite maps in the CSV or array layer format; layer offsets and parallax are not read
4272
+ * - A tileset kept in the map with a margin or a spacing, a sheet with gaps between its tiles, is read where its
4273
+ * tiles are, whatever padding the tile info has; one in a file of its own (a tsx) is not read, pass a tile info
4274
+ * with its padding
4275
+ * - An LDtk level loads through tileLayersFromLDtk, which makes it a map like these
4242
4276
  * - Group layers are flattened in order, each replaced by the layers inside it, so the layer indices
4243
4277
  * (collisionLayer and the returned array) count that flattened list; a group's tint, opacity and
4244
4278
  * visibility carry to the layers inside it
@@ -4253,6 +4287,28 @@ declare module "littlejsengine" {
4253
4287
  * @return {Array<TileCollisionLayer>}
4254
4288
  * @memberof TileLayers */
4255
4289
  export function tileLayersLoad(tileMapData: any, tileInfo?: TileInfo, renderOrder?: number, collisionLayer?: number, draw?: boolean): Array<TileCollisionLayer>;
4290
+ /**
4291
+ * Make a Tiled map of a level of an LDtk project, to load with tileLayersLoad and objectLayersLoad
4292
+ * - Each Tiles, AutoLayer and IntGrid layer is a tile layer, the bottom one first as in Tiled, so the last layer
4293
+ * of the LDtk file is layer 0; where LDtk stacks tiles in a cell, an edge over a fill, each tile over another
4294
+ * goes in a layer of its own just above, named with (2), (3) and so on, so a layer of the first tiles has one
4295
+ * wherever the LDtk layer has any, which makes it the one for collision
4296
+ * - An IntGrid layer with no tiles is a hidden layer of its values, for collision: pass its index as collisionLayer
4297
+ * - An Entities layer is an object layer: an entity's name is its type for objectLayersAddType, it is placed at
4298
+ * its middle, and its Int, Float, Bool, String, Color and FilePath fields are its properties (an enum is a string)
4299
+ * - The tileset is the first tile layer's, with its padding and spacing; give tileLayersLoad a tile info of its image
4300
+ * - The level is in the project file (not saved as separate level files), its layers of one grid size; a layer of
4301
+ * another grid size or another tileset is left out, with a warning in debug builds
4302
+ * - The level editor edits the map this returns, and saves it as a Tiled map
4303
+ * @param {Object} ldtk - The LDtk project, its JSON
4304
+ * @param {number|string} [level] - Which level, by its index or its identifier
4305
+ * @return {Object} - A Tiled map: width, height, tilewidth, tileheight, tilesets and layers
4306
+ * @example
4307
+ * const map = tileLayersFromLDtk(await fetchJSON('world.ldtk'), 'Level_0');
4308
+ * const layers = tileLayersLoad(map, tile(0, 16), 0, 1); // layer 1 is solid
4309
+ * objectLayersLoad(map);
4310
+ * @memberof TileLayers */
4311
+ export function tileLayersFromLDtk(ldtk: any, level?: number | string): any;
4256
4312
  /** Add a type of object, so objectLayersLoad makes one wherever a map's object layer has an object of that type
4257
4313
  * - The name is the object's type in Tiled (its class in Tiled 1.9); it is a string because minified builds
4258
4314
  * rename classes
@@ -5314,58 +5370,6 @@ declare module "littlejsengine" {
5314
5370
  * called by LightSystemPlugin after the lightmap is applied */
5315
5371
  renderGlow(): void;
5316
5372
  }
5317
- /**
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
5321
- * @namespace ZzFXM
5322
- */
5323
- /**
5324
- * Music Object - Stores a zzfx music track for later use
5325
- *
5326
- * <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
5327
- * @extends Sound
5328
- * @memberof ZzFXM
5329
- * @example
5330
- * // create some music
5331
- * const music_example = new ZzFXMusic(
5332
- * [
5333
- * [ // instruments
5334
- * [,0,400] // simple note
5335
- * ],
5336
- * [ // patterns
5337
- * [ // pattern 1
5338
- * [ // channel 0
5339
- * 0, -1, // instrument 0, left speaker
5340
- * 1, 0, 9, 1 // channel notes
5341
- * ],
5342
- * [ // channel 1
5343
- * 0, 1, // instrument 0, right speaker
5344
- * 0, 12, 17, -1 // channel notes
5345
- * ]
5346
- * ],
5347
- * ],
5348
- * [0, 0, 0, 0], // sequence, play pattern 0 four times
5349
- * 90 // BPM
5350
- * ]);
5351
- *
5352
- * // play the music on a loop
5353
- * music_example.playMusic();
5354
- */
5355
- export class ZzFXMusic extends Sound {
5356
- /** Create a music object and cache the zzfx music samples for later use
5357
- * @param {[Array, Array, Array, number?, ...any[]]} zzfxMusic - Array of zzfx music parameters: instruments, patterns, sequence, and an optional BPM; anything after it, like the tracker's metadata, is ignored
5358
- */
5359
- constructor(zzfxMusic: [any[], any[], any[], number?, ...any[]]);
5360
- }
5361
- /** Generate samples for a ZzFM song with given parameters
5362
- * @param {Array} instruments - Array of ZzFX sound parameters
5363
- * @param {Array} patterns - Array of pattern data
5364
- * @param {Array} sequence - Array of pattern indexes
5365
- * @param {number} [BPM] - Playback speed of the song in BPM
5366
- * @return {Array} - Left and right channel sample data
5367
- * @memberof ZzFXM */
5368
- export function zzfxM(instruments: any[], patterns: any[], sequence: any[], BPM?: number): any[];
5369
5373
  /**
5370
5374
  * LittleJS Audio Effects Plugin
5371
5375
  * - Web Audio effects with a wet/dry mix: filter, reverb, delay, distortion, compressor
@@ -8682,8 +8686,8 @@ declare module "littlejsengine" {
8682
8686
  * @return {Vector3|undefined} - undefined when the ray misses the plane */
8683
8687
  screenToGround(screenPos: Vector2, groundHeight?: number, canvasSize?: Vector2): Vector3 | undefined;
8684
8688
  /** Find the nearest object under a screen position or along a ray, for clicking on things
8685
- * - Each object is tested as the box around its mesh in its own space, or a sprite as the quad it draws,
8686
- * not triangle by triangle
8689
+ * - A mesh is hit on its triangles, the ones that face the ray as they are drawn, both sides of a doubleSided
8690
+ * mesh; a sprite is hit as the quad it draws, and a height map or a voxel map on its surface
8687
8691
  * - engineObjectsRaycast3D is the other half of this, every object along a ray instead of the nearest
8688
8692
  * @param {Vector2|Ray3D} from - A screen position like mousePosScreen, or a ray to look along
8689
8693
  * @param {Array<EngineObject>} [objects] - Defaults to every object; only those with a mesh or a sprite count
@@ -9839,10 +9843,12 @@ declare module "littlejsengine" {
9839
9843
  * - radius is a world distance, so scale3D does not change it
9840
9844
  * - An alpha, an intensity or a radius of 0 switches it off, and a light that is off takes none of those slots
9841
9845
  * - Draws nothing but its glow, when it has one; add a small emissive mesh if the lamp itself should be seen
9846
+ * - addFlare gives it a lens flare, see LensFlare3D
9842
9847
  * @extends EngineObject3D
9843
9848
  * @memberof Render3D
9844
9849
  * @example
9845
9850
  * const torch = new Light3D(vec3(0, 3, 0), 10, hsl(.1, 1, .65));
9851
+ * torch.addFlare(); // light in the lens when the torch is in view
9846
9852
  */
9847
9853
  export class Light3D extends EngineObject3D {
9848
9854
  /** Create a point light
@@ -9870,6 +9876,22 @@ declare module "littlejsengine" {
9870
9876
  /** @property {number} - How fast the glow fades from its middle: 1 by default, .5 a wide haze, 2 a tight
9871
9877
  * bright core */
9872
9878
  glowFalloff: number;
9879
+ /** @type {LensFlare3D|undefined} */
9880
+ flareObject: LensFlare3D | undefined;
9881
+ /** Give the light a lens flare, made with the arguments of LensFlare3D, in place of the one it had
9882
+ * @param {number} [size] - Scales every part of it
9883
+ * @param {number} [count] - How many ghosts there are, besides the glow at the light
9884
+ * @param {number} [intensity] - How bright it is
9885
+ * @param {number} [saturation] - How colorful the ghosts are
9886
+ * @return {LensFlare3D} - The flare, to change: light.addFlare().shapes = ['hex'] */
9887
+ addFlare(size?: number, count?: number, intensity?: number, saturation?: number): LensFlare3D;
9888
+ set flare(arg: LensFlare3D);
9889
+ /** The light's lens flare, undefined for none: addFlare makes it, or set a LensFlare3D of your own, and
9890
+ * destroying the flare takes it away
9891
+ * - The flare is the light's: it is attached to the light as its child, so it stays through a scene change
9892
+ * when the light does, and is destroyed with the light or when another takes its place
9893
+ * @type {LensFlare3D|undefined} */
9894
+ get flare(): LensFlare3D;
9873
9895
  }
9874
9896
  /**
9875
9897
  * DirectionalLight3D - A Light3D that shines from far away with no falloff, like sunlight
@@ -10165,16 +10187,31 @@ declare module "littlejsengine" {
10165
10187
  clear(): void;
10166
10188
  worldPos3D: Vector3;
10167
10189
  }
10190
+ /**
10191
+ * A part of a lens flare
10192
+ * @typedef {Object} LensFlareElement
10193
+ * @property {number} at - Where along the line: 0 the sun, 1 the middle of the screen, 2 as far past it
10194
+ * @property {number|Vector2} size - How big across, as a part of the screen's height, a vector for a part wider
10195
+ * than it is tall
10196
+ * @property {Color} color - Its color, the alpha how bright
10197
+ * @property {string} [shape] - glow, disc, ring, hex, streak or star, a glow when left out
10198
+ * @property {TileInfo} [tileInfo] - A tile of the game's own to draw in place of a shape, best white on clear
10199
+ * @property {number} [angle] - How far it is turned, in radians
10200
+ * @memberof Render3D
10201
+ */
10168
10202
  /**
10169
10203
  * LensFlare3D - The sun's lens flare, the old kind: a glow at the sun and a row of discs and rings of different
10170
10204
  * sizes along the line from the sun through the middle of the screen
10171
10205
  * - 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
10206
  * - It follows render3D.sunDirection, and fades out as the sun leaves the screen or goes behind something
10207
+ * - A Light3D gets one of its own with light.addFlare()
10173
10208
  * - 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
10209
+ * with the sun's own color; shapes says what its ghosts are, glowSize and ghostSize how big its parts are; or
10210
+ * give it elements of your own, which may be tiles of the game's
10211
+ * - visible is how much of the sun shows, 0 to 1, eased over fadeTime, there for a game to read; it is 0 while the
10212
+ * sun is off the screen, where nothing is tested
10176
10213
  * - 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
10214
+ * through, each on the triangles of its mesh, see render3D.pick; turn it off with occlusion
10178
10215
  * - It needs WebGL, and it draws nothing in the shadow of renderAfter2D
10179
10216
  * @extends EngineObject3D
10180
10217
  * @memberof Render3D
@@ -10200,67 +10237,73 @@ declare module "littlejsengine" {
10200
10237
  saturation: number;
10201
10238
  /** @property {number} - Picks the arrangement of the ghosts, another seed is another flare */
10202
10239
  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
- }[];
10240
+ /** @property {Array<string>|undefined} - The shapes the ghosts are picked from, glow, disc, ring, hex,
10241
+ * streak or star: ['hex'] makes every ghost a hexagon, and a shape listed twice is picked twice as often;
10242
+ * discs, rings and glows when not set
10243
+ * @type {Array<string>|undefined} */
10244
+ shapes: Array<string> | undefined;
10245
+ /** @property {number} - Scales the glow at the sun, 0 for none */
10246
+ glowSize: number;
10247
+ /** @property {number} - Scales the ghosts */
10248
+ ghostSize: number;
10249
+ /** @property {Array<LensFlareElement>|undefined} - The parts of the flare, to set your own in place of the
10250
+ * ones made from count, seed, saturation, shapes, glowSize and ghostSize
10251
+ * @type {Array<LensFlareElement>|undefined} */
10252
+ elements: Array<LensFlareElement> | undefined;
10214
10253
  /** @property {Light3D|undefined} - A light the flare is of in place of the sun, a lamp or a spotlight: the
10215
10254
  * 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
10255
+ * in front of the light, and a spotlight's shows from inside its beam only; a DirectionalLight3D's is far
10256
+ * away where it shines from, like the sun's; the flare is destroyed when its light is; light.addFlare
10257
+ * sets this
10217
10258
  * @type {Light3D|undefined} */
10218
10259
  light: Light3D | undefined;
10219
10260
  /** @property {boolean} - Fade out when something is between the camera and the sun */
10220
10261
  occlusion: boolean;
10221
10262
  /** @property {number} - Seconds the flare takes to fade out or in when the sun is hidden or shows again */
10222
10263
  fadeTime: number;
10223
- /** @property {number} - How much of the sun shows, 0 hidden or behind the camera to 1 in plain view, eased */
10264
+ /** @property {number} - How much of the sun shows, 0 hidden, off the screen or behind the camera to 1 in
10265
+ * plain view, eased */
10224
10266
  visible: number;
10225
10267
  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
- }>;
10268
+ /** @type {Array<LensFlareElement>} */
10269
+ made: Array<LensFlareElement>;
10270
+ /** The parts of the flare: the elements set by hand, or the ones made from count, seed, saturation, shapes,
10271
+ * glowSize and ghostSize, a glow and a core at the sun and the ghosts, made again when one of those changes
10272
+ * @return {Array<LensFlareElement>} */
10273
+ getElements(): Array<LensFlareElement>;
10242
10274
  flareSource(): {
10243
10275
  direction: Vector3;
10244
10276
  distance: number;
10245
10277
  pos: Vector3;
10246
10278
  };
10279
+ flareLook(): {
10280
+ sun: Vector2;
10281
+ center: Vector2;
10282
+ strength: number;
10283
+ tint: Color;
10284
+ height: number;
10285
+ };
10247
10286
  /** Where the sun, or the flare's light, is on the screen, in pixels like mousePosScreen, undefined when it is
10248
10287
  * behind the camera
10249
10288
  * @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}>} */
10289
+ getScreenPos(): Vector2 | undefined;
10290
+ /** The parts of the flare as they are drawn now: each one's place on the screen, its size in pixels, a vector
10291
+ * when the element's is, and its color, dimmed by how much of the sun shows; empty when there is nothing to draw
10292
+ * @return {Array<{pos: Vector2, size: number|Vector2, color: Color, shape: string|undefined,
10293
+ * tileInfo: TileInfo|undefined, angle: number}>} */
10254
10294
  getScreenElements(): Array<{
10255
10295
  pos: Vector2;
10256
- size: number;
10296
+ size: number | Vector2;
10257
10297
  color: Color;
10258
- shape: string;
10298
+ shape: string | undefined;
10299
+ tileInfo: TileInfo | undefined;
10300
+ angle: number;
10259
10301
  }>;
10260
10302
  /** Is something between the camera and the sun, or the flare's light: the level, or an object that is not see
10261
- * through
10303
+ * through, hit on its triangles as render3D.pick hits it, so a mesh the camera is inside hides nothing unless
10304
+ * it is doubleSided
10262
10305
  * @return {boolean} */
10263
- isSunHidden(): boolean;
10306
+ isHidden(): boolean;
10264
10307
  }
10265
10308
  /**
10266
10309
  * Collect the EngineObject3D objects whose boxes overlap a sphere or a box, the 3D twin of engineObjectsCollect
@@ -10602,8 +10645,9 @@ declare module "littlejsengine" {
10602
10645
  * are added before its objects are made, one the game added itself keeps its place
10603
10646
  * - A level may set the scene too, in a scene block beside its objects: sky, three colors for straight up, the
10604
10647
  * 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
10648
+ * sunColor, fog, its start and end, fogColor, the horizon color when not given, shadows, and lensFlare, the
10649
+ * sun's lens flare; what the block leaves out stays as the game set it, and a level with no block changes
10650
+ * nothing
10607
10651
  * @param {Object} level - The level, the level editor edits this same object
10608
10652
  * @return {Array<any>} - What each object's type made, a function that made nothing is left out
10609
10653
  * @memberof Level3D */