angry-pixel 2.0.19 → 2.0.21

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/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This type represents a dependency class
3
3
  * @public
4
- * @category Core
4
+ * @category Dependency Injection
5
5
  */
6
6
  type DependencyType = {
7
7
  new (...args: any[]): any;
@@ -9,9 +9,14 @@ type DependencyType = {
9
9
  /**
10
10
  * This type represents a dependency name
11
11
  * @public
12
- * @category Core
12
+ * @category Dependency Injection
13
13
  */
14
14
  type DependencyName = string | symbol;
15
+ /**
16
+ * This type represents a property key of a decorator target
17
+ * @public
18
+ * @category Dependency Injection
19
+ */
15
20
  type PropertyKey = string | symbol;
16
21
  declare class Container {
17
22
  private instances;
@@ -372,6 +377,11 @@ declare class Rectangle {
372
377
  * @param min min value
373
378
  * @param max max value
374
379
  * @returns clamped value
380
+ * @example
381
+ * ```js
382
+ * clamp(10, 0, 5); // 5
383
+ * clamp(10, 0, 15); // 10
384
+ * ```
375
385
  */
376
386
  declare const clamp: (value: number, min: number, max: number) => number;
377
387
  /**
@@ -381,6 +391,10 @@ declare const clamp: (value: number, min: number, max: number) => number;
381
391
  * @param min min value
382
392
  * @param max max value
383
393
  * @returns the random int value
394
+ * @example
395
+ * ```js
396
+ * randomInt(0, 10); // 5
397
+ * ```
384
398
  */
385
399
  declare const randomInt: (min: number, max: number) => number;
386
400
  /**
@@ -390,6 +404,11 @@ declare const randomInt: (min: number, max: number) => number;
390
404
  * @param min min value
391
405
  * @param max max value
392
406
  * @returns the random float value
407
+ * @example
408
+ * ```js
409
+ * randomFloat(0, 10); // 5.23
410
+ * randomFloat(0, 10, 4); // 5.2345
411
+ * ```
393
412
  */
394
413
  declare const randomFloat: (min: number, max: number, decimals?: number) => number;
395
414
  /**
@@ -399,6 +418,10 @@ declare const randomFloat: (min: number, max: number, decimals?: number) => numb
399
418
  * @param value the value to round
400
419
  * @param decimals the number of decimals
401
420
  * @returns the rounded value
421
+ * @example
422
+ * ```js
423
+ * fixedRound(5.2345, 2); // 5.23
424
+ * ```
402
425
  */
403
426
  declare const fixedRound: (value: number, decimals: number) => number;
404
427
  /**
@@ -409,6 +432,11 @@ declare const fixedRound: (value: number, decimals: number) => number;
409
432
  * @param end the end value
410
433
  * @param steps the steps to move
411
434
  * @returns number range
435
+ * @example
436
+ * ```js
437
+ * range(0, 5); // [0, 1, 2, 3, 4, 5]
438
+ * range(0, 10, 2); // [0, 2, 4, 6, 8, 10]
439
+ * ```
412
440
  */
413
441
  declare const range: (start: number, end: number, steps?: number) => number[];
414
442
  /**
@@ -419,12 +447,23 @@ declare const range: (start: number, end: number, steps?: number) => number[];
419
447
  * @param min min value
420
448
  * @param max max value
421
449
  * @returns true if the number is between the min and the max, false instead
450
+ * @example
451
+ * ```js
452
+ * between(5, 0, 10); // true
453
+ * between(5, 0, 4); // false
454
+ * ```
422
455
  */
423
456
  declare const between: (value: number, min: number, max: number) => boolean;
424
457
  /**
425
458
  * Converts the given radians to degrees.
426
459
  * @param radians
427
460
  * @returns degrees
461
+ * @category Math
462
+ * @public
463
+ * @example
464
+ * ```js
465
+ * radiansToDegrees(Math.PI); // 180
466
+ * ```
428
467
  */
429
468
  declare const radiansToDegrees: (radians: number) => number;
430
469
  /**
@@ -433,8 +472,35 @@ declare const radiansToDegrees: (radians: number) => number;
433
472
  * @returns radians
434
473
  * @category Math
435
474
  * @public
475
+ * @example
476
+ * ```js
477
+ * degreesToRadians(180); // 3.141592653589793
478
+ * ```
436
479
  */
437
480
  declare const degreesToRadians: (degrees: number) => number;
481
+ /**
482
+ * Convert RGB to HEX as string
483
+ * @param rgb
484
+ * @param prefix default is "#"
485
+ * @returns string
486
+ * @public
487
+ * @category Math
488
+ * @example
489
+ * ```js
490
+ * // default prefix "#"
491
+ * rgbToHex({ r: 255, g: 255, b: 255 }); // #ffffff
492
+ * ```
493
+ * @example
494
+ * ```js
495
+ * // no prefix
496
+ * rgbToHex({ r: 0, g: 255, b: 0 }, ""); // 00ff00
497
+ * ```
498
+ */
499
+ declare const rgbToHex: ({ r, g, b }: {
500
+ r: number;
501
+ g: number;
502
+ b: number;
503
+ }, prefix?: string) => string;
438
504
 
439
505
  /** @internal */
440
506
  interface Shape {
@@ -552,13 +618,13 @@ interface Collider {
552
618
  /**
553
619
  * This type an unique identifier of an Entity
554
620
  * @public
555
- * @category Core
621
+ * @category Entity-Component-System
556
622
  */
557
623
  type Entity = number;
558
624
  /**
559
625
  * This type represents an instance of a component
560
626
  * @public
561
- * @category Core
627
+ * @category Entity-Component-System
562
628
  */
563
629
  type Component = {
564
630
  [key: string]: any;
@@ -566,7 +632,7 @@ type Component = {
566
632
  /**
567
633
  * This type represents a component class
568
634
  * @public
569
- * @category Core
635
+ * @category Entity-Component-System
570
636
  */
571
637
  type ComponentType<T extends Component = Component> = {
572
638
  new (...args: any[]): T;
@@ -574,7 +640,7 @@ type ComponentType<T extends Component = Component> = {
574
640
  /**
575
641
  * This type represents a search result object
576
642
  * @public
577
- * @category Core
643
+ * @category Entity-Component-System
578
644
  */
579
645
  type SearchResult<T extends Component> = {
580
646
  entity: Entity;
@@ -583,7 +649,7 @@ type SearchResult<T extends Component> = {
583
649
  /**
584
650
  * This type represents a search criteria object
585
651
  * @public
586
- * @category Core
652
+ * @category Entity-Component-System
587
653
  */
588
654
  type SearchCriteria = {
589
655
  [key: string]: any;
@@ -592,7 +658,7 @@ type SearchCriteria = {
592
658
  * The EntityManager manages the entities and components.\
593
659
  * It provides the necessary methods for reading and writing entities and components.
594
660
  * @public
595
- * @category Core
661
+ * @category Entity-Component-System
596
662
  */
597
663
  declare class EntityManager {
598
664
  private lastEntityId;
@@ -928,7 +994,7 @@ declare class EntityManager {
928
994
  /**
929
995
  * This interface is used for the creation of system classes. You will have to inject the dependencies you need manully.
930
996
  * @public
931
- * @category Core
997
+ * @category Entity-Component-System
932
998
  * @example
933
999
  * ```typescript
934
1000
  * class PlayerSystem implements System {
@@ -972,7 +1038,7 @@ interface System {
972
1038
  /**
973
1039
  * This type represents a system class
974
1040
  * @public
975
- * @category Core
1041
+ * @category Entity-Component-System
976
1042
  */
977
1043
  type SystemType<T extends System = System> = {
978
1044
  new (...args: any[]): T;
@@ -983,7 +1049,7 @@ type SystemGroup = string | number | symbol;
983
1049
  * The SystemManager manages the systems.\
984
1050
  * It provides the necessary methods for reading and writing systems.
985
1051
  * @public
986
- * @category Core
1052
+ * @category Entity-Component-System
987
1053
  */
988
1054
  declare class SystemManager {
989
1055
  private systems;
@@ -1178,12 +1244,19 @@ interface GameConfig {
1178
1244
  width: number;
1179
1245
  /** Game height */
1180
1246
  height: number;
1181
- /** Enables the debug mode */
1182
- debugEnabled?: boolean;
1183
- /** Color of debug elements, default "#00FF00" (green) */
1184
- debugColor?: string;
1185
- /** Position of debug text, default "bottom-left" */
1186
- debugTextPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
1247
+ /** Debug options */
1248
+ debug?: {
1249
+ /** Show colliders */
1250
+ colliders: boolean;
1251
+ /** Show mouse position */
1252
+ mousePosition: boolean;
1253
+ /** Color of the colliders, default "#00FF00" (green) */
1254
+ collidersColor?: string;
1255
+ /** Color of the text, default "#00FF00" (green) */
1256
+ textColor?: string;
1257
+ /** Position of debug text, default "bottom-left" */
1258
+ textPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
1259
+ };
1187
1260
  /** Background color of canvas, default "#000000" (black) */
1188
1261
  canvasColor?: string;
1189
1262
  /** Framerate for physics execution. The allowed values are 60, 120, 180, 240.
@@ -1315,6 +1388,11 @@ declare class AssetManager {
1315
1388
  private createAsset;
1316
1389
  }
1317
1390
 
1391
+ /**
1392
+ * Options for setting an interval.
1393
+ * @public
1394
+ * @category Managers
1395
+ */
1318
1396
  type IntervalOptions = {
1319
1397
  callback: () => void;
1320
1398
  delay: number;
@@ -1668,7 +1746,7 @@ interface AudioPlayerOptions {
1668
1746
  * @category Components
1669
1747
  */
1670
1748
  declare class AudioPlayer {
1671
- /** The action to perform with the audio source. */
1749
+ /** The action to perform with the audio source. This action will be erased at the end of the frame */
1672
1750
  action: AudioPlayerAction;
1673
1751
  /** The audio source to play. */
1674
1752
  audioSource: HTMLAudioElement;
@@ -1676,12 +1754,18 @@ declare class AudioPlayer {
1676
1754
  fixedToTimeScale: boolean;
1677
1755
  /** TRUE If the audio source should loop. */
1678
1756
  loop: boolean;
1679
- /** READONLY, TRUE If the audio source is playing. */
1680
- playing: boolean;
1757
+ /** READONLY, The current state of the audio source. */
1758
+ state: AudioPlayerState;
1681
1759
  /** The volume of the audio source. */
1682
1760
  volume: number;
1761
+ /** READONLY, TRUE If the audio source is playing. */
1762
+ get playing(): boolean;
1763
+ /** READONLY, TRUE If the audio source is paused. */
1764
+ get paused(): boolean;
1765
+ /** READONLY, TRUE If the audio source is stopped. */
1766
+ get stopped(): boolean;
1683
1767
  /** @internal */
1684
- _currentAudioSrc: string;
1768
+ _currentAudioSource: HTMLAudioElement;
1685
1769
  _playPromisePendind: boolean;
1686
1770
  constructor(options?: Partial<AudioPlayerOptions>);
1687
1771
  /**
@@ -1702,6 +1786,11 @@ declare class AudioPlayer {
1702
1786
  * @category Components
1703
1787
  */
1704
1788
  type AudioPlayerAction = "stop" | "play" | "pause";
1789
+ /**
1790
+ * @public
1791
+ * @category Components
1792
+ */
1793
+ type AudioPlayerState = "stopped" | "playing" | "paused";
1705
1794
 
1706
1795
  /**
1707
1796
  * @public
@@ -3615,6 +3704,52 @@ declare function gamePreRenderSystem(): (target: SystemType) => void;
3615
3704
  */
3616
3705
  declare function decorate(decorator: (...args: any[]) => any, target: any, propertyKey?: string | symbol | number): void;
3617
3706
 
3707
+ /**
3708
+ * Options for playSfx function.
3709
+ * @public
3710
+ * @category Audio
3711
+ */
3712
+ interface PlaySfxOptions {
3713
+ audioSource: HTMLAudioElement;
3714
+ volume?: number;
3715
+ loop?: boolean;
3716
+ }
3717
+ /**
3718
+ * This funciton is ideal to play one-shot sound effects. It will play the sound effect from the beginning, even if it's already playing.\
3719
+ * You can also use this function to play audio tracks, but it is recommended to use the AudioPlayer component for this. The AudioPlayer component can handle the browser's autoplay policy and other audio-related functions.
3720
+ * @param playSfxOptions - The options for playing the sound effect.
3721
+ * @public
3722
+ * @category Audio
3723
+ * @example
3724
+ * ```javascript
3725
+ * const audioSource = this.assetManager.getAudio("audio/sfx/coin.ogg");
3726
+ * playSfx({ audioSource });
3727
+ * ```
3728
+ * @example
3729
+ * ```javascript
3730
+ * const audioSource = this.assetManager.getAudio("audio/sfx/coin.ogg");
3731
+ * playSfx({ audioSource, volume: 0.5 });
3732
+ * ```
3733
+ * @example
3734
+ * ```javascript
3735
+ * const audioSource = this.assetManager.getAudio("audio/sfx/coin.ogg");
3736
+ * playSfx({ audioSource, loop: true });
3737
+ * ```
3738
+ */
3739
+ declare const playSfx: ({ audioSource, volume, loop }: PlaySfxOptions) => void;
3740
+ /**
3741
+ * Stop a sound effect.
3742
+ * @param audioSource - The audio source to stop.
3743
+ * @public
3744
+ * @category Audio
3745
+ * @example
3746
+ * ```javascript
3747
+ * const audioSource = this.assetManager.getAudio("audio/sfx/coin.ogg");
3748
+ * stopSfx(audioSource);
3749
+ * ```
3750
+ */
3751
+ declare const stopSfx: (audioSource: HTMLAudioElement) => void;
3752
+
3618
3753
  /**
3619
3754
  * Symbols to be used as dependency identifiers
3620
3755
  * @public
@@ -3632,4 +3767,4 @@ declare const Symbols: {
3632
3767
  TimeManager: symbol;
3633
3768
  };
3634
3769
 
3635
- export { Animation, type AnimationSlice, Animator, type AnimatorOptions, AssetManager, AudioPlayer, type AudioPlayerAction, type AudioPlayerOptions, BallCollider, type BallColliderOptions, BoxCollider, type BoxColliderOptions, BroadPhaseMethods, Button, type ButtonOptions, ButtonShape, Camera, type CameraOptions, Children, type Chunk, Circumference, type Collider, type Collision, type CollisionMatrix, CollisionMethods, CollisionRepository, type CollisionResolution, type Component, type ComponentType, type DependencyName, type DependencyType, EdgeCollider, type EdgeColliderOptions, type Entity, EntityManager, Game, type GameConfig, GameSystem, GamepadController, InputManager, type IntervalOptions, Keyboard, LightRenderer, type LightRendererOptions, MaskRenderer, type MaskRendererOptions, MaskShape, Mouse, Parent, Polygon, PolygonCollider, type PolygonColliderOptions, Rectangle, RigidBody, type RigidBodyOptions, RigidBodyType, Scene, SceneManager, type SceneType, type SearchCriteria, type SearchResult, ShadowRenderer, type ShadowRendererOptions, type Shape, type Slice, SpriteRenderer, type SpriteRendererOptions, Symbols, type System, type SystemGroup, SystemManager, type SystemType, TextOrientation, TextRenderer, type TextRendererOptions, type TiledChunk, type TiledLayer, type TiledObject, type TiledObjectLayer, type TiledProperty, type TiledTilemap, TiledWrapper, type TiledWrapperOptions, TilemapCollider, type TilemapColliderOptions, TilemapOrientation, TilemapRenderer, type TilemapRendererOptions, type Tileset, TimeManager, type TouchInteraction, TouchScreen, Transform, type TransformOptions, Vector2, type VibrationInput, VideoRenderer, type VideoRendererOptions, between, clamp, debugRenderLayer, decorate, defaultRenderLayer, defaultTextureAtlasOptions, degreesToRadians, fixedRound, gameLogicSystem, gamePhysicsSystem, gamePreRenderSystem, inject, injectable, radiansToDegrees, randomFloat, randomInt, range };
3770
+ export { Animation, type AnimationSlice, Animator, type AnimatorOptions, AssetManager, AudioPlayer, type AudioPlayerAction, type AudioPlayerOptions, type AudioPlayerState, BallCollider, type BallColliderOptions, BoxCollider, type BoxColliderOptions, BroadPhaseMethods, Button, type ButtonOptions, ButtonShape, Camera, type CameraOptions, Children, type Chunk, Circumference, type Collider, type Collision, type CollisionMatrix, CollisionMethods, CollisionRepository, type CollisionResolution, type Component, type ComponentType, type DependencyName, type DependencyType, EdgeCollider, type EdgeColliderOptions, type Entity, EntityManager, Game, type GameConfig, GameSystem, GamepadController, InputManager, type IntervalOptions, Keyboard, LightRenderer, type LightRendererOptions, MaskRenderer, type MaskRendererOptions, MaskShape, Mouse, Parent, type PlaySfxOptions, Polygon, PolygonCollider, type PolygonColliderOptions, type PropertyKey, Rectangle, RigidBody, type RigidBodyOptions, RigidBodyType, Scene, SceneManager, type SceneType, type SearchCriteria, type SearchResult, ShadowRenderer, type ShadowRendererOptions, type Shape, type Slice, SpriteRenderer, type SpriteRendererOptions, Symbols, type System, type SystemGroup, SystemManager, type SystemType, TextOrientation, TextRenderer, type TextRendererOptions, type TiledChunk, type TiledLayer, type TiledObject, type TiledObjectLayer, type TiledProperty, type TiledTilemap, TiledWrapper, type TiledWrapperOptions, TilemapCollider, type TilemapColliderOptions, TilemapOrientation, TilemapRenderer, type TilemapRendererOptions, type Tileset, TimeManager, type TouchInteraction, TouchScreen, Transform, type TransformOptions, Vector2, type VibrationInput, VideoRenderer, type VideoRendererOptions, between, clamp, debugRenderLayer, decorate, defaultRenderLayer, defaultTextureAtlasOptions, degreesToRadians, fixedRound, gameLogicSystem, gamePhysicsSystem, gamePreRenderSystem, inject, injectable, playSfx, radiansToDegrees, randomFloat, randomInt, range, rgbToHex, stopSfx };