litecanvas 0.63.0 → 0.65.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.
package/types/types.d.ts CHANGED
@@ -42,55 +42,55 @@ type LitecanvasInstance = {
42
42
  /**
43
43
  * Calculates a linear (interpolation) value over t%.
44
44
  *
45
- * @param {number} start
46
- * @param {number} end
47
- * @param {number} t The progress in percentage, where 0 = 0% and 1 = 100%.
48
- * @returns {number} The unterpolated value
45
+ * @param start
46
+ * @param end
47
+ * @param t The progress in percentage, where 0 = 0% and 1 = 100%.
48
+ * @returns The unterpolated value
49
49
  * @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
50
50
  */
51
51
  lerp(start: number, end: number, t: number): number
52
52
  /**
53
53
  * Convert degrees to radians
54
54
  *
55
- * @param {number} degs
56
- * @returns {number} the value in radians
55
+ * @param degs
56
+ * @returns the value in radians
57
57
  */
58
58
  deg2rad(degs: number): number
59
59
  /**
60
60
  * Convert radians to degrees
61
61
  *
62
- * @param {number} rads
63
- * @returns {number} the value in degrees
62
+ * @param rads
63
+ * @returns the value in degrees
64
64
  */
65
65
  rad2deg(rads: number): number
66
66
  /**
67
67
  * Constrains a number between `min` and `max`.
68
68
  *
69
- * @param {number} value
70
- * @param {number} min
71
- * @param {number} max
72
- * @returns {number}
69
+ * @param value
70
+ * @param min
71
+ * @param max
72
+ * @returns
73
73
  */
74
74
  clamp(value: number, min: number, max: number): number
75
75
  /**
76
76
  * Wraps a number between `min` (inclusive) and `max` (exclusive).
77
77
  *
78
- * @param {number} value
79
- * @param {number} min
80
- * @param {number} max
81
- * @returns {number}
78
+ * @param value
79
+ * @param min
80
+ * @param max
81
+ * @returns
82
82
  */
83
83
  wrap(value: number, min: number, max: number): number
84
84
  /**
85
85
  * Re-maps a number from one range to another.
86
86
  *
87
- * @param {number} value the value to be remapped.
88
- * @param {number} min1 lower bound of the value's current range.
89
- * @param {number} max1 upper bound of the value's current range.
90
- * @param {number} min2 lower bound of the value's target range.
91
- * @param {number} max2 upper bound of the value's target range.
92
- * @param {boolean} [withinBounds=false] constrain the value to the newly mapped range
93
- * @returns {number} the remapped number
87
+ * @param value the value to be remapped.
88
+ * @param min1 lower bound of the value's current range.
89
+ * @param max1 upper bound of the value's current range.
90
+ * @param min2 lower bound of the value's target range.
91
+ * @param max2 upper bound of the value's target range.
92
+ * @param [withinBounds=false] constrain the value to the newly mapped range
93
+ * @returns the remapped number
94
94
  */
95
95
  map(
96
96
  value: number,
@@ -105,10 +105,10 @@ type LitecanvasInstance = {
105
105
  * Identical to `map(value, min, max, 0, 1)`.
106
106
  * Note: Numbers outside the range are not clamped to 0 and 1.
107
107
  *
108
- * @param {number} value
109
- * @param {number} min
110
- * @param {number} max
111
- * @returns {number} the normalized number.
108
+ * @param value
109
+ * @param min
110
+ * @param max
111
+ * @returns the normalized number.
112
112
  */
113
113
  norm(value: number, min: number, max: number): number
114
114
  /**
@@ -181,42 +181,37 @@ type LitecanvasInstance = {
181
181
  /**
182
182
  * Generates a pseudorandom float between min (inclusive) and max (exclusive)
183
183
  *
184
- * @param {number} [min=0.0]
185
- * @param {number} [max=1.0]
186
- * @returns {number} the random number
184
+ * @param [min=0.0]
185
+ * @param [max=1.0]
186
+ * @returns the random number
187
187
  */
188
188
  rand(min?: number, max?: number): number
189
189
  /**
190
190
  * Generates a pseudorandom integer between min (inclusive) and max (inclusive)
191
191
  *
192
- * @param {number} [min=0]
193
- * @param {number} [max=1]
194
- * @returns {number} the random number
192
+ * @param [min=0]
193
+ * @param [max=1]
194
+ * @returns the random number
195
195
  */
196
196
  randi(min?: number, max?: number): number
197
- /**
198
- * Returns the fractional part of a number
199
- *
200
- * @param {number} value The number
201
- * @returns {number}
202
- */
203
197
 
204
198
  /** BASIC GRAPHICS API */
205
199
  /**
206
200
  * Clear the game screen
207
201
  *
208
- * @param {number|null} color The background color (from 0 to 7) or null
202
+ * @param color The background color index or `null`
209
203
  */
210
204
  cls(color: number | null): void
205
+
211
206
  /**
212
207
  * Draw a rectangle outline
213
208
  *
214
- * @param {number} x
215
- * @param {number} y
216
- * @param {number} width
217
- * @param {number} height
218
- * @param {number} [color=0] the color index (generally from 0 to 7)
219
- * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
209
+ * @param x
210
+ * @param y
211
+ * @param width
212
+ * @param height
213
+ * @param [color=0] the color index
214
+ * @param [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
220
215
  */
221
216
  rect(
222
217
  x: number,
@@ -229,12 +224,12 @@ type LitecanvasInstance = {
229
224
  /**
230
225
  * Draw a color-filled rectangle
231
226
  *
232
- * @param {number} x
233
- * @param {number} y
234
- * @param {number} width
235
- * @param {number} height
236
- * @param {number} [color=0] the color index (generally from 0 to 7)
237
- * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
227
+ * @param x
228
+ * @param y
229
+ * @param width
230
+ * @param height
231
+ * @param [color=0] the color index
232
+ * @param [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
238
233
  */
239
234
  rectfill(
240
235
  x: number,
@@ -247,81 +242,81 @@ type LitecanvasInstance = {
247
242
  /**
248
243
  * Draw a circle outline
249
244
  *
250
- * @param {number} x
251
- * @param {number} y
252
- * @param {number} radius
253
- * @param {number} [color=0] the color index (generally from 0 to 7)
245
+ * @param x
246
+ * @param y
247
+ * @param radius
248
+ * @param [color=0] the color index
254
249
  */
255
250
  circ(x: number, y: number, radius: number, color?: number): void
256
251
  /**
257
252
  * Draw a color-filled circle
258
253
  *
259
- * @param {number} x
260
- * @param {number} y
261
- * @param {number} radius
262
- * @param {number} [color=0] the color index (generally from 0 to 7)
254
+ * @param x
255
+ * @param y
256
+ * @param radius
257
+ * @param [color=0] the color index
263
258
  */
264
259
  circfill(x: number, y: number, radius: number, color?: number): void
265
260
  /**
266
261
  * Draw a line
267
262
  *
268
- * @param {number} x1
269
- * @param {number} y1
270
- * @param {number} x2
271
- * @param {number} y2
272
- * @param {number} [color=0] the color index (generally from 0 to 7)
263
+ * @param x1
264
+ * @param y1
265
+ * @param x2
266
+ * @param y2
267
+ * @param [color=0] the color index
273
268
  */
274
269
  line(x1: number, y1: number, x2: number, y2: number, color?: number): void
275
270
  /**
276
271
  * Sets the thickness of lines
277
272
  *
278
- * @param {number} value
273
+ * @param value
279
274
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
280
275
  */
281
276
  linewidth(value: number): void
282
277
  /**
283
278
  * Sets the line dash pattern used when drawing lines
284
279
  *
285
- * @param {number|number[]} segments the line dash pattern
286
- * @param {number} [offset=0] the line dash offset, or "phase".
280
+ * @param segments the line dash pattern
281
+ * @param [offset=0] the line dash offset, or "phase".
287
282
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
288
283
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
289
284
  */
290
- linedash(segments: number | number[], offset?: number): void
285
+ linedash(segments: number[], offset?: number): void
291
286
 
292
287
  /** TEXT RENDERING API */
293
288
  /**
294
289
  * Draw text
295
290
  *
296
- * @param {number} x
297
- * @param {number} y
298
- * @param {string} text the text message
299
- * @param {number} [color=3] the color index (generally from 0 to 7)
291
+ * @param x
292
+ * @param y
293
+ * @param text the text message
294
+ * @param [color=3] the color index
300
295
  */
301
296
  text(x: number, y: number, text: string, color?: number): void
302
297
  /**
303
298
  * Set the font family
304
299
  *
305
- * @param {string} fontFamily
300
+ * @param fontFamily
306
301
  */
307
302
  textfont(fontFamily: string): void
308
303
  /**
309
304
  * Set the font size
310
305
  *
311
- * @param {string} size
306
+ * @param size
312
307
  */
313
308
  textsize(size: string): void
314
309
  /**
315
310
  * Sets whether a font should be styled with a normal, italic, or bold.
316
311
  *
317
- * @param {string} style
312
+ * @param style
318
313
  */
319
314
  textstyle(style: string): void
320
315
  /**
321
316
  * Sets the alignment used when drawing texts
322
317
  *
323
- * @param {string} align the horizontal alignment. Possible values: "left", "right", "center", "start" or "end"
324
- * @param {string} baseline the vertical alignment. Possible values: "top", "bottom", "middle", "hanging" or "ideographic"
318
+ * @param align the horizontal alignment. Possible values: "left", "right", "center", "start" or "end"
319
+ * @param baseline the vertical alignment. Possible values: "top", "bottom", "middle", "hanging" or "ideographic"
325
320
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
326
321
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
327
322
  */
@@ -329,9 +324,8 @@ type LitecanvasInstance = {
329
324
  /**
330
325
  * Returns a TextMetrics object that contains information about the measured text (such as its width, for example)
331
326
  *
332
- * @param {string} text
333
- * @param {number} [size]
334
- * @returns {TextMetrics}
327
+ * @param text
328
+ * @param [size]
335
329
  * @see https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics
336
330
  */
337
331
  textmetrics(text: string, size?: number): TextMetrics
@@ -340,9 +334,9 @@ type LitecanvasInstance = {
340
334
  /**
341
335
  * Draw an image
342
336
  *
343
- * @param {number} x
344
- * @param {number} y
345
- * @param {OffscreenCanvas|HTMLImageElement|HTMLCanvasElement} image
337
+ * @param x
338
+ * @param y
339
+ * @param image
346
340
  */
347
341
  image(
348
342
  x: number,
@@ -352,11 +346,10 @@ type LitecanvasInstance = {
352
346
  /**
353
347
  * Creates a offscreen canvas to draw on it
354
348
  *
355
- * @param {number} width
356
- * @param {number} height
357
- * @param {string[]|drawCallback} draw
358
- * @param {{scale?:number}} [options]
359
- * @returns {OffscreenCanvas}
349
+ * @param width
350
+ * @param height
351
+ * @param draw
352
+ * @param [options]
360
353
  * @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
361
354
  */
362
355
  paint(
@@ -372,9 +365,12 @@ type LitecanvasInstance = {
372
365
  /** ADVANCED GRAPHICS API */
373
366
  /**
374
367
  * Get or set the canvas context 2D
368
+ *
369
+ * @param [context] an new canvas context
370
+ * @returns the current canvas context
375
371
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
376
372
  */
377
- ctx(value?: CanvasRenderingContext2D): CanvasRenderingContext2D
373
+ ctx(context?: CanvasRenderingContext2D): CanvasRenderingContext2D
378
374
  /**
379
375
  * saves the current drawing style settings and transformations
380
376
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
@@ -388,31 +384,31 @@ type LitecanvasInstance = {
388
384
  /**
389
385
  * Adds a translation transformation to the current matrix
390
386
  *
391
- * @param {number} x
392
- * @param {number} y
387
+ * @param x
388
+ * @param y
393
389
  */
394
390
  translate(x: number, y: number): void
395
391
  /**
396
392
  * Adds a scaling transformation to the canvas units horizontally and/or vertically.
397
393
  *
398
- * @param {number} x
399
- * @param {number} [y]
394
+ * @param x
395
+ * @param [y]
400
396
  */
401
397
  scale(x: number, y?: number): void
402
398
  /**
403
399
  * Adds a rotation to the transformation matrix
404
400
  *
405
- * @param {number} radians
401
+ * @param radians
406
402
  */
407
403
  rotate(radians: number): void
408
404
  /**
409
- * @param {number} a
410
- * @param {number} b
411
- * @param {number} c
412
- * @param {number} d
413
- * @param {number} e
414
- * @param {number} f
415
- * @param {boolean} [resetFirst=true] `false` to use _ctx.transform(); by default use _ctx.setTransform()
405
+ * @param a
406
+ * @param b
407
+ * @param c
408
+ * @param d
409
+ * @param e
410
+ * @param f
411
+ * @param [resetFirst=true] `false` to use _ctx.transform(); by default use _ctx.setTransform()
416
412
  *
417
413
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform
418
414
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/transform
@@ -429,7 +425,7 @@ type LitecanvasInstance = {
429
425
  /**
430
426
  * Sets the alpha (transparency) value to apply when drawing new shapes and images
431
427
  *
432
- * @param {number} alpha float from 0 to 1 (e.g: 0.5 = 50% transparent)
428
+ * @param alpha float from 0 to 1 (e.g: 0.5 = 50% transparent)
433
429
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
434
430
  */
435
431
  alpha(alpha: number): void
@@ -438,61 +434,40 @@ type LitecanvasInstance = {
438
434
  * path as an argument (creates a copy), or optionally with a string
439
435
  * consisting of SVG path data.
440
436
  *
441
- * @param {Path2D|string} [arg]
442
- * @returns Path2D
437
+ * @param [arg]
443
438
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
444
439
  */
445
440
  path(arg?: Path2D | string): Path2D
446
441
  /**
447
442
  * Fills the current or given path with a given color.
448
443
  *
449
- * @param {number} color
450
- * @param {Path2D} [path]
444
+ * @param color
445
+ * @param [path]
451
446
  */
452
447
  fill(color: number, path?: Path2D): void
453
448
  /**
454
449
  * Outlines the current or given path with a given color.
455
450
  *
456
- * @param {number} color
457
- * @param {Path2D} [path]
451
+ * @param color
452
+ * @param [path]
458
453
  */
459
454
  stroke(color: number, path?: Path2D): void
460
455
  /**
461
- * Create a retangular clipping region.
462
- *
463
- * Note: Clip paths cannot be reverted directly. You must save your
464
- * canvas state using push() before calling cliprect(), and restore it
465
- * once you have finished drawing in the clipped area using pop().
466
- *
467
- * @param {number} x
468
- * @param {number} y
469
- * @param {number} width
470
- * @param {number} height
471
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
472
- */
473
- cliprect(x: number, y: number, width: number, height: number): void
474
- /**
475
- * Create a circular clipping region.
456
+ * Turn given path into a clipping region.
476
457
  *
477
- * Note: Clip paths cannot be reverted directly. You must save your
478
- * canvas state using push() before calling clipcirc(), and restore it
479
- * once you have finished drawing in the clipped area using pop().
480
- *
481
- * @param {number} x
482
- * @param {number} y
483
- * @param {number} radius
458
+ * @param path
484
459
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
485
460
  */
486
- clipcirc(x: number, y: number, radius: number): void
461
+ clip(path: Path2D): void
487
462
 
488
463
  /** SOUND API */
489
464
  /**
490
465
  * Play a sound effects using ZzFX library.
491
466
  * If the first argument is omitted, plays an default sound.
492
467
  *
493
- * @param {number|number[]} [zzfxParams] a ZzFX array of params
494
- * @param {number} [pitchSlide] a value to increment/decrement the pitch
495
- * @param {number} [volumeFactor] the volume factor
468
+ * @param [zzfxParams] a ZzFX array of params
469
+ * @param [pitchSlide=0] a value to increment/decrement the pitch
470
+ * @param [volumeFactor=1] the volume factor
496
471
  * @returns The sound that was played or `false`
497
472
  *
498
473
  * @see https://github.com/KilledByAPixel/ZzFX
@@ -506,14 +481,13 @@ type LitecanvasInstance = {
506
481
  * Set the ZzFX's global volume factor.
507
482
  * Note: use 0 to mute all sound effects.
508
483
  *
509
- * @param {number} value
484
+ * @param value
510
485
  */
511
486
  volume(value: number): void
512
487
 
513
488
  /** UTILS API */
514
489
  /**
515
490
  * Checks if a key is currently pressed in your keyboard.
516
- *
517
491
  * Notes:
518
492
  * - to check the space key use `iskeydown(" ")`.
519
493
  * - you can check if any key is pressed using `iskeydown("any")`.
@@ -525,15 +499,14 @@ type LitecanvasInstance = {
525
499
  /**
526
500
  * Check a collision between two rectangles
527
501
  *
528
- * @param {number} x1 first rectangle position X
529
- * @param {number} y1 first rectangle position Y
530
- * @param {number} w1 first rectangle width
531
- * @param {number} h1 first rectangle height
532
- * @param {number} x2 second rectangle position X
533
- * @param {number} y2 second rectangle position Y
534
- * @param {number} w2 second rectangle width
535
- * @param {number} h2 second rectangle height
536
- * @returns {boolean}
502
+ * @param x1 first rectangle position X
503
+ * @param y1 first rectangle position Y
504
+ * @param w1 first rectangle width
505
+ * @param h1 first rectangle height
506
+ * @param x2 second rectangle position X
507
+ * @param y2 second rectangle position Y
508
+ * @param w2 second rectangle width
509
+ * @param h2 second rectangle height
537
510
  */
538
511
  colrect(
539
512
  x1: number,
@@ -548,13 +521,12 @@ type LitecanvasInstance = {
548
521
  /**
549
522
  * Check a collision between two circles
550
523
  *
551
- * @param {number} x1 first circle position X
552
- * @param {number} y1 first circle position Y
553
- * @param {number} r1 first circle position radius
554
- * @param {number} x2 second circle position X
555
- * @param {number} y2 second circle position Y
556
- * @param {number} r2 second circle position radius
557
- * @returns {boolean}
524
+ * @param x1 first circle position X
525
+ * @param y1 first circle position Y
526
+ * @param r1 first circle position radius
527
+ * @param x2 second circle position X
528
+ * @param y2 second circle position Y
529
+ * @param r2 second circle position radius
558
530
  */
559
531
  colcirc(
560
532
  x1: number,
@@ -564,61 +536,67 @@ type LitecanvasInstance = {
564
536
  y2: number,
565
537
  r2: number
566
538
  ): boolean
567
- /**
568
- * The scale of the game's delta time (dt).
569
- * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
570
- * A value of 0 freezes time and is effectively equivalent to pausing.
571
- *
572
- * @param {number} value
573
- */
574
- timescale(value: number): void
575
539
 
576
540
  /** PLUGINS API */
577
541
  /**
578
542
  * Prepares a plugin to be loaded
579
543
  *
580
- * @param {pluginCallback} callback
544
+ * @param callback
581
545
  */
582
546
  use(callback: pluginCallback): void
583
547
  /**
584
548
  * Add a game loop event listener
585
549
  *
586
- * @param {string} event The game event type
587
- * @param {function} callback the function that is called when the event occurs
588
- * @returns {function?} a function to remove the listener
550
+ * @param event The game event type
551
+ * @param callback the function that is called when the event occurs
552
+ * @returns a function to remove the listener
589
553
  */
590
554
  listen(event: string, callback: Function): Function | null
591
555
  /**
592
556
  * Call all listeners attached to a game event
593
557
  *
594
558
  * @param event The game event type
595
- * @param arg1 any data to be passed over the listeners
596
- * @param arg2 any data to be passed over the listeners
597
- * @param arg3 any data to be passed over the listeners
598
- * @param arg4 any data to be passed over the listeners
559
+ * @param [arg1] any data to be passed over the listeners
560
+ * @param [arg2] any data to be passed over the listeners
561
+ * @param [arg3] any data to be passed over the listeners
562
+ * @param [arg4] any data to be passed over the listeners
599
563
  */
600
- emit(event: string, arg1: any, arg2: any, arg3: any, arg4: any): void
564
+ emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
601
565
  /**
602
566
  * Get the color value
603
567
  *
604
- * @param {number} index The color number
605
- * @returns {string} the color value
568
+ * @param index The color number
569
+ * @returns the color value
606
570
  */
607
571
  getcolor(index: number): string
608
572
  /**
609
573
  * Create or update a instance variable
610
574
  *
611
- * @param {string} key
612
- * @param {any} value
575
+ * @param key
576
+ * @param value
613
577
  */
614
578
  setvar(key: string, value: any): void
615
579
  /**
616
580
  * Resizes the game canvas and emit the "resized" event
617
581
  *
618
- * @param {number} width
619
- * @param {number} height
582
+ * @param width
583
+ * @param height
620
584
  */
621
585
  resize(width: number, height: number): void
586
+ /**
587
+ * The scale of the game's delta time (dt).
588
+ * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
589
+ * A value of 0 freezes time and is effectively equivalent to pausing.
590
+ *
591
+ * @param value
592
+ */
593
+ timescale(value: number): void
594
+ /**
595
+ * Set the target FPS at runtime.
596
+ *
597
+ * @param fps
598
+ */
599
+ setfps(fps: number): void
622
600
  }
623
601
 
624
602
  type LitecanvasOptions = {