angry-pixel 2.0.16 → 2.0.18

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
@@ -55,7 +55,7 @@ declare function injectable(name: DependencyName): (target: DependencyType) => v
55
55
  * }
56
56
  * ```
57
57
  */
58
- declare function inject(name: DependencyName): (target: any, propertyKey: PropertyKey, parameterIndex?: number) => void;
58
+ declare function inject(name: DependencyName): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
59
59
 
60
60
  /**
61
61
  * Represents a 2D vector and provides static methods for vector calculations.
@@ -245,8 +245,57 @@ declare class Vector2 {
245
245
  * v2.x // 4
246
246
  * v2.y // 2
247
247
  * ```
248
+ * @example
249
+ * ```js
250
+ * const v1 = new Vector2(3.9, 2.2);
251
+ * Vector2.round(v1, v1);
252
+ * v1.x // 4
253
+ * v1.y // 2
254
+ * ```
248
255
  */
249
256
  static round(out: Vector2, a: Vector2): Vector2;
257
+ /**
258
+ * Floors a vector
259
+ *
260
+ * @param a The vector to floor
261
+ * @returns The output vector
262
+ * @example
263
+ * ```js
264
+ * const v1 = new Vector2(3.9, 2.2);
265
+ * const v2 = Vector2.floor(new Vector2(), v1);
266
+ * v2.x // 3
267
+ * v2.y // 2
268
+ * ```
269
+ * @example
270
+ * ```js
271
+ * const v1 = new Vector2(3.9, 2.2);
272
+ * Vector2.floor(v1, v1);
273
+ * v1.x // 3
274
+ * v1.y // 2
275
+ * ```
276
+ */
277
+ static floor(out: Vector2, a: Vector2): Vector2;
278
+ /**
279
+ * Ceils a vector
280
+ *
281
+ * @param a The vector to ceil
282
+ * @returns The output vector
283
+ * @example
284
+ * ```js
285
+ * const v1 = new Vector2(3.9, 2.2);
286
+ * const v2 = Vector2.ceil(new Vector2(), v1);
287
+ * v2.x // 4
288
+ * v2.y // 3
289
+ * ```
290
+ * @example
291
+ * ```js
292
+ * const v1 = new Vector2(3.9, 2.2);
293
+ * Vector2.ceil(v1, v1);
294
+ * v1.x // 4
295
+ * v1.y // 3
296
+ * ```
297
+ */
298
+ static ceil(out: Vector2, a: Vector2): Vector2;
250
299
  toString(): string;
251
300
  }
252
301
 
@@ -372,6 +421,20 @@ declare const range: (start: number, end: number, steps?: number) => number[];
372
421
  * @returns true if the number is between the min and the max, false instead
373
422
  */
374
423
  declare const between: (value: number, min: number, max: number) => boolean;
424
+ /**
425
+ * Converts the given radians to degrees.
426
+ * @param radians
427
+ * @returns degrees
428
+ */
429
+ declare const radiansToDegrees: (radians: number) => number;
430
+ /**
431
+ * Converts the given degrees to radians.
432
+ * @param degrees
433
+ * @returns radians
434
+ * @category Math
435
+ * @public
436
+ */
437
+ declare const degreesToRadians: (degrees: number) => number;
375
438
 
376
439
  /** @internal */
377
440
  interface Shape {
@@ -1117,7 +1180,11 @@ interface GameConfig {
1117
1180
  height: number;
1118
1181
  /** Enables the debug mode */
1119
1182
  debugEnabled?: boolean;
1120
- /** Background color of canvas */
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";
1187
+ /** Background color of canvas, default "#000000" (black) */
1121
1188
  canvasColor?: string;
1122
1189
  /** Framerate for physics execution. The allowed values are 60, 120, 180, 240.
1123
1190
  * The higher the framerate, the more accurate the physics will be, but it will consume more processor resources.
@@ -1178,15 +1245,17 @@ declare class AssetManager {
1178
1245
  /**
1179
1246
  * Loads an image asset
1180
1247
  * @param url The asset URL
1248
+ * @param name The asset name [optional]
1181
1249
  * @returns The HTML Image element created
1182
1250
  */
1183
- loadImage(url: string): HTMLImageElement;
1251
+ loadImage(url: string, name?: string): HTMLImageElement;
1184
1252
  /**
1185
1253
  * Loads an audio asset
1186
1254
  * @param url The asset URL
1255
+ * @param name The asset name [optional]
1187
1256
  * @returns The HTML Audio element created
1188
1257
  */
1189
- loadAudio(url: string): HTMLAudioElement;
1258
+ loadAudio(url: string, name?: string): HTMLAudioElement;
1190
1259
  /**
1191
1260
  * Loads a font asset
1192
1261
  * @param family The font family name
@@ -1197,21 +1266,34 @@ declare class AssetManager {
1197
1266
  /**
1198
1267
  * Loads an video asset
1199
1268
  * @param url The asset URL
1269
+ * @param name The asset name [optional]
1200
1270
  * @returns The HTML Video element created
1201
1271
  */
1202
- loadVideo(url: string): HTMLVideoElement;
1272
+ loadVideo(url: string, name?: string): HTMLVideoElement;
1203
1273
  /**
1204
1274
  * Retrieves an image asset
1205
1275
  * @param url The asset URL
1206
1276
  * @returns The HTML Image element
1207
1277
  */
1208
1278
  getImage(url: string): HTMLImageElement;
1279
+ /**
1280
+ * Retrieves an image asset
1281
+ * @param name The asset name
1282
+ * @returns The HTML Image element
1283
+ */
1284
+ getImage(name: string): HTMLImageElement;
1209
1285
  /**
1210
1286
  * Retrieves an audio asset
1211
1287
  * @param url The asset URL
1212
1288
  * @returns The HTML Audio element
1213
1289
  */
1214
1290
  getAudio(url: string): HTMLAudioElement;
1291
+ /**
1292
+ * Retrieves an audio asset
1293
+ * @param name The asset name
1294
+ * @returns The HTML Audio element
1295
+ */
1296
+ getAudio(name: string): HTMLAudioElement;
1215
1297
  /**
1216
1298
  * Retrieves a font asset
1217
1299
  * @param family The font family name
@@ -1224,6 +1306,12 @@ declare class AssetManager {
1224
1306
  * @returns The HTML Video element
1225
1307
  */
1226
1308
  getVideo(url: string): HTMLVideoElement;
1309
+ /**
1310
+ * Retrieves a video asset
1311
+ * @param name The asset name
1312
+ * @returns The HTML Video element
1313
+ */
1314
+ getVideo(name: string): HTMLVideoElement;
1227
1315
  private createAsset;
1228
1316
  }
1229
1317
 
@@ -2400,21 +2488,27 @@ declare enum TextOrientation {
2400
2488
  RightCenter = 3
2401
2489
  }
2402
2490
  interface TextRenderData extends RenderData {
2491
+ color: string;
2492
+ flipHorizontally: boolean;
2493
+ flipVertically: boolean;
2403
2494
  font: FontFace | string;
2404
- text: string;
2405
2495
  fontSize: number;
2406
- color: string;
2407
- lineSeparation: number;
2496
+ lineHeight: number;
2408
2497
  letterSpacing: number;
2498
+ opacity: number;
2409
2499
  orientation: TextOrientation;
2410
2500
  rotation: number;
2411
- opacity: number;
2501
+ shadow?: {
2502
+ color: string;
2503
+ offset: Vector2;
2504
+ opacity: number;
2505
+ };
2412
2506
  smooth: boolean;
2413
- bitmap: {
2507
+ text: string;
2508
+ textureAtlas: {
2414
2509
  charRanges: number[];
2415
2510
  fontSize: number;
2416
- margin: Vector2;
2417
- spacing: Vector2;
2511
+ spacing: number;
2418
2512
  };
2419
2513
  }
2420
2514
 
@@ -2479,6 +2573,11 @@ interface VideoRenderData extends RenderData {
2479
2573
  * @category Components
2480
2574
  */
2481
2575
  declare const defaultRenderLayer = "Default";
2576
+ /**
2577
+ * Debug render layer
2578
+ * @internal
2579
+ */
2580
+ declare const debugRenderLayer = "Debug";
2482
2581
  /**
2483
2582
  * @public
2484
2583
  * @category Components
@@ -2499,6 +2598,8 @@ declare class Camera {
2499
2598
  zoom: number;
2500
2599
  /** In case you have more than one camera, the depth value determines which camera is rendered first. The lesser value, the first to render */
2501
2600
  depth: number;
2601
+ /** Set to TRUE to allow this camera to render debug data (default FALSE) */
2602
+ debug: boolean;
2502
2603
  /** @internal */
2503
2604
  _renderData: CameraData;
2504
2605
  constructor(options?: Partial<CameraOptions>);
@@ -2724,91 +2825,173 @@ declare class SpriteRenderer {
2724
2825
  constructor(options?: Partial<SpriteRendererOptions>);
2725
2826
  }
2726
2827
 
2828
+ /**
2829
+ * @internal
2830
+ */
2831
+ declare const defaultTextureAtlasOptions: {
2832
+ charRanges: number[];
2833
+ fontSize: number;
2834
+ spacing: number;
2835
+ };
2727
2836
  /**
2728
2837
  * @public
2729
2838
  * @category Components
2730
2839
  */
2731
2840
  interface TextRendererOptions {
2732
- layer: string;
2733
- text: string;
2841
+ /** The text color */
2842
+ color: string;
2843
+ /** Flip the text horizontally */
2844
+ flipHorizontally: boolean;
2845
+ /** Flip the text vertically */
2846
+ flipVertically: boolean;
2847
+ /** The font family to use */
2734
2848
  font: FontFace | string;
2849
+ /** The size of the font in pixels. */
2735
2850
  fontSize: number;
2736
- width: number;
2851
+ /** The height of the invisible box where the text is rendered */
2737
2852
  height: number;
2738
- offset: Vector2;
2739
- color: string;
2740
- lineSeparation: number;
2853
+ /** The render layer */
2854
+ layer: string;
2855
+ /** The space between chars in pixels */
2741
2856
  letterSpacing: number;
2742
- charRanges: number[];
2743
- smooth: boolean;
2744
- rotation: number;
2857
+ /** The height of the line in pixels. Default value is equal to the font size */
2858
+ lineHeight: number;
2859
+ /** X-axis and Y-axis offset */
2860
+ offset: Vector2;
2861
+ /** Change the opacity between 1 and 0 */
2745
2862
  opacity: number;
2863
+ /** Direction in which the text will be rendered. */
2746
2864
  orientation: TextOrientation;
2747
- bitmapMargin: Vector2;
2748
- bitmapSpacing: Vector2;
2865
+ /** Text rotation in radians */
2866
+ rotation: number;
2867
+ /** Smoothing pixels (not recommended for bitmap fonts) */
2868
+ smooth: boolean;
2869
+ /** Shadow text configuration */
2870
+ shadow?: {
2871
+ /** Shadow text color */
2872
+ color: string;
2873
+ /** Shadow text offset in pixels */
2874
+ offset: Vector2;
2875
+ /** Shadow text opacity */
2876
+ opacity: number;
2877
+ };
2878
+ /** The text to render */
2879
+ text: string;
2880
+ /** The texture atlas configuration */
2881
+ textureAtlas: {
2882
+ /** Range of characters covered by the component defined in number pairs.
2883
+ * The default value is [32, 126, 161, 255], this means that the component
2884
+ * will render characters from 32 to 126 and from 161 to 255. */
2885
+ charRanges?: number[];
2886
+ /** The size of the font in pixels for bitmap fonts. */
2887
+ fontSize?: number;
2888
+ /** Spacing in pixels to correct badly sliced characters. */
2889
+ spacing?: number;
2890
+ };
2891
+ /** The width of the invisible box where the text is rendered */
2892
+ width: number;
2749
2893
  }
2750
2894
  /**
2751
2895
  * The TextRenderer component allows to render text using font families, colors, and other configuration options.
2752
2896
  * @public
2753
2897
  * @category Components
2898
+ * @example
2899
+ * ```typescript
2900
+ * const textRenderer = new TextRenderer({
2901
+ * text: "Hello World!",
2902
+ * color: "#FFFFFF",
2903
+ * fontSize: 24,
2904
+ * font: "Arial",
2905
+ * width: 1920,
2906
+ * height: 32,
2907
+ * layer: "TextLayer",
2908
+ * });
2909
+ * ```
2754
2910
  * @example
2755
- * ```js
2756
- * textRenderer.layer: "default";
2757
- * textRenderer.text: "Hello world!";
2758
- * textRenderer.font: "Arial";
2759
- * textRenderer.fontSize: 16;
2760
- * textRenderer.width: 160;
2761
- * textRenderer.height: 16;
2762
- * textRenderer.color: "#000000";
2763
- * textRenderer.offset: new Vector2();
2764
- * textRenderer.lineSeparation: 0;
2765
- * textRenderer.letterSpacing: 0;
2766
- * textRenderer.charRanges: [32, 126, 161, 255];
2767
- * textRenderer.smooth: false;
2768
- * textRenderer.rotation: 0;
2769
- * textRenderer.opacity: 1;
2770
- * textRenderer.orientation: TextOrientation.RightDown;
2771
- * textRenderer.bitmapMargin: new Vector2();
2772
- * textRenderer.bitmapSpacing: new Vector2();
2911
+ * ```typescript
2912
+ * const textRenderer = new TextRenderer({
2913
+ * text: "Hello World!",
2914
+ * color: "#FFFFFF",
2915
+ * fontSize: 24,
2916
+ * width: 1920,
2917
+ * height: 32,
2918
+ * opacity: 1,
2919
+ * layer: "TextLayer",
2920
+ * orientation: TextOrientation.RightCenter,
2921
+ * shadow: {
2922
+ * color: "#00FF00",
2923
+ * offset: new Vector2(3, -3),
2924
+ * opacity: 0.5,
2925
+ * },
2926
+ * textureAtlas: {
2927
+ * charRanges: [32, 126, 161, 255, 0x3040, 0x309f],
2928
+ * fontSize: 64,
2929
+ * spacing: 4,
2930
+ * },
2931
+ * font: "Arial",
2932
+ * flipHorizontally: false,
2933
+ * flipVertically: false,
2934
+ * letterSpacing: 0,
2935
+ * lineHeight: 24,
2936
+ * offset: new Vector2(0, 0),
2937
+ * rotation: 0,
2938
+ * smooth: false,
2939
+ * });
2773
2940
  * ```
2774
2941
  */
2775
2942
  declare class TextRenderer {
2776
- /** The render layer */
2777
- layer: string;
2778
- /** The text to render */
2779
- text: string;
2943
+ /** The text color */
2944
+ color: string;
2945
+ /** Flip the text horizontally */
2946
+ flipHorizontally: boolean;
2947
+ /** Flip the text vertically */
2948
+ flipVertically: boolean;
2780
2949
  /** The font family to use */
2781
2950
  font: FontFace | string;
2782
2951
  /** The size of the font in pixels. */
2783
2952
  fontSize: number;
2784
- /** The width of the invisible box where the text is rendered */
2785
- width: number;
2786
2953
  /** The height of the invisible box where the text is rendered */
2787
2954
  height: number;
2788
- /** X-axis and Y-axis offset */
2789
- offset: Vector2;
2790
- /** The text color */
2791
- color: string;
2792
- /** The separation between lines in pixels */
2793
- lineSeparation: number;
2955
+ /** The render layer */
2956
+ layer: string;
2794
2957
  /** The space between chars in pixels */
2795
2958
  letterSpacing: number;
2796
- /** Range of characters covered by the component defined in number pairs.
2797
- * The default value is [32, 126, 161, 255], this means that the component
2798
- * will render characters from 32 to 126 and from 161 to 255. */
2799
- charRanges: number[];
2800
- /** Smoothing pixels (not recommended for bitmap fonts) */
2801
- smooth: boolean;
2802
- /** Text rotation in radians */
2803
- rotation: number;
2959
+ /** The height of the line in pixels. Default value is equal to the font size */
2960
+ lineHeight: number;
2961
+ /** X-axis and Y-axis offset */
2962
+ offset: Vector2;
2804
2963
  /** Change the opacity between 1 and 0 */
2805
2964
  opacity: number;
2806
2965
  /** Direction in which the text will be rendered. */
2807
2966
  orientation: TextOrientation;
2808
- /** Margin in pixels to correct badly sliced characters. */
2809
- bitmapMargin: Vector2;
2810
- /** Spacing in pixels to correct badly sliced characters. */
2811
- bitmapSpacing: Vector2;
2967
+ /** Text rotation in radians */
2968
+ rotation: number;
2969
+ /** Shadow text configuration */
2970
+ shadow: {
2971
+ /** Shadow text color */
2972
+ color: string;
2973
+ /** Shadow text offset in pixels */
2974
+ offset: Vector2;
2975
+ /** Shadow text opacity */
2976
+ opacity: number;
2977
+ };
2978
+ /** Smoothing pixels (not recommended for bitmap fonts) */
2979
+ smooth: boolean;
2980
+ /** The text to render */
2981
+ text: string;
2982
+ /** The texture atlas configuration */
2983
+ textureAtlas: {
2984
+ /** Range of characters covered by the component defined in number pairs.
2985
+ * The default value is [32, 126, 161, 255], this means that the component
2986
+ * will render characters from 32 to 126 and from 161 to 255. */
2987
+ charRanges?: number[];
2988
+ /** The size of the font in pixels for bitmap fonts. */
2989
+ fontSize?: number;
2990
+ /** Spacing in pixels to correct badly sliced characters. */
2991
+ spacing?: number;
2992
+ };
2993
+ /** The width of the invisible box where the text is rendered */
2994
+ width: number;
2812
2995
  /** @internal */
2813
2996
  _renderData: TextRenderData;
2814
2997
  constructor(options?: Partial<TextRendererOptions>);
@@ -3401,6 +3584,36 @@ declare function gamePhysicsSystem(): (target: SystemType) => void;
3401
3584
  */
3402
3585
  declare function gamePreRenderSystem(): (target: SystemType) => void;
3403
3586
 
3587
+ /**
3588
+ * Applies a decorator manually.
3589
+ * @param decorator The decorator function to be applied.
3590
+ * @param target The target to which the decorator is applied (class, prototype, or constructor argument).
3591
+ * @param propertyKey The property name or constructor argument index (optional).
3592
+ * @public
3593
+ * @category Decorators
3594
+ * @example
3595
+ * ```javascript
3596
+ * decorate(injectable("SomeDependency"), SomeDependency);
3597
+ * ```
3598
+ * @example
3599
+ * ```javascript
3600
+ * decorate(inject("AnotherDependency"), SomeClass, "anotherDependency");
3601
+ * ```
3602
+ * @example
3603
+ * ```javascript
3604
+ * decorate(inject("AnotherDependency"), SomeClass, 0);
3605
+ * ```
3606
+ * @example
3607
+ * ```javascript
3608
+ * decorate(gamePhysicsSystem(), SomeSystem);
3609
+ * ```
3610
+ * @example
3611
+ * ```javascript
3612
+ * decorate(gamePreRenderSystem(), SomeSystem);
3613
+ * ```
3614
+ */
3615
+ declare function decorate(decorator: (...args: any[]) => any, target: any, propertyKey?: string | symbol | number): void;
3616
+
3404
3617
  /**
3405
3618
  * Symbols to be used as dependency identifiers
3406
3619
  * @public
@@ -3418,4 +3631,4 @@ declare const Symbols: {
3418
3631
  TimeManager: symbol;
3419
3632
  };
3420
3633
 
3421
- 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, defaultRenderLayer, fixedRound, gameLogicSystem, gamePhysicsSystem, gamePreRenderSystem, inject, injectable, randomFloat, randomInt, range };
3634
+ 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 };