angry-pixel 2.1.4 → 2.1.6

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
@@ -708,6 +708,7 @@ type Component = Record<string, any>;
708
708
  */
709
709
  type ComponentType<T extends Component = Component> = {
710
710
  new (...args: any[]): T;
711
+ componentName?: string;
711
712
  };
712
713
  /**
713
714
  * This type represents a search result object containing an entity and its matching component.\
@@ -957,13 +958,18 @@ declare class EntityManager {
957
958
  removeEntity(entity: Entity): void;
958
959
  /**
959
960
  * Removes all Entities and all their Components
961
+ * @param preserveComponentType Optional component type to preserve entities that have this component
960
962
  * @public
961
963
  * @example
962
964
  * ```js
965
+ * // Remove all entities
963
966
  * entityManager.removeAllEntities();
967
+ *
968
+ * // Remove all entities except those that have a SpriteRenderer component
969
+ * entityManager.removeAllEntities(SpriteRenderer);
964
970
  * ```
965
971
  */
966
- removeAllEntities(): void;
972
+ removeAllEntities(preserveComponentType?: ComponentType): void;
967
973
  /**
968
974
  * If the Entity exists, returns TRUE, otherwise it returns FALSE
969
975
  * @param entity
@@ -1277,7 +1283,7 @@ declare class EntityManager {
1277
1283
  * The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
1278
1284
  * @param componentType The component class
1279
1285
  * @param filter The filter function
1280
- * @param includeDisabled TRUE to incluide disabled entities and components, FALSE otherwise
1286
+ * @param includeDisabled TRUE to incluide disabled entities and components. Default is FALSE.
1281
1287
  * @returns SearchResult
1282
1288
  * @public
1283
1289
  * @example
@@ -1309,7 +1315,7 @@ declare class EntityManager {
1309
1315
  * This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.\
1310
1316
  * The second argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
1311
1317
  * @param componentType The component class
1312
- * @param includeDisabled TRUE to incluide disabled entities and components, FALSE otherwise
1318
+ * @param includeDisabled TRUE to incluide disabled entities and components. Default is FALSE.
1313
1319
  * @returns SearchResult
1314
1320
  * @public
1315
1321
  * @example
@@ -1348,7 +1354,7 @@ declare class EntityManager {
1348
1354
  * The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
1349
1355
  * @param parent The parent entity
1350
1356
  * @param componentType The component class
1351
- * @param includeDisabled TRUE to incluide disabled entities and components, FALSE otherwise
1357
+ * @param includeDisabled TRUE to incluide disabled entities and components. Default is FALSE.
1352
1358
  * @returns SearchResult
1353
1359
  * @public
1354
1360
  * @example
@@ -1812,6 +1818,12 @@ type IntervalOptions = {
1812
1818
  times?: number;
1813
1819
  /** Whether to execute the callback immediately before starting the interval timer */
1814
1820
  executeImmediately?: boolean;
1821
+ /** Entity reference to cancel the interval when the entity is disabled or destroyed */
1822
+ entityRef?: Entity;
1823
+ /** Component reference to cancel the interval when the component is disabled or destroyed */
1824
+ componentRef?: Component;
1825
+ /** Whether to use the time scale for the interval, default is TRUE */
1826
+ useTimeScale?: boolean;
1815
1827
  };
1816
1828
  /**
1817
1829
  * Manages the properties associated with time.\
@@ -1851,11 +1863,26 @@ type IntervalOptions = {
1851
1863
  * executeImmediately: true,
1852
1864
  * });
1853
1865
  *
1866
+ * // set an interval that will be cleared when the entity is destroyed
1867
+ * const intervalId = timeManager.setInterval({
1868
+ * callback: () => console.log("Will be called indefinitely!"),
1869
+ * delay: 1000,
1870
+ * entityRef: entity,
1871
+ * });
1872
+ *
1873
+ * // set an interval that will be cleared when the component is destroyed
1874
+ * const intervalId = timeManager.setInterval({
1875
+ * callback: () => console.log("Will be called indefinitely!"),
1876
+ * delay: 1000,
1877
+ * componentRef: component,
1878
+ * });
1879
+ *
1854
1880
  * // clear the interval with the given id
1855
1881
  * this.timeManager.clearInterval(intervalId);
1856
1882
  * ```
1857
1883
  */
1858
1884
  declare class TimeManager {
1885
+ private readonly entityManager;
1859
1886
  /** @internal */
1860
1887
  readonly fixedGameFramerate: number;
1861
1888
  /** @internal */
@@ -1889,7 +1916,7 @@ declare class TimeManager {
1889
1916
  get physicsDeltaTime(): number;
1890
1917
  /** The browser delta time affected by time scale. */
1891
1918
  get renderDeltaTime(): number;
1892
- constructor({ physicsFramerate }: GameConfig);
1919
+ constructor({ physicsFramerate }: GameConfig, entityManager: EntityManager);
1893
1920
  /** @internal */
1894
1921
  updateForRender(time: number): void;
1895
1922
  /** @internal */
@@ -1898,11 +1925,13 @@ declare class TimeManager {
1898
1925
  updateForPhysics(time: number): void;
1899
1926
  /** @internal */
1900
1927
  updateIntervals(): void;
1928
+ private intervalHealthCheck;
1901
1929
  /**
1902
1930
  * Sets a timer which executes a function repeatedly at a fixed time interval.\
1903
1931
  * If `times` is provided, the interval will be cleared after the function has been called that many times.\
1904
1932
  * But if `times` is not provided, the interval will continue until it is cleared.\
1905
1933
  * If `executeImmediately` is set to true, the function will be called immediately after the interval is set.\
1934
+ * If `useTimeScale` is set to false, the interval will use the unscaled delta time.\
1906
1935
  * Intervals are cleared when loading a new scene.
1907
1936
  * @param intervalOptions
1908
1937
  * @returns intervalId
@@ -1930,7 +1959,7 @@ declare class TimeManager {
1930
1959
  * });
1931
1960
  * ```
1932
1961
  */
1933
- setInterval({ callback, delay, times, executeImmediately }: IntervalOptions): number;
1962
+ setInterval({ callback, delay, times, executeImmediately, entityRef, componentRef, useTimeScale, }: IntervalOptions): number;
1934
1963
  /**
1935
1964
  * Clears the interval with the given id.
1936
1965
  * @param intervalId
@@ -1942,6 +1971,66 @@ declare class TimeManager {
1942
1971
  clearAllIntervals(): void;
1943
1972
  }
1944
1973
 
1974
+ /**
1975
+ * Manages scene loading, transitions and lifecycle.\
1976
+ * Provides methods to register scenes, load scenes by name, and handles the opening scene.\
1977
+ * Ensures proper cleanup between scene transitions and maintains scene state.
1978
+ * @public
1979
+ * @category Managers
1980
+ * @example
1981
+ * ```js
1982
+ * this.sceneManager.loadScene("MainScene");
1983
+ * ```
1984
+ */
1985
+ declare class SceneManager {
1986
+ private readonly systemManager;
1987
+ private readonly systemFactory;
1988
+ private readonly entityManager;
1989
+ private readonly assetManager;
1990
+ private readonly timeManager;
1991
+ private readonly scenes;
1992
+ private openingSceneName;
1993
+ private currentSceneName;
1994
+ private sceneNameToBeLoaded;
1995
+ private _loadingScene;
1996
+ private _sceneLoadedThisFrame;
1997
+ private preserveEntitiesWithComponent;
1998
+ /** @internal */
1999
+ constructor(systemManager: SystemManager, systemFactory: CreateSystemService, entityManager: EntityManager, assetManager: AssetManager, timeManager: TimeManager);
2000
+ /**
2001
+ * Adds a scene to the SceneManager
2002
+ * @param sceneType The scene class
2003
+ * @param name The name of the scene
2004
+ * @param openingScene Whether the scene is the opening scene
2005
+ * @public
2006
+ */
2007
+ addScene(sceneType: SceneType, name: string, openingScene?: boolean): void;
2008
+ /**
2009
+ * Loads a scene
2010
+ * @param name The name of the scene
2011
+ * @param preserveEntitiesWithComponent Optional component type to preserve entities that have this component
2012
+ * @public
2013
+ */
2014
+ loadScene(name: string, preserveEntitiesWithComponent?: ComponentType): void;
2015
+ /**
2016
+ * Loads the opening scene
2017
+ * @public
2018
+ */
2019
+ loadOpeningScene(): void;
2020
+ /**
2021
+ * Returns true if the scene is loading
2022
+ * @public
2023
+ */
2024
+ get loadingScene(): boolean;
2025
+ /**
2026
+ * Returns true if the scene was loaded this frame
2027
+ * @public
2028
+ */
2029
+ get sceneLoadedThisFrame(): boolean;
2030
+ /** @internal */
2031
+ update(): void;
2032
+ private destroyCurrentScene;
2033
+ }
1945
2034
  /**
1946
2035
  * This type represents a scene class
1947
2036
  * @public
@@ -1965,14 +2054,14 @@ type SceneType<T extends Scene = Scene> = {
1965
2054
  * this.assetManager.loadImage("image.png");
1966
2055
  * }
1967
2056
  *
1968
- * loadSystems() {
2057
+ * registerSystems() {
1969
2058
  * this.systems.push(
1970
2059
  * SomeSystem,
1971
2060
  * AnotherSystem
1972
2061
  * );
1973
2062
  * }
1974
2063
  *
1975
- * setup() {
2064
+ * createEntities() {
1976
2065
  * this.entityManager.createEntity([
1977
2066
  * SomeComponent,
1978
2067
  * AnotherComponent
@@ -1986,43 +2075,33 @@ declare abstract class Scene {
1986
2075
  protected readonly assetManager: AssetManager;
1987
2076
  systems: SystemType[];
1988
2077
  constructor(entityManager: EntityManager, assetManager: AssetManager);
1989
- loadSystems(): void;
2078
+ /**
2079
+ * Override this method to register the systems that will be executed in the scene
2080
+ * @public
2081
+ */
2082
+ registerSystems(): void;
2083
+ /**
2084
+ * Override this method to load the assets needed for the scene
2085
+ * @public
2086
+ */
1990
2087
  loadAssets(): void;
1991
- setup(): void;
1992
- }
1993
- /**
1994
- * Manages scene loading, transitions and lifecycle.\
1995
- * Provides methods to register scenes, load scenes by name, and handles the opening scene.\
1996
- * Ensures proper cleanup between scene transitions and maintains scene state.
1997
- * @public
1998
- * @category Managers
1999
- * @example
2000
- * ```js
2001
- * this.sceneManager.loadScene("MainScene");
2002
- * ```
2003
- */
2004
- declare class SceneManager {
2005
- private readonly systemManager;
2006
- private readonly systemFactory;
2007
- private readonly entityManager;
2008
- private readonly assetManager;
2009
- private readonly timeManager;
2010
- private readonly scenes;
2011
- private openingSceneName;
2012
- private currentSceneName;
2013
- private sceneNameToBeLoaded;
2014
- private _loadingScene;
2015
- private _sceneLoadedThisFrame;
2016
- /** @internal */
2017
- constructor(systemManager: SystemManager, systemFactory: CreateSystemService, entityManager: EntityManager, assetManager: AssetManager, timeManager: TimeManager);
2018
- addScene(sceneType: SceneType, name: string, openingScene?: boolean): void;
2019
- loadScene(name: string): void;
2020
- loadOpeningScene(): void;
2021
- get loadingScene(): boolean;
2022
- get sceneLoadedThisFrame(): boolean;
2023
- /** @internal */
2024
- update(): void;
2025
- private destroyCurrentScene;
2088
+ /**
2089
+ * Override this method to create the entities needed for the scene
2090
+ * @public
2091
+ */
2092
+ createEntities(): void;
2093
+ /**
2094
+ * Adds a system to the scene
2095
+ * @param system The system to add
2096
+ * @public
2097
+ */
2098
+ protected addSystem(system: SystemType): void;
2099
+ /**
2100
+ * Adds multiple systems to the scene
2101
+ * @param systems The systems to add
2102
+ * @public
2103
+ */
2104
+ protected addSystems(systems: SystemType[]): void;
2026
2105
  }
2027
2106
 
2028
2107
  /**
@@ -2116,6 +2195,7 @@ declare class Game {
2116
2195
  * const walkAnimation = new Animation({
2117
2196
  * image: "walk.png",
2118
2197
  * slice: { size: new Vector2(32, 32) },
2198
+ * frames: [0, 1, 2, 3, 4, 5],
2119
2199
  * fps: 12,
2120
2200
  * loop: true
2121
2201
  * });
@@ -2123,6 +2203,7 @@ declare class Game {
2123
2203
  * const idleAnimation = new Animation({
2124
2204
  * image: "idle.png",
2125
2205
  * slice: { size: new Vector2(32, 32) },
2206
+ * frames: [6, 7, 8, 9]
2126
2207
  * fps: 8,
2127
2208
  * loop: true
2128
2209
  * });
@@ -2154,6 +2235,7 @@ interface AnimatorOptions {
2154
2235
  * const walkAnimation = new Animation({
2155
2236
  * image: "walk.png",
2156
2237
  * slice: { size: new Vector2(32, 32) },
2238
+ * frames: [0, 1, 2, 3, 4, 5],
2157
2239
  * fps: 12,
2158
2240
  * loop: true
2159
2241
  * });
@@ -2161,6 +2243,7 @@ interface AnimatorOptions {
2161
2243
  * const idleAnimation = new Animation({
2162
2244
  * image: "idle.png",
2163
2245
  * slice: { size: new Vector2(32, 32) },
2246
+ * frames: [6, 7, 8, 9],
2164
2247
  * fps: 8,
2165
2248
  * loop: true
2166
2249
  * });
@@ -2177,17 +2260,26 @@ interface AnimatorOptions {
2177
2260
  * ```
2178
2261
  */
2179
2262
  declare class Animator {
2263
+ /** The animations to play. */
2180
2264
  animations: Map<string, Animation>;
2265
+ /** The animation to play. */
2181
2266
  animation: string;
2267
+ /** The speed of the animation. */
2182
2268
  speed: number;
2269
+ /** TRUE If the animation should reset to the first frame when the animation is stopped, FALSE otherwise. */
2183
2270
  reset: boolean;
2271
+ /** TRUE If the animation is playing, FALSE otherwise. */
2184
2272
  playing: boolean;
2273
+ /** The current frame of the animation. */
2185
2274
  currentFrame: number;
2275
+ /** The current time of the animation. */
2186
2276
  currentTime: number;
2187
2277
  /** @internal */
2188
2278
  _currentAnimation: string;
2189
2279
  /** @internal */
2190
2280
  _assetsReady: boolean;
2281
+ /** @internal */
2282
+ static componentName: string;
2191
2283
  constructor(options?: Partial<AnimatorOptions>);
2192
2284
  }
2193
2285
  /**
@@ -2199,6 +2291,7 @@ declare class Animator {
2199
2291
  * const walkAnimation = new Animation({
2200
2292
  * image: "walk.png",
2201
2293
  * slice: { size: new Vector2(32, 32) },
2294
+ * frames: [0, 1, 2, 3, 4, 5],
2202
2295
  * fps: 12,
2203
2296
  * loop: true
2204
2297
  * });
@@ -2206,6 +2299,7 @@ declare class Animator {
2206
2299
  * const idleAnimation = new Animation({
2207
2300
  * image: "idle.png",
2208
2301
  * slice: { size: new Vector2(32, 32) },
2302
+ * frames: [6, 7, 8, 9],
2209
2303
  * fps: 8,
2210
2304
  * loop: true
2211
2305
  * });
@@ -2242,6 +2336,7 @@ interface AnimationOptions {
2242
2336
  * const walkAnimation = new Animation({
2243
2337
  * image: "walk.png",
2244
2338
  * slice: { size: new Vector2(32, 32) },
2339
+ * frames: [0, 1, 2, 3, 4, 5],
2245
2340
  * fps: 12,
2246
2341
  * loop: true
2247
2342
  * });
@@ -2249,6 +2344,7 @@ interface AnimationOptions {
2249
2344
  * const idleAnimation = new Animation({
2250
2345
  * image: "idle.png",
2251
2346
  * slice: { size: new Vector2(32, 32) },
2347
+ * frames: [6, 7, 8, 9],
2252
2348
  * fps: 8,
2253
2349
  * loop: true
2254
2350
  * });
@@ -2301,6 +2397,8 @@ interface AudioPlayerOptions {
2301
2397
  action: AudioPlayerAction;
2302
2398
  /** The audio source to play. */
2303
2399
  audioSource: HTMLAudioElement | string;
2400
+ /** TRUE If the audio source should stop on scene transition, FALSE otherwise. Default is TRUE. */
2401
+ stopOnSceneTransition: boolean;
2304
2402
  /** TRUE If the playback rate is fixed to the TimeManager time scale, default FALSE */
2305
2403
  fixedToTimeScale: boolean;
2306
2404
  /** TRUE If the audio source should loop. */
@@ -2328,6 +2426,8 @@ declare class AudioPlayer {
2328
2426
  action: AudioPlayerAction;
2329
2427
  /** The audio source to play. */
2330
2428
  audioSource: HTMLAudioElement | string;
2429
+ /** TRUE If the audio source should stop on scene transition, FALSE otherwise. Default is TRUE. */
2430
+ stopOnSceneTransition: boolean;
2331
2431
  /** TRUE If the playback rate is fixed to the TimeManager time scale, default FALSE */
2332
2432
  fixedToTimeScale: boolean;
2333
2433
  /** TRUE If the audio source should loop. */
@@ -2346,6 +2446,8 @@ declare class AudioPlayer {
2346
2446
  _currentAudioSource: HTMLAudioElement;
2347
2447
  _playPromisePendind: boolean;
2348
2448
  _playAfterUserInput: boolean;
2449
+ /** @internal */
2450
+ static componentName: string;
2349
2451
  constructor(options?: Partial<AudioPlayerOptions>);
2350
2452
  /**
2351
2453
  * Play the audio source.
@@ -2438,6 +2540,8 @@ declare class Button {
2438
2540
  onClick: () => void;
2439
2541
  /** Function executed when the button is pressed */
2440
2542
  onPressed: () => void;
2543
+ /** @internal */
2544
+ static componentName: string;
2441
2545
  constructor(options?: Partial<ButtonOptions>);
2442
2546
  }
2443
2547
  /**
@@ -2493,8 +2597,12 @@ interface TiledWrapperOptions {
2493
2597
  * ```
2494
2598
  */
2495
2599
  declare class TiledWrapper {
2600
+ /** The tilemap to render. */
2496
2601
  tilemap: TiledTilemap | string;
2602
+ /** The layer to render. */
2497
2603
  layerToRender: string;
2604
+ /** @internal */
2605
+ static componentName: string;
2498
2606
  constructor(options?: Partial<TiledWrapperOptions>);
2499
2607
  }
2500
2608
  /**
@@ -2657,6 +2765,8 @@ declare class Transform {
2657
2765
  _awake: boolean;
2658
2766
  /** @internal */
2659
2767
  _parent: Transform;
2768
+ /** @internal */
2769
+ static componentName: string;
2660
2770
  constructor(options?: Partial<TransformOptions>);
2661
2771
  }
2662
2772
 
@@ -2718,6 +2828,8 @@ declare class BallCollider implements Collider {
2718
2828
  ignoreCollisionsWithLayers: string[];
2719
2829
  /** @internal */
2720
2830
  shapes: Shape[];
2831
+ /** @internal */
2832
+ static componentName: string;
2721
2833
  constructor(options?: Partial<BallColliderOptions>);
2722
2834
  }
2723
2835
 
@@ -2791,6 +2903,8 @@ declare class BoxCollider implements Collider {
2791
2903
  ignoreCollisionsWithLayers: string[];
2792
2904
  /** @internal */
2793
2905
  shapes: Shape[];
2906
+ /** @internal */
2907
+ static componentName: string;
2794
2908
  constructor(options?: Partial<BoxColliderOptions>);
2795
2909
  }
2796
2910
 
@@ -2857,6 +2971,8 @@ declare class EdgeCollider implements Collider {
2857
2971
  ignoreCollisionsWithLayers: string[];
2858
2972
  /** @internal */
2859
2973
  shapes: Shape[];
2974
+ /** @internal */
2975
+ static componentName: string;
2860
2976
  constructor(options?: Partial<EdgeColliderOptions>);
2861
2977
  }
2862
2978
 
@@ -2925,6 +3041,8 @@ declare class PolygonCollider implements Collider {
2925
3041
  ignoreCollisionsWithLayers: string[];
2926
3042
  /** @internal */
2927
3043
  shapes: Shape[];
3044
+ /** @internal */
3045
+ static componentName: string;
2928
3046
  constructor(options?: Partial<PolygonColliderOptions>);
2929
3047
  }
2930
3048
 
@@ -3058,6 +3176,8 @@ declare class RigidBody {
3058
3176
  * @public
3059
3177
  */
3060
3178
  acceleration: Vector2;
3179
+ /** @internal */
3180
+ static componentName: string;
3061
3181
  constructor(options?: Partial<RigidBodyOptions>);
3062
3182
  }
3063
3183
 
@@ -3121,6 +3241,8 @@ declare class TilemapCollider implements Collider {
3121
3241
  physics: boolean;
3122
3242
  /** @internal */
3123
3243
  shapes: Shape[];
3244
+ /** @internal */
3245
+ static componentName: string;
3124
3246
  constructor(options?: Partial<TilemapColliderOptions>);
3125
3247
  }
3126
3248
 
@@ -3378,6 +3500,8 @@ declare class Camera {
3378
3500
  debug: boolean;
3379
3501
  /** @internal */
3380
3502
  _renderData: CameraData;
3503
+ /** @internal */
3504
+ static componentName: string;
3381
3505
  constructor(options?: Partial<CameraOptions>);
3382
3506
  }
3383
3507
 
@@ -3430,6 +3554,8 @@ declare class LightRenderer {
3430
3554
  intensity: number;
3431
3555
  /** @internal */
3432
3556
  _boundingBox: Rectangle;
3557
+ /** @internal */
3558
+ static componentName: string;
3433
3559
  constructor(options?: Partial<LightRendererOptions>);
3434
3560
  }
3435
3561
 
@@ -3551,6 +3677,8 @@ declare class MaskRenderer {
3551
3677
  layer: string;
3552
3678
  /** @internal */
3553
3679
  _renderData: MaskRenderData;
3680
+ /** @internal */
3681
+ static componentName: string;
3554
3682
  constructor(options?: Partial<MaskRendererOptions>);
3555
3683
  }
3556
3684
 
@@ -3609,6 +3737,8 @@ declare class DarknessRenderer {
3609
3737
  _boundingBox: Rectangle;
3610
3738
  /** @internal */
3611
3739
  _renderData: DarknessRenderData;
3740
+ /** @internal */
3741
+ static componentName: string;
3612
3742
  constructor(options?: Partial<DarknessRendererOptions>);
3613
3743
  }
3614
3744
 
@@ -3720,6 +3850,8 @@ declare class SpriteRenderer {
3720
3850
  tiled: Vector2;
3721
3851
  /** @internal */
3722
3852
  _renderData: SpriteRenderData;
3853
+ /** @internal */
3854
+ static componentName: string;
3723
3855
  constructor(options?: Partial<SpriteRendererOptions>);
3724
3856
  }
3725
3857
 
@@ -3930,6 +4062,8 @@ declare class TextRenderer {
3930
4062
  width: number;
3931
4063
  /** @internal */
3932
4064
  _renderData: TextRenderData;
4065
+ /** @internal */
4066
+ static componentName: string;
3933
4067
  constructor(options?: Partial<TextRendererOptions>);
3934
4068
  }
3935
4069
 
@@ -4043,6 +4177,8 @@ declare class TilemapRenderer {
4043
4177
  _processed: boolean;
4044
4178
  /** @internal */
4045
4179
  _renderData: TilemapRenderData[];
4180
+ /** @internal */
4181
+ static componentName: string;
4046
4182
  constructor(options?: Partial<TilemapRendererOptions>);
4047
4183
  }
4048
4184
  /**
@@ -4197,6 +4333,8 @@ declare class VideoRenderer {
4197
4333
  _playPromisePendind: boolean;
4198
4334
  /** @internal */
4199
4335
  _renderData: VideoRenderData;
4336
+ /** @internal */
4337
+ static componentName: string;
4200
4338
  constructor(options?: Partial<VideoRendererOptions>);
4201
4339
  /**
4202
4340
  * Play the video source.