litecanvas 0.80.0 → 0.81.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import './types'
1
+ import './types.d.ts'
2
2
 
3
3
  /**
4
4
  * The litecanvas constructor
@@ -10,24 +10,22 @@ export default function litecanvas(
10
10
  declare global {
11
11
  function litecanvas(settings?: LitecanvasOptions): LitecanvasInstance
12
12
 
13
- /** The game screen width */
14
- var WIDTH: number
15
- /** The game screen height */
16
- var HEIGHT: number
17
13
  /** The game canvas HTML element */
18
14
  var CANVAS: HTMLCanvasElement
15
+ /** The game screen width */
16
+ var W: number
17
+ /** The game screen height */
18
+ var H: number
19
19
  /** the amount of time (in seconds) since the game started */
20
- var ELAPSED: number
20
+ var T: number
21
21
  /** the center X of the game screen */
22
- var CENTERX: number
22
+ var CX: number
23
23
  /** the center Y of the game screen */
24
- var CENTERY: number
24
+ var CY: number
25
25
  /** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
26
- var MOUSEX: number
26
+ var MX: number
27
27
  /** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */
28
- var MOUSEY: number
29
- /** the default `sfx()` sound */
30
- var DEFAULT_SFX: number[]
28
+ var MY: number
31
29
 
32
30
  /** MATH API */
33
31
  /**
@@ -128,6 +126,20 @@ declare global {
128
126
  * @returns the normalized number.
129
127
  */
130
128
  function norm(value: number, start: number, stop: number): number
129
+ /**
130
+ * Interpolate between 2 values using a periodic function.
131
+ *
132
+ * @param from - the lower bound
133
+ * @param to - the higher bound
134
+ * @param t - the amount
135
+ * @param fn - the periodic function (which default to `Math.sin`)
136
+ */
137
+ function wave(
138
+ from: number,
139
+ to: number,
140
+ t: number,
141
+ fn?: (n: number) => number
142
+ ): number
131
143
  /**
132
144
  * Returns the sine of a number in radians
133
145
  */
@@ -212,13 +224,13 @@ declare global {
212
224
  */
213
225
  function randi(min?: number, max?: number): number
214
226
  /**
215
- * If a value is passed, initializes the random number generator with an explicit seed value.
216
- * Otherwise, returns the current seed state.
227
+ * Initializes the random number generator with an explicit seed value.
228
+ *
229
+ * Note: The seed should be a integer number greater than or equal to zero.
217
230
  *
218
- * @param [value]
219
- * @returns the seed state
231
+ * @param value
220
232
  */
221
- function seed(value?: number): number
233
+ function rseed(value: number): void
222
234
 
223
235
  /** BASIC GRAPHICS API */
224
236
  /**
@@ -348,7 +360,7 @@ declare global {
348
360
  *
349
361
  * @param size
350
362
  */
351
- function textsize(size: string): void
363
+ function textsize(size: number): void
352
364
  /**
353
365
  * Sets the alignment used when drawing texts
354
366
  *
@@ -357,7 +369,10 @@ declare global {
357
369
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
358
370
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
359
371
  */
360
- function textalign(align: string, baseline: string): void
372
+ function textalign(
373
+ align: CanvasTextAlign,
374
+ baseline: CanvasTextBaseline
375
+ ): void
361
376
 
362
377
  /** IMAGE GRAPHICS API */
363
378
  /**
@@ -387,7 +402,7 @@ declare global {
387
402
  drawing: string[] | drawCallback,
388
403
  options?: {
389
404
  scale?: number
390
- canvas?: HTMLCanvasElement | OffscreenCanvas
405
+ canvas?: OffscreenCanvas
391
406
  }
392
407
  ): ImageBitmap
393
408
 
@@ -399,7 +414,9 @@ declare global {
399
414
  * @returns the current canvas context
400
415
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
401
416
  */
402
- function ctx(context?: CanvasRenderingContext2D): CanvasRenderingContext2D
417
+ function ctx(
418
+ context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
419
+ ): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
403
420
  /**
404
421
  * saves the current drawing style settings and transformations
405
422
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
@@ -543,19 +560,18 @@ declare global {
543
560
  arg4?: any
544
561
  ): void
545
562
  /**
546
- * Get the color value
563
+ * Set or reset the color palette
547
564
  *
548
- * @param index The color number
549
- * @returns the color value
565
+ * @param [colors]
550
566
  */
551
- function getcolor(index: number): string
567
+ function pal(colors?: string[]): void
552
568
  /**
553
- * Create or update a instance variable
569
+ * Define or update a instance property
554
570
  *
555
571
  * @param key
556
572
  * @param value
557
573
  */
558
- function setvar(key: string, value: any): void
574
+ function def(key: string, value: any): void
559
575
  /**
560
576
  * The scale of the game's delta time (dt).
561
577
  * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
@@ -565,9 +581,32 @@ declare global {
565
581
  */
566
582
  function timescale(value: number): void
567
583
  /**
568
- * Set the target FPS at runtime.
584
+ * Set the target FPS (frames per second).
569
585
  *
570
586
  * @param fps
571
587
  */
572
- function setfps(fps: number): void
588
+ function framerate(fps: number): void
589
+ /**
590
+ * Returns information about that engine instance.
591
+ *
592
+ * n = 0: the settings passed to that instance
593
+ * n = 1: returns true if the "init" event has already been emitted
594
+ * n = 2: the current ID returned by last requestAnimationFrame
595
+ * n = 3: the current canvas element scale (not the context 2D scale)
596
+ * n = 4: the attached event callbacks
597
+ * n = 5: the current color palette
598
+ * n = 6: the default sound used by `sfx()`
599
+ * n = 7: the current time scale
600
+ * n = 8: the current volume used by ZzFX
601
+ * n = 9: the current RNG state
602
+ *
603
+ * n = any other value: returns undefined
604
+ *
605
+ * @param n
606
+ */
607
+ function stat(n: number): any
608
+ /**
609
+ * Stops the litecanvas instance and remove all event listeners.
610
+ */
611
+ function quit(): void
573
612
  }
package/types/types.d.ts CHANGED
@@ -1,22 +1,20 @@
1
1
  type LitecanvasInstance = {
2
- /** The game screen width */
3
- WIDTH: number
4
- /** The game screen height */
5
- HEIGHT: number
6
2
  /** The game canvas HTML element */
7
3
  CANVAS: HTMLCanvasElement
4
+ /** The game screen width */
5
+ W: number
6
+ /** The game screen height */
7
+ H: number
8
8
  /** the amount of time (in seconds) since the game started */
9
- ELAPSED: number
9
+ T: number
10
10
  /** the center X of the game screen */
11
- CENTERX: number
11
+ CX: number
12
12
  /** the center Y of the game screen */
13
- CENTERY: number
13
+ CY: number
14
14
  /** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
15
- MOUSEX: number
15
+ MX: number
16
16
  /** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */
17
- MOUSEY: number
18
- /** the default `sfx()` sound */
19
- DEFAULT_SFX: number[]
17
+ MY: number
20
18
 
21
19
  /** MATH API */
22
20
  /**
@@ -117,6 +115,20 @@ type LitecanvasInstance = {
117
115
  * @returns the normalized number.
118
116
  */
119
117
  norm(value: number, start: number, stop: number): number
118
+ /**
119
+ * Interpolate between 2 values using a periodic function.
120
+ *
121
+ * @param from - the lower bound
122
+ * @param to - the higher bound
123
+ * @param t - the amount
124
+ * @param fn - the periodic function (which default to `Math.sin`)
125
+ */
126
+ wave(
127
+ from: number,
128
+ to: number,
129
+ t: number,
130
+ fn?: (n: number) => number
131
+ ): number
120
132
  /**
121
133
  * Returns the sine of a number in radians
122
134
  */
@@ -201,13 +213,13 @@ type LitecanvasInstance = {
201
213
  */
202
214
  randi(min?: number, max?: number): number
203
215
  /**
204
- * If a value is passed, initializes the random number generator with an explicit seed value.
205
- * Otherwise, returns the current seed state.
216
+ * Initializes the random number generator with an explicit seed value.
217
+ *
218
+ * Note: The seed should be a integer number greater than or equal to zero.
206
219
  *
207
- * @param [value]
208
- * @returns the seed state
220
+ * @param value
209
221
  */
210
- seed(value?: number): number
222
+ rseed(value: number): void
211
223
 
212
224
  /** BASIC GRAPHICS API */
213
225
  /**
@@ -326,7 +338,7 @@ type LitecanvasInstance = {
326
338
  *
327
339
  * @param size
328
340
  */
329
- textsize(size: string): void
341
+ textsize(size: number): void
330
342
  /**
331
343
  * Sets the alignment used when drawing texts
332
344
  *
@@ -335,7 +347,7 @@ type LitecanvasInstance = {
335
347
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
336
348
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
337
349
  */
338
- textalign(align: string, baseline: string): void
350
+ textalign(align: CanvasTextAlign, baseline: CanvasTextBaseline): void
339
351
 
340
352
  /** IMAGE GRAPHICS API */
341
353
  /**
@@ -365,7 +377,7 @@ type LitecanvasInstance = {
365
377
  drawing: string[] | drawCallback,
366
378
  options?: {
367
379
  scale?: number
368
- canvas?: HTMLCanvasElement | OffscreenCanvas
380
+ canvas?: OffscreenCanvas
369
381
  }
370
382
  ): ImageBitmap
371
383
 
@@ -377,7 +389,9 @@ type LitecanvasInstance = {
377
389
  * @returns the current canvas context
378
390
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
379
391
  */
380
- ctx(context?: CanvasRenderingContext2D): CanvasRenderingContext2D
392
+ ctx(
393
+ context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
394
+ ): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
381
395
  /**
382
396
  * saves the current drawing style settings and transformations
383
397
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
@@ -515,19 +529,18 @@ type LitecanvasInstance = {
515
529
  */
516
530
  emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
517
531
  /**
518
- * Get the color value
532
+ * Define or update a instance property
519
533
  *
520
- * @param index The color number
521
- * @returns the color value
534
+ * @param key
535
+ * @param value
522
536
  */
523
- getcolor(index: number): string
537
+ def(key: string, value: any): void
524
538
  /**
525
- * Create or update a instance variable
539
+ * Set or reset the color palette
526
540
  *
527
- * @param key
528
- * @param value
541
+ * @param [colors]
529
542
  */
530
- setvar(key: string, value: any): void
543
+ pal(colors?: string[]): void
531
544
  /**
532
545
  * The scale of the game's delta time (dt).
533
546
  * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
@@ -537,11 +550,34 @@ type LitecanvasInstance = {
537
550
  */
538
551
  timescale(value: number): void
539
552
  /**
540
- * Set the target FPS at runtime.
553
+ * Set the target FPS (frames per second).
541
554
  *
542
555
  * @param fps
543
556
  */
544
- setfps(fps: number): void
557
+ framerate(fps: number): void
558
+ /**
559
+ * Returns information about that engine instance.
560
+ *
561
+ * n = 0: the settings passed to that instance
562
+ * n = 1: returns true if the "init" event has already been emitted
563
+ * n = 2: the current ID returned by last requestAnimationFrame
564
+ * n = 3: the current canvas element scale (not the context 2D scale)
565
+ * n = 4: the attached event callbacks
566
+ * n = 5: the current color palette
567
+ * n = 6: the default sound used by `sfx()`
568
+ * n = 7: the current time scale
569
+ * n = 8: the current volume used by ZzFX
570
+ * n = 9: the current RNG state
571
+ *
572
+ * n = any other value: returns undefined
573
+ *
574
+ * @param n
575
+ */
576
+ stat(n: number): any
577
+ /**
578
+ * Stops the litecanvas instance and remove all event listeners.
579
+ */
580
+ quit(): void
545
581
  }
546
582
 
547
583
  type LitecanvasOptions = {
@@ -631,19 +667,4 @@ type drawCallback = (
631
667
  context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
632
668
  ) => void
633
669
 
634
- type LitecanvasPluginHelpers = {
635
- /**
636
- * The instance color palette (writable)
637
- */
638
- colors: string[]
639
- /**
640
- * Litecanvas instance settings (read-only)
641
- */
642
- settings: LitecanvasOptions
643
- }
644
-
645
- type pluginCallback = (
646
- instance: LitecanvasInstance,
647
- helpers: LitecanvasPluginHelpers,
648
- config?: any
649
- ) => any
670
+ type pluginCallback = (instance: LitecanvasInstance, config?: any) => any
package/src/types.js DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * @typedef LitecanvasOptions
3
- * @type {object}
4
- * @property {number} [width]
5
- * @property {number} [height]
6
- * @property {boolean} [pauseOnBlur=true]
7
- * @property {boolean} [autoscale=true]
8
- * @property {boolean} [pixelart=false]
9
- * @property {boolean} [antialias=false]
10
- * @property {string} [canvas]
11
- * @property {boolean} [global=true]
12
- * @property {boolean} [tapEvents=true]
13
- * @property {boolean} [keyboardEvents=true]
14
- * @property {boolean} [animate=true]
15
- * @property {LitecanvasGameLoop} [loop]
16
- */
17
-
18
- /**
19
- * @typedef LitecanvasInstance
20
- * @type {object}
21
- */
22
-
23
- /**
24
- * @typedef LitecanvasGameLoop
25
- * @type {object}
26
- * @property {() => void} [init]
27
- * @property {(dt: number) => void} [update]
28
- * @property {() => void} [draw]
29
- * @property {() => void} [resized]
30
- * @property {(tapX: number, tapY: number, tapId: number) => void} [tap]
31
- * @property {(tapX: number, tapY: number, tapId: number) => void} [untap]
32
- * @property {(tapX: number, tapY: number, tapId: number) => void} [tapping]
33
- * @property {(tapX: number, tapY: number, tapId: number) => void} [tapped]
34
- */
35
-
36
- /**
37
- * @callback drawCallback
38
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
39
- * @returns {void}
40
- */
41
-
42
- /**
43
- * @typedef LitecanvasPluginHelpers
44
- * @type {object}
45
- * @property {string[]} colors The instance color palette
46
- * @property {LitecanvasOptions} settings Litecanvas instance settings (read-only)
47
- */
48
-
49
- /**
50
- * @callback pluginCallback
51
- * @param {LitecanvasInstance} instance The litecanvas instance
52
- * @param {LitecanvasPluginHelpers} helpers
53
- * @param {any?} [config] - option plugin configuration
54
- * @returns
55
- */