litecanvas 0.91.0 → 0.92.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/types/index.d.ts CHANGED
@@ -1,597 +1,8 @@
1
- import './types.d.ts'
1
+ import './types'
2
+
3
+ declare module 'litecanvas'
2
4
 
3
5
  /**
4
6
  * The litecanvas constructor
5
7
  */
6
8
  export default function litecanvas(settings?: LitecanvasOptions): LitecanvasInstance
7
-
8
- declare global {
9
- function litecanvas(settings?: LitecanvasOptions): LitecanvasInstance
10
-
11
- /** The game screen width */
12
- var W: number
13
- /** The game screen height */
14
- var H: number
15
- /** the amount of time (in seconds) since the game started */
16
- var T: number
17
- /** The current mouse's horizontal (X) position or -1 (if the mouse was not used or detected) */
18
- var MX: number
19
- /** The current mouse's vertical (Y) position or -1 (if the mouse was not used or detected) */
20
- var MY: number
21
-
22
- /** MATH API */
23
- /**
24
- * The value of the mathematical constant PI (π).
25
- * Approximately 3.14159
26
- */
27
- var PI: number
28
- /**
29
- * Twice the value of the mathematical constant PI (π).
30
- * Approximately 6.28318
31
- *
32
- * Note: TWO_PI radians equals 360°, PI radians equals 180°,
33
- * HALF_PI radians equals 90°, and HALF_PI/2 radians equals 45°.
34
- */
35
- var TWO_PI: number
36
- /**
37
- * Half the value of the mathematical constant PI (π).
38
- * Approximately 1.57079
39
- */
40
- var HALF_PI: number
41
- /**
42
- * Calculates a linear (interpolation) value over t%.
43
- *
44
- * @param start
45
- * @param end
46
- * @param t The progress in percentage, where 0 = 0% and 1 = 100%.
47
- * @returns The unterpolated value
48
- * @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
49
- */
50
- function lerp(start: number, end: number, t: number): number
51
- /**
52
- * Convert degrees to radians
53
- *
54
- * @param degs
55
- * @returns the value in radians
56
- */
57
- function deg2rad(degs: number): number
58
- /**
59
- * Convert radians to degrees
60
- *
61
- * @param rads
62
- * @returns the value in degrees
63
- */
64
- function rad2deg(rads: number): number
65
- /**
66
- * Returns the rounded value of an number to optional precision (number of digits after the decimal point).
67
- *
68
- * @param n number to round.
69
- * @param [precision] number of decimal digits to round to, default is 0.
70
- * @returns the rounded number.
71
- */
72
- function round(n: number, precision?: number): number
73
- /**
74
- * Constrains a number between `min` and `max`.
75
- *
76
- * @param value
77
- * @param min
78
- * @param max
79
- * @returns
80
- */
81
- function clamp(value: number, min: number, max: number): number
82
- /**
83
- * Wraps a number between `min` (inclusive) and `max` (exclusive).
84
- *
85
- * @param value
86
- * @param min
87
- * @param max
88
- * @returns the wrapped number
89
- */
90
- function wrap(value: number, min: number, max: number): number
91
- /**
92
- * Re-maps a number from one range to another.
93
- *
94
- * @param value the value to be remapped.
95
- * @param start1 lower bound of the value's current range.
96
- * @param stop1 upper bound of the value's current range.
97
- * @param start2 lower bound of the value's target range.
98
- * @param stop2 upper bound of the value's target range.
99
- * @param [withinBounds=false] constrain the value to the newly mapped range
100
- * @returns the remapped number
101
- */
102
- function map(
103
- value: number,
104
- start1: number,
105
- stop1: number,
106
- start2: number,
107
- stop2: number,
108
- withinBounds?: boolean
109
- ): number
110
- /**
111
- * Maps a number from one range to a value between 0 and 1.
112
- * Identical to `map(value, min, max, 0, 1)`.
113
- * Note: Numbers outside the range are not clamped to 0 and 1.
114
- *
115
- * @param value
116
- * @param start
117
- * @param stop
118
- * @returns the normalized number.
119
- */
120
- function norm(value: number, start: number, stop: number): number
121
- /**
122
- * Interpolate between 2 values using a periodic function.
123
- *
124
- * @param from - the lower bound
125
- * @param to - the higher bound
126
- * @param t - the value passed to the periodic function
127
- * @param fn= - the periodic function (which default to `Math.sin`)
128
- */
129
- function wave(from: number, to: number, t: number, fn?: (n: number) => number): number
130
- /**
131
- * Returns the sine of a number in radians
132
- */
133
- function sin(n: number): number
134
- /**
135
- * Returns the cosine of a number in radians
136
- */
137
- function cos(n: number): number
138
- /**
139
- * Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y)
140
- */
141
- function atan2(y: number, x: number): number
142
- /**
143
- * Returns the square root of the sum of squares of its arguments.
144
- */
145
- function hypot(...ns: number[]): number
146
- /**
147
- * Returns the tangent of a number in radians.
148
- */
149
- function tan(n: number): number
150
- /**
151
- * Returns the absolute value of a number.
152
- */
153
- function abs(n: number): number
154
- /**
155
- * Always rounds up and returns the smallest integer greater than or equal to a given number.
156
- */
157
- function ceil(n: number): number
158
- /**
159
- * Always rounds down and returns the largest integer less than or equal to a given number.
160
- */
161
- function floor(n: number): number
162
- /**
163
- * Returns the integer part of a number by removing any fractional digits.
164
- */
165
- function trunc(n: number): number
166
- /**
167
- * Returns the smallest of the numbers given as input parameters, or `Infinity` if there are no parameters.
168
- */
169
- function min(...ns: number[]): number
170
- /**
171
- * Returns the largest of the numbers given as input parameters, or `-Infinity` if there are no parameters.
172
- */
173
- function max(...ns: number[]): number
174
- /**
175
- * Returns the value of a base raised to a power.
176
- */
177
- function pow(base: number, exponent: number): number
178
- /**
179
- * Returns the square root of a number.
180
- */
181
- function sqrt(n: number): number
182
- /**
183
- * Returns 1 or -1, indicating the sign of the number passed as argument.
184
- * If the input is 0 or -0, it will be returned as-is.
185
- */
186
- function sign(n: number): number
187
- /**
188
- * Returns the Euler's number raised to the power of a number.
189
- */
190
- function exp(exponent: number): number
191
-
192
- /** RNG API */
193
- /**
194
- * Generates a pseudorandom float between min (inclusive) and max (exclusive)
195
- *
196
- * @param [min=0.0]
197
- * @param [max=1.0]
198
- * @returns the random number
199
- */
200
- function rand(min?: number, max?: number): number
201
- /**
202
- * Generates a pseudorandom integer between min (inclusive) and max (inclusive)
203
- *
204
- * @param [min=0]
205
- * @param [max=1]
206
- * @returns the random number
207
- */
208
- function randi(min?: number, max?: number): number
209
- /**
210
- * Initializes the random number generator with an explicit seed value.
211
- *
212
- * Note: The seed should be a integer number greater than or equal to zero.
213
- *
214
- * @param value
215
- */
216
- function rseed(value: number): void
217
-
218
- /** BASIC GRAPHICS API */
219
- /**
220
- * Clear the game screen with an optional color
221
- *
222
- * @param color The background color index or `null`
223
- */
224
- function cls(color: number | null): void
225
-
226
- /**
227
- * Draw a rectangle outline
228
- *
229
- * @param x
230
- * @param y
231
- * @param width
232
- * @param height
233
- * @param [color=0] the color index
234
- * @param [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
235
- *
236
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
237
- */
238
- function rect(
239
- x: number,
240
- y: number,
241
- width: number,
242
- height: number,
243
- color?: number,
244
- radii?: number | number[]
245
- ): void
246
- /**
247
- * Draw a color-filled rectangle
248
- *
249
- * @param x
250
- * @param y
251
- * @param width
252
- * @param height
253
- * @param [color=0] the color index
254
- * @param [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
255
- */
256
- function rectfill(
257
- x: number,
258
- y: number,
259
- width: number,
260
- height: number,
261
- color?: number,
262
- radii?: number | number[]
263
- ): void
264
- /**
265
- * Draw a circle outline
266
- *
267
- * @param x
268
- * @param y
269
- * @param radius
270
- * @param [color=0] the color index
271
- */
272
- function circ(x: number, y: number, radius: number, color?: number): void
273
- /**
274
- * Draw a color-filled circle
275
- *
276
- * @param x
277
- * @param y
278
- * @param radius
279
- * @param [color=0] the color index
280
- */
281
- function circfill(x: number, y: number, radius: number, color?: number): void
282
- /**
283
- * Draw a ellipse outline
284
- *
285
- * @param x
286
- * @param y
287
- * @param radiusX
288
- * @param radiusY
289
- * @param [color=0] the color index
290
- */
291
- function oval(x: number, y: number, radiusX: number, radiusY: number, color?: number): void
292
- /**
293
- * Draw a color-filled ellipse
294
- *
295
- * @param x
296
- * @param y
297
- * @param radiusX
298
- * @param radiusY
299
- * @param [color=0] the color index
300
- */
301
- function ovalfill(x: number, y: number, radiusX: number, radiusY: number, color?: number): void
302
- /**
303
- * Draw a line
304
- *
305
- * @param x1
306
- * @param y1
307
- * @param x2
308
- * @param y2
309
- * @param [color=0] the color index
310
- */
311
- function line(x1: number, y1: number, x2: number, y2: number, color?: number): void
312
- /**
313
- * Sets the thickness of lines
314
- *
315
- * @param value
316
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
317
- */
318
- function linewidth(value: number): void
319
- /**
320
- * Sets the line dash pattern used when drawing lines
321
- *
322
- * @param segments the line dash pattern
323
- * @param [offset=0] the line dash offset, or "phase".
324
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
325
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
326
- */
327
- function linedash(segments: number[], offset?: number): void
328
-
329
- /** TEXT RENDERING API */
330
- /**
331
- * Draw text
332
- *
333
- * @param x
334
- * @param y
335
- * @param message the text message
336
- * @param [color=3] the color index
337
- * @param [fontStyle="normal"] can be "normal" (default), "italic" and/or "bold"
338
- */
339
- function text(x: number, y: number, message: string, color?: number, fontStyle?: string): void
340
- /**
341
- * Set the font family
342
- *
343
- * @param fontFamily
344
- */
345
- function textfont(fontFamily: string): void
346
- /**
347
- * Set the font size
348
- *
349
- * @param size
350
- */
351
- function textsize(size: number): void
352
- /**
353
- * Sets the alignment used when drawing texts
354
- *
355
- * @param align the horizontal alignment. Possible values: "left", "right", "center", "start" or "end"
356
- * @param baseline the vertical alignment. Possible values: "top", "bottom", "middle", "hanging" or "ideographic"
357
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
358
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
359
- */
360
- function textalign(align: CanvasTextAlign, baseline: CanvasTextBaseline): void
361
-
362
- /** IMAGE GRAPHICS API */
363
- /**
364
- * Draw an image
365
- *
366
- * @param x
367
- * @param y
368
- * @param source
369
- */
370
- function image(
371
- x: number,
372
- y: number,
373
- source: OffscreenCanvas | HTMLImageElement | HTMLCanvasElement
374
- ): void
375
- /**
376
- * Draw in an OffscreenCanvas and returns its image.
377
- *
378
- * @param width
379
- * @param height
380
- * @param drawing
381
- * @param [options]
382
- * @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
383
- */
384
- function paint(
385
- width: number,
386
- height: number,
387
- drawing: string[] | drawCallback,
388
- options?: {
389
- scale?: number
390
- canvas?: OffscreenCanvas
391
- }
392
- ): ImageBitmap
393
-
394
- /** ADVANCED GRAPHICS API */
395
- /**
396
- * Get or set the canvas context 2D
397
- *
398
- * @param [context] an new canvas context
399
- * @returns the current canvas context
400
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
401
- */
402
- function ctx(
403
- context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
404
- ): CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D
405
- /**
406
- * saves the current drawing style settings and transformations
407
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
408
- */
409
- function push(): void
410
- /**
411
- * restores the drawing style settings and transformations
412
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore
413
- */
414
- function pop(): void
415
- /**
416
- * Adds a translation transformation to the current matrix
417
- *
418
- * @param x
419
- * @param y
420
- */
421
- function translate(x: number, y: number): void
422
- /**
423
- * Adds a scaling transformation to the canvas units horizontally and/or vertically.
424
- *
425
- * @param x
426
- * @param [y]
427
- */
428
- function scale(x: number, y?: number): void
429
- /**
430
- * Adds a rotation to the transformation matrix
431
- *
432
- * @param radians
433
- */
434
- function rotate(radians: number): void
435
- /**
436
- * Sets the alpha (transparency) value to apply when drawing new shapes and images
437
- *
438
- * @param value float from 0 to 1 (e.g: 0.5 = 50% transparent)
439
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
440
- */
441
- function alpha(value: number): void
442
- /**
443
- * Fills the current path with a given color.
444
- *
445
- * @param color
446
- */
447
- function fill(color: number): void
448
- /**
449
- * Outlines the current path with a given color.
450
- *
451
- * @param color
452
- */
453
- function stroke(color: number): void
454
- /**
455
- * Turns a path (in the callback) into the current clipping region.
456
- *
457
- * @param callback
458
- * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
459
- */
460
- function clip(callback: clipCallback): void
461
-
462
- /** SOUND API */
463
- /**
464
- * Play a sound effects using ZzFX library.
465
- * If the first argument is omitted, plays an default sound.
466
- *
467
- * @param [zzfxParams] a ZzFX array of params
468
- * @param [pitchSlide=0] a value to increment/decrement the pitch
469
- * @param [volumeFactor=1] the volume factor
470
- * @returns The sound that was played or `false`
471
- *
472
- * @see https://github.com/KilledByAPixel/ZzFX
473
- */
474
- function sfx(
475
- zzfxParams?: number[],
476
- pitchSlide?: number,
477
- volumeFactor?: number
478
- ): number[] | boolean
479
- /**
480
- * Set the ZzFX's global volume factor.
481
- * Note: use 0 to mute all sound effects.
482
- *
483
- * @param value
484
- */
485
- function volume(value: number): void
486
-
487
- /** UTILS API */
488
- /**
489
- * Checks if a which key is pressed on the keyboard.
490
- * Note: use `iskeydown()` to check for any key pressed.
491
- *
492
- * @param key
493
- * @returns `true` if the which key is down
494
- */
495
- function iskeydown(key: string): boolean
496
- /**
497
- * Checks if a which key just got pressed on the keyboard.
498
- * Note: use `iskeypressed()` to check for any key.
499
- *
500
- * @param [key]
501
- * @returns `true` if the which key was pressed
502
- */
503
- function iskeypressed(key: string): boolean
504
-
505
- /** PLUGINS API */
506
- /**
507
- * Returns the canvas
508
- */
509
- function canvas(): HTMLCanvasElement
510
- /**
511
- * Prepares a plugin to be loaded
512
- *
513
- * @param callback
514
- */
515
- function use(callback: pluginCallback): void
516
- /**
517
- * Add a game loop event listener
518
- *
519
- * @param event The game event type
520
- * @param callback the function that is called when the event occurs
521
- * @returns a function to remove the listener
522
- */
523
- function listen(event: string, callback: Function): Function
524
- /**
525
- * Call all listeners attached to a game event
526
- *
527
- * @param event The game event type
528
- * @param [arg1] any data to be passed over the listeners
529
- * @param [arg2] any data to be passed over the listeners
530
- * @param [arg3] any data to be passed over the listeners
531
- * @param [arg4] any data to be passed over the listeners
532
- */
533
- function emit(event: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
534
- /**
535
- * Set or reset the color palette
536
- *
537
- * @param [colors]
538
- */
539
- function pal(colors?: string[]): void
540
- /**
541
- * Define or update a instance property
542
- *
543
- * @param key
544
- * @param value
545
- */
546
- function def(key: string, value: any): void
547
- /**
548
- * The scale of the game's delta time (dt).
549
- * Values higher than 1 increase the speed of time, while values smaller than 1 decrease it.
550
- * A value of 0 freezes time and is effectively equivalent to pausing.
551
- *
552
- * @param value
553
- */
554
- function timescale(value: number): void
555
- /**
556
- * Set the target FPS (frames per second).
557
- *
558
- * @param fps
559
- */
560
- function framerate(fps: number): void
561
- /**
562
- * Returns information about that engine instance.
563
- *
564
- * - n = 0: the settings passed to that instance
565
- * - n = 1: returns true if the "init" event has already been emitted
566
- * - n = 2: the current delta time (dt)
567
- * - n = 3: the current canvas element scale (not the context 2D scale)
568
- * - n = 4: the attached event callbacks
569
- * - n = 5: the current color palette
570
- * - n = 6: the default sound used by `sfx()`
571
- * - n = 7: the current time scale
572
- * - n = 8: the current volume used by ZzFX
573
- * - n = 9: the current RNG state
574
- * - n = 10: the current font size
575
- * - n = 11: the current font family
576
- * - n = *any other value*: probably returns undefined
577
- *
578
- * @param n
579
- */
580
- function stat(n: number): any
581
- /**
582
- * Shutdown the litecanvas instance and remove all event listeners.
583
- */
584
- function quit(): void
585
- /**
586
- * Pauses the engine loop (update & draw).
587
- */
588
- function pause(): void
589
- /**
590
- * Resumes (if paused) the engine loop.
591
- */
592
- function resume(): void
593
- /**
594
- * Returns `true` if the engine loop is paused.
595
- */
596
- function paused(): boolean
597
- }
package/types/types.d.ts CHANGED
@@ -15,7 +15,7 @@ type LitecanvasInstance = {
15
15
  * The value of the mathematical constant PI (π).
16
16
  * Approximately 3.14159
17
17
  */
18
- PI: number
18
+ PI?: number
19
19
  /**
20
20
  * Twice the value of the mathematical constant PI (π).
21
21
  * Approximately 6.28318
@@ -121,64 +121,64 @@ type LitecanvasInstance = {
121
121
  /**
122
122
  * Returns the sine of a number in radians
123
123
  */
124
- sin(n: number): number
124
+ sin?(n: number): number
125
125
  /**
126
126
  * Returns the cosine of a number in radians
127
127
  */
128
- cos(n: number): number
128
+ cos?(n: number): number
129
129
  /**
130
130
  * Returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y)
131
131
  */
132
- atan2(y: number, x: number): number
132
+ atan2?(y: number, x: number): number
133
133
  /**
134
134
  * Returns the square root of the sum of squares of its arguments.
135
135
  */
136
- hypot(...ns: number[]): number
136
+ hypot?(...ns: number[]): number
137
137
  /**
138
138
  * Returns the tangent of a number in radians.
139
139
  */
140
- tan(n: number): number
140
+ tan?(n: number): number
141
141
  /**
142
142
  * Returns the absolute value of a number.
143
143
  */
144
- abs(n: number): number
144
+ abs?(n: number): number
145
145
  /**
146
146
  * Always rounds up and returns the smallest integer greater than or equal to a given number.
147
147
  */
148
- ceil(n: number): number
148
+ ceil?(n: number): number
149
149
  /**
150
150
  * Always rounds down and returns the largest integer less than or equal to a given number.
151
151
  */
152
- floor(n: number): number
152
+ floor?(n: number): number
153
153
  /**
154
154
  * Returns the integer part of a number by removing any fractional digits.
155
155
  */
156
- trunc(n: number): number
156
+ trunc?(n: number): number
157
157
  /**
158
158
  * Returns the smallest of the numbers given as input parameters, or `Infinity` if there are no parameters.
159
159
  */
160
- min(...ns: number[]): number
160
+ min?(...ns: number[]): number
161
161
  /**
162
162
  * Returns the largest of the numbers given as input parameters, or `-Infinity` if there are no parameters.
163
163
  */
164
- max(...ns: number[]): number
164
+ max?(...ns: number[]): number
165
165
  /**
166
166
  * Returns the value of a base raised to a power.
167
167
  */
168
- pow(base: number, exponent: number): number
168
+ pow?(base: number, exponent: number): number
169
169
  /**
170
170
  * Returns the square root of a number.
171
171
  */
172
- sqrt(n: number): number
172
+ sqrt?(n: number): number
173
173
  /**
174
174
  * Returns 1 or -1, indicating the sign of the number passed as argument.
175
175
  * If the input is 0 or -0, it will be returned as-is.
176
176
  */
177
- sign(n: number): number
177
+ sign?(n: number): number
178
178
  /**
179
179
  * Returns the Euler's number raised to the power of a number.
180
180
  */
181
- exp(exponent: number): number
181
+ exp?(exponent: number): number
182
182
 
183
183
  /** RNG API */
184
184
  /**
@@ -479,7 +479,7 @@ type LitecanvasInstance = {
479
479
  * @param key
480
480
  * @returns `true` if the which key is down
481
481
  */
482
- iskeydown(key: string): boolean
482
+ iskeydown?(key: string): boolean
483
483
  /**
484
484
  * Checks if a which key just got pressed on the keyboard.
485
485
  * Note: use `iskeypressed()` to check for any key.
@@ -487,7 +487,7 @@ type LitecanvasInstance = {
487
487
  * @param [key]
488
488
  * @returns `true` if the which key was pressed
489
489
  */
490
- iskeypressed(key: string): boolean
490
+ iskeypressed?(key: string): boolean
491
491
 
492
492
  /** PLUGINS API */
493
493
  /**
@@ -668,3 +668,8 @@ type drawCallback = (context: OffscreenCanvasRenderingContext2D) => void
668
668
  type pluginCallback = (instance: LitecanvasInstance, config?: any) => any
669
669
 
670
670
  type clipCallback = (ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D) => void
671
+
672
+ interface Window {
673
+ zzfxV: number
674
+ ENGINE: LitecanvasInstance | undefined
675
+ }