angry-pixel 2.3.7 → 2.4.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/lib/index.d.ts CHANGED
@@ -574,6 +574,7 @@ declare class Polygon implements Shape {
574
574
  layer: string;
575
575
  position: Vector2;
576
576
  projectionAxes: Vector2[];
577
+ edgeNormals: Vector2[];
577
578
  radius: number;
578
579
  vertices: Vector2[];
579
580
  updateCollisions: boolean;
@@ -771,11 +772,24 @@ type Archetype = {
771
772
  /** Whether the entity starts enabled. Defaults to `true`. Set to `false` to disable the entity on creation. */
772
773
  enabled?: boolean;
773
774
  };
775
+ /**
776
+ * Options for the `removeAllEntities` method of the EntityManager
777
+ * @public
778
+ * @category Entity-Component-System
779
+ * @example
780
+ * ```js
781
+ * entityManager.removeAllEntities({ preserveEntitiesWithComponent: DontDestroy });
782
+ * ```
783
+ */
784
+ type RemoveAllEntitiesOptions = {
785
+ /** The entities that have a component of this type are preserved instead of being removed */
786
+ preserveEntitiesWithComponent: ComponentType;
787
+ };
774
788
  /**
775
789
  * This interface defines the core structure for system classes in the ECS architecture.\
776
790
  * Systems contain the game logic that operates on entities and their components.\
777
791
  * Dependencies like EntityManager can be injected using dependency injection decorators.\
778
- * Systems must implement onUpdate() and can optionally implement lifecycle hooks like onCreate(), onDestroy(), onEnabled() and onDisabled().
792
+ * Systems must implement onUpdate().
779
793
  * @public
780
794
  * @category Entity-Component-System
781
795
  * @example
@@ -792,26 +806,6 @@ type Archetype = {
792
806
  * ```
793
807
  */
794
808
  interface System {
795
- /**
796
- * This method is called the first time the system is enabled
797
- * @public
798
- */
799
- onCreate?(): void;
800
- /**
801
- * This method is called when the system is destroyed
802
- * @public
803
- */
804
- onDestroy?(): void;
805
- /**
806
- * This method is called when the system is disabled
807
- * @public
808
- */
809
- onDisabled?(): void;
810
- /**
811
- * This method is called when the system is enabled
812
- * @public
813
- */
814
- onEnabled?(): void;
815
809
  /**
816
810
  * This method is called once every frame
817
811
  * @public
@@ -988,18 +982,18 @@ declare class EntityManager {
988
982
  removeEntity(entity: Entity): void;
989
983
  /**
990
984
  * Removes all Entities and all their Components
991
- * @param preserveComponentType Optional component type to preserve entities that have this component
985
+ * @param options Optional options object. See {@link RemoveAllEntitiesOptions}
992
986
  * @public
993
987
  * @example
994
988
  * ```js
995
989
  * // Remove all entities
996
990
  * entityManager.removeAllEntities();
997
991
  *
998
- * // Remove all entities except those that have a SpriteRenderer component
999
- * entityManager.removeAllEntities(SpriteRenderer);
992
+ * // Remove all entities except those that have a component of type DontDestroy
993
+ * entityManager.removeAllEntities({ preserveEntitiesWithComponent: DontDestroy });
1000
994
  * ```
1001
995
  */
1002
- removeAllEntities(preserveComponentType?: ComponentType): void;
996
+ removeAllEntities(options?: RemoveAllEntitiesOptions): void;
1003
997
  /**
1004
998
  * If the Entity exists, returns TRUE, otherwise it returns FALSE
1005
999
  * @param entity
@@ -1463,8 +1457,7 @@ declare class SystemManager {
1463
1457
  */
1464
1458
  groupHasSystems(group: SystemGroup): boolean;
1465
1459
  /**
1466
- * Enables a system by its type.\
1467
- * The method `onEnabled` of the system will be called. If the system is enabled for the first time, the method `onCreate` will also be called.
1460
+ * Enables a system by its type.
1468
1461
  * @param systemType The system class
1469
1462
  * @public
1470
1463
  * @example
@@ -1474,8 +1467,7 @@ declare class SystemManager {
1474
1467
  */
1475
1468
  enableSystem(systemType: SystemType): void;
1476
1469
  /**
1477
- * Disables a system by its type.\
1478
- * The method `onDisabled` of the system will be called.
1470
+ * Disables a system by its type.
1479
1471
  * @param systemType The system class
1480
1472
  * @public
1481
1473
  * @example
@@ -1493,7 +1485,6 @@ declare class SystemManager {
1493
1485
  setExecutionOrder(systemType: SystemType, position: number): void;
1494
1486
  /**
1495
1487
  * Removes a system by its type.
1496
- * The method `onDestroy` of the system will be called.
1497
1488
  * @param systemType The system class
1498
1489
  * @internal
1499
1490
  */
@@ -1575,13 +1566,16 @@ interface Collision {
1575
1566
  * playerCollider,
1576
1567
  * "enemy"
1577
1568
  * );
1578
- *
1579
- * // Get all current collisions
1580
- * const allCollisions = collisionRepository.findAll();
1581
1569
  * ```
1582
1570
  */
1583
1571
  declare class CollisionRepository {
1572
+ private collisionPool;
1573
+ private collisionPoolIndex;
1584
1574
  private collisions;
1575
+ private step;
1576
+ private findCache;
1577
+ /** @internal */
1578
+ private updateCache;
1585
1579
  /**
1586
1580
  * Searches for and returns a collection of collisions for the given collider
1587
1581
  * @param collider The local collider
@@ -1596,15 +1590,22 @@ declare class CollisionRepository {
1596
1590
  */
1597
1591
  findCollisionsForColliderAndLayer(collider: Collider, layer: string): Collision[];
1598
1592
  /**
1599
- * Returns all the collisions
1600
- * @public
1601
- * @returns A collection of collisions
1593
+ * Returns the raw collisions of the current physics step, for engine systems that need every collision at once.
1594
+ * - Each pair of colliding shapes is stored once, not once per side: the shape that detected the collision is
1595
+ * the local one. Check both `localEntity` and `remoteEntity` (and negate `resolution.direction` for the
1596
+ * remote side) to find every collision of an entity.
1597
+ * - The collisions are pooled: the objects and the array are reused on the next physics step. Read them
1598
+ * synchronously and do not keep references to them.
1599
+ *
1600
+ * Use `findCollisionsForCollider` or `findCollisionsForColliderAndLayer` instead when querying the collisions of
1601
+ * a single collider: they return copies, already oriented with that collider as the local one.
1602
+ * @internal
1602
1603
  */
1603
- findAll(): Collision[];
1604
+ getCollisions(): Collision[];
1604
1605
  /** @internal */
1605
- persist(collision: Collision): void;
1606
+ persist(localEntity: Entity, localCollider: Collider, remoteEntity: Entity, remoteCollider: Collider, { direction, penetration }: CollisionResolution): void;
1606
1607
  /** @internal */
1607
- removeAll(): void;
1608
+ clear(): void;
1608
1609
  }
1609
1610
 
1610
1611
  /**
@@ -1738,7 +1739,7 @@ interface AudioSource {
1738
1739
  declare class AssetManager {
1739
1740
  private readonly audioContext;
1740
1741
  private readonly assets;
1741
- constructor(audioContext: AudioContext | null);
1742
+ constructor(audioContext: AudioContext | undefined);
1742
1743
  /**
1743
1744
  * Returns TRUE if the assets are loaded
1744
1745
  * @returns TRUE or FALSE
@@ -1755,9 +1756,9 @@ declare class AssetManager {
1755
1756
  * Loads an audio asset
1756
1757
  * @param url The asset URL
1757
1758
  * @param name The asset name [optional]
1758
- * @returns The {@link AudioSource} (with its `buffer` populated asynchronously), or `null` if no AudioContext is available.
1759
+ * @returns The {@link AudioSource} (with its `buffer` populated asynchronously), or `undefined` if no AudioContext is available.
1759
1760
  */
1760
- loadAudio(url: string, name?: string): AudioSource | null;
1761
+ loadAudio(url: string, name?: string): AudioSource | undefined;
1761
1762
  private decodeAudioBuffer;
1762
1763
  /**
1763
1764
  * Loads a font asset
@@ -2056,15 +2057,16 @@ declare class SceneManager {
2056
2057
  /**
2057
2058
  * Loads a scene
2058
2059
  * @param name The name of the scene
2059
- * @param preserveEntitiesWithComponent Optional component type to preserve entities that have this component
2060
+ * @param options Optional options object. See {@link LoadSceneOptions}
2060
2061
  * @public
2061
2062
  */
2062
- loadScene(name: string, preserveEntitiesWithComponent?: ComponentType): void;
2063
+ loadScene(name: string, options?: LoadSceneOptions): void;
2063
2064
  /**
2064
2065
  * Loads the opening scene
2066
+ * @param options Optional options object. See {@link LoadSceneOptions}
2065
2067
  * @public
2066
2068
  */
2067
- loadOpeningScene(): void;
2069
+ loadOpeningScene(options?: LoadSceneOptions): void;
2068
2070
  /**
2069
2071
  * Returns true if the scene is loading
2070
2072
  * @public
@@ -2077,8 +2079,22 @@ declare class SceneManager {
2077
2079
  get sceneLoadedThisFrame(): boolean;
2078
2080
  /** @internal */
2079
2081
  update(): void;
2080
- private destroyCurrentScene;
2082
+ /** @internal */
2083
+ destroyCurrentScene(): void;
2081
2084
  }
2085
+ /**
2086
+ * Options for the `loadScene` and `loadOpeningScene` methods of the SceneManager
2087
+ * @public
2088
+ * @category Managers
2089
+ * @example
2090
+ * ```js
2091
+ * this.sceneManager.loadScene("Level2", { preserveEntitiesWithComponent: DontDestroy });
2092
+ * ```
2093
+ */
2094
+ type LoadSceneOptions = {
2095
+ /** The entities that have a component of this type are preserved across the scene transition */
2096
+ preserveEntitiesWithComponent: ComponentType;
2097
+ };
2082
2098
  /**
2083
2099
  * This type represents a scene class
2084
2100
  * @public
@@ -2102,14 +2118,12 @@ type SceneType<T extends Scene = Scene> = {
2102
2118
  * this.assetManager.loadImage("image.png");
2103
2119
  * }
2104
2120
  *
2105
- * registerSystems() {
2106
- * this.systems.push(
2121
+ * setup() {
2122
+ * this.systems = [
2107
2123
  * SomeSystem,
2108
2124
  * AnotherSystem
2109
- * );
2110
- * }
2125
+ * ];
2111
2126
  *
2112
- * createEntities() {
2113
2127
  * this.entityManager.createEntity([
2114
2128
  * SomeComponent,
2115
2129
  * AnotherComponent
@@ -2123,33 +2137,16 @@ declare abstract class Scene {
2123
2137
  protected readonly assetManager: AssetManager;
2124
2138
  systems: SystemType[];
2125
2139
  constructor(entityManager: EntityManager, assetManager: AssetManager);
2126
- /**
2127
- * Override this method to register the systems that will be executed in the scene
2128
- * @public
2129
- */
2130
- registerSystems(): void;
2131
2140
  /**
2132
2141
  * Override this method to load the assets needed for the scene
2133
2142
  * @public
2134
2143
  */
2135
2144
  loadAssets(): void;
2136
2145
  /**
2137
- * Override this method to create the entities needed for the scene
2138
- * @public
2139
- */
2140
- createEntities(): void;
2141
- /**
2142
- * Adds a system to the scene
2143
- * @param system The system to add
2146
+ * Override this method to create the entities and register the systems that will be executed in the scene
2144
2147
  * @public
2145
2148
  */
2146
- protected addSystem(system: SystemType): void;
2147
- /**
2148
- * Adds multiple systems to the scene
2149
- * @param systems The systems to add
2150
- * @public
2151
- */
2152
- protected addSystems(systems: SystemType[]): void;
2149
+ setup(): void;
2153
2150
  }
2154
2151
 
2155
2152
  /**
@@ -5229,13 +5226,14 @@ declare class InputManager {
5229
5226
 
5230
5227
  /**
5231
5228
  * Abstract base class for creating game systems with commonly needed dependencies injected.\
5232
- * Provides access to the following core managers and services:\
5233
- * - EntityManager: For managing game entities and components\
5234
- * - AssetManager: For loading and managing game resources\
5235
- * - SceneManager: For controlling scene transitions and state\
5236
- * - TimeManager: For handling game timing and delta time\
5237
- * - InputManager: For processing keyboard, mouse and touch input\
5238
- * - CollisionRepository: For physics and collision detection\
5229
+ * Provides access to the following core managers and services:
5230
+ * - EntityManager: For managing game entities and components
5231
+ * - SystemManager: For managing game systems
5232
+ * - AssetManager: For loading and managing game resources
5233
+ * - SceneManager: For controlling scene transitions and state
5234
+ * - TimeManager: For handling game timing and delta time
5235
+ * - InputManager: For processing keyboard, mouse and touch input
5236
+ * - CollisionRepository: For physics and collision detection
5239
5237
  * - GameConfig: For accessing game configuration settings
5240
5238
  * @public
5241
5239
  * @category Core
@@ -5250,17 +5248,28 @@ declare class InputManager {
5250
5248
  */
5251
5249
  declare abstract class GameSystem implements System {
5252
5250
  protected readonly entityManager: EntityManager;
5251
+ protected readonly systemManager: SystemManager;
5253
5252
  protected readonly assetManager: AssetManager;
5254
5253
  protected readonly sceneManager: SceneManager;
5255
5254
  protected readonly timeManager: TimeManager;
5256
5255
  protected readonly inputManager: InputManager;
5257
5256
  protected readonly collisionRepository: CollisionRepository;
5258
5257
  protected readonly gameConfig: GameConfig;
5258
+ /**
5259
+ * This method is called once every frame
5260
+ * @public
5261
+ */
5259
5262
  onUpdate(): void;
5260
- onCreate(): void;
5261
- onEnabled(): void;
5262
- onDisabled(): void;
5263
- onDestroy(): void;
5263
+ /**
5264
+ * This method is called when the scene finishes loading, after its entities have been created
5265
+ * @public
5266
+ */
5267
+ onSceneLoaded(): void;
5268
+ /**
5269
+ * This method is called when the scene is destroyed, before its entities are removed
5270
+ * @public
5271
+ */
5272
+ onSceneDestroyed(): void;
5264
5273
  }
5265
5274
 
5266
5275
  /**
@@ -5419,4 +5428,4 @@ declare const SYMBOLS: {
5419
5428
  TimeManager: symbol;
5420
5429
  };
5421
5430
 
5422
- export { Animation, type AnimationOptions, type AnimationSlice, Animator, type AnimatorOptions, type Archetype, AssetManager, AudioPlayer, type AudioPlayerOptions, type AudioSource, BallCollider, type BallColliderOptions, BoxCollider, type BoxColliderOptions, BroadPhaseMethods, Button, type ButtonOptions, ButtonShape, Camera, type CameraOptions, type Chunk, Circumference, type Collider, type Collision, type CollisionMatrix, CollisionMethods, CollisionRepository, type CollisionResolution, type Component, type ComponentType, DarknessRenderer, type DarknessRendererOptions, type DependencyName, type DependencyType, EdgeCollider, type EdgeColliderOptions, type Entity, EntityManager, Game, type GameConfig, GameSystem, GamepadController, GeometricRenderer, type GeometricRendererOptions, GeometricShape, InputManager, type IntervalOptions, Keyboard, LightRenderer, type LightRendererOptions, MaskRenderer, type MaskRendererOptions, MaskShape, Mouse, type PlaySfxOptions, Polygon, PolygonCollider, type PolygonColliderOptions, type PropertyKey, Rectangle, RigidBody, type RigidBodyOptions, RigidBodyType, SYMBOLS, Scene, SceneManager, type SceneType, type SearchResult, type Shape, type Slice, SpriteRenderer, type SpriteRendererOptions, type System, type SystemGroup, SystemManager, type SystemType, TextAlignment, TextRenderer, type TextRendererOptions, TileAnimation, type TileAnimationOptions, type TiledChunk, type TiledGroupLayer, type TiledLayer, type TiledObject, type TiledObjectBlueprint, type TiledObjectFactory, type TiledObjectLayer, type TiledObjectProperties, type TiledProperty, type TiledTileAnimationFrame, type TiledTilemap, type TiledTileset, type TiledTilesetTile, 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 };
5431
+ export { Animation, type AnimationOptions, type AnimationSlice, Animator, type AnimatorOptions, type Archetype, AssetManager, AudioPlayer, type AudioPlayerOptions, type AudioSource, BallCollider, type BallColliderOptions, BoxCollider, type BoxColliderOptions, BroadPhaseMethods, Button, type ButtonOptions, ButtonShape, Camera, type CameraOptions, type Chunk, Circumference, type Collider, type Collision, type CollisionMatrix, CollisionMethods, CollisionRepository, type CollisionResolution, type Component, type ComponentType, DarknessRenderer, type DarknessRendererOptions, type DependencyName, type DependencyType, EdgeCollider, type EdgeColliderOptions, type Entity, EntityManager, Game, type GameConfig, GameSystem, GamepadController, GeometricRenderer, type GeometricRendererOptions, GeometricShape, InputManager, type IntervalOptions, Keyboard, LightRenderer, type LightRendererOptions, type LoadSceneOptions, MaskRenderer, type MaskRendererOptions, MaskShape, Mouse, type PlaySfxOptions, Polygon, PolygonCollider, type PolygonColliderOptions, type PropertyKey, Rectangle, type RemoveAllEntitiesOptions, RigidBody, type RigidBodyOptions, RigidBodyType, SYMBOLS, Scene, SceneManager, type SceneType, type SearchResult, type Shape, type Slice, SpriteRenderer, type SpriteRendererOptions, type System, type SystemGroup, SystemManager, type SystemType, TextAlignment, TextRenderer, type TextRendererOptions, TileAnimation, type TileAnimationOptions, type TiledChunk, type TiledGroupLayer, type TiledLayer, type TiledObject, type TiledObjectBlueprint, type TiledObjectFactory, type TiledObjectLayer, type TiledObjectProperties, type TiledProperty, type TiledTileAnimationFrame, type TiledTilemap, type TiledTileset, type TiledTilesetTile, 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 };