angry-pixel 2.3.4 → 2.3.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
@@ -945,6 +945,20 @@ declare class EntityManager {
945
945
  * ```
946
946
  */
947
947
  createEntity(archetype: Archetype, parent?: Entity): Entity;
948
+ /**
949
+ * Adds the components of an Archetype to an existing Entity.\
950
+ * Component instances are cloned, so the archetype can be reused.\
951
+ * Child archetypes are created as new entities parented to the given one.
952
+ * @param entity The entity to add the archetype to
953
+ * @param archetype The archetype to add
954
+ * @public
955
+ * @example
956
+ * ```js
957
+ * const entity = entityManager.createEntity();
958
+ * entityManager.addArchetype(entity, archetype);
959
+ * ```
960
+ */
961
+ addArchetype(entity: Entity, { components, disabledComponents, children, enabled }: Archetype): void;
948
962
  private createEntityFromArray;
949
963
  /**
950
964
  * Creates an Entity from an Archetype.
@@ -1644,8 +1658,12 @@ interface GameConfig {
1644
1658
  mousePosition: boolean;
1645
1659
  /** Show text renderer bounding boxes */
1646
1660
  textRendererBoundingBoxes: boolean;
1661
+ /** Show button shapes */
1662
+ buttons?: boolean;
1647
1663
  /** Color of the colliders, default "#00FF00" (green) */
1648
1664
  collidersColor?: string;
1665
+ /** Color of the button shapes, default "#FF00FF" (magenta) */
1666
+ buttonColor?: string;
1649
1667
  /** Color of the text box, default "#0000FF" (blue) */
1650
1668
  textBoxColor?: string;
1651
1669
  /** Color of the text, default "#00FF00" (green) */
@@ -2619,17 +2637,25 @@ declare enum ButtonShape {
2619
2637
  *
2620
2638
  * const tiledWrapper = new TiledWrapper({
2621
2639
  * tilemap: assetManager.getJson("tilemap.json"),
2622
- * layerToRender: "Ground"
2640
+ * layerToRender: "Ground",
2641
+ * objects: new Map([
2642
+ * ["Player", playerArchetype],
2643
+ * ["Coin", [new Transform(), new SpriteRenderer({ image: "coin.png" })]],
2644
+ * ["Door", (properties) => doorArchetype(properties.get("locked"))]
2645
+ * ])
2623
2646
  * });
2624
2647
  * ```
2625
2648
  */
2626
2649
  interface TiledWrapperOptions {
2627
2650
  tilemap: TiledTilemap | string;
2628
2651
  layerToRender: string;
2652
+ objects: Map<string, TiledObjectBlueprint>;
2629
2653
  }
2630
2654
  /**
2631
2655
  * The TiledWrapper component wraps a Tiled map editor tilemap and handles rendering a specific layer.\
2632
- * It provides an interface between Tiled's map format and the engine's tilemap rendering system.
2656
+ * It provides an interface between Tiled's map format and the engine's tilemap rendering system.\
2657
+ * The tiles animated in Tiled are mapped to the animations of the TilemapRenderer tileset.\
2658
+ * It can also create entities from the objects of the tilemap, matching them by class with the `objects` map.
2633
2659
  * @public
2634
2660
  * @category Components
2635
2661
  * @example
@@ -2654,10 +2680,62 @@ declare class TiledWrapper {
2654
2680
  tilemap: TiledTilemap | string;
2655
2681
  /** The layer to render. */
2656
2682
  layerToRender: string;
2683
+ /**
2684
+ * Entities to create from the objects found in the tilemap, keyed by the object class.\
2685
+ * Objects are matched by class in every visible object layer of the tilemap.
2686
+ */
2687
+ objects: Map<string, TiledObjectBlueprint>;
2688
+ /** @internal */
2689
+ _processed: boolean;
2690
+ /** @internal */
2691
+ _objectsCreated: boolean;
2692
+ /** @internal */
2693
+ _animationsMapped: boolean;
2694
+ /** The coordinates (in tiles) of the top-left corner of the rendered layer. @internal */
2695
+ _origin: Vector2;
2657
2696
  /** @internal */
2658
2697
  static componentName: string;
2659
2698
  constructor(options?: Partial<TiledWrapperOptions>);
2699
+ /**
2700
+ * Reads the tilemap again, to apply the changes made to it at runtime, such as rendering another layer.\
2701
+ * The entities created from the objects of the tilemap are not created again.\
2702
+ * The TilemapRenderer and the TilemapCollider of the entity need to be refreshed too.\
2703
+ * This operation is expensive, avoid calling it on every frame.
2704
+ */
2705
+ refresh(): void;
2660
2706
  }
2707
+ /**
2708
+ * The properties of a Tiled object, keyed by property name.\
2709
+ * `int` and `float` properties are given as `number`, `bool` as `boolean`, `string`, `color` and `file` as `string`,\
2710
+ * and `class` as a nested set of values.\
2711
+ * Properties of type `object` are given as the {@link Entity} created for the referenced Tiled object,\
2712
+ * or `undefined` if no entity was created for it.
2713
+ * @public
2714
+ * @category Components Configuration
2715
+ */
2716
+ type TiledObjectProperties = Map<string, number | boolean | string | Entity | Record<string, unknown>>;
2717
+ /**
2718
+ * Creates the entity for a Tiled object, based on its properties.
2719
+ * @param properties The properties of the Tiled object
2720
+ * @param object The Tiled object itself
2721
+ * @returns An archetype or a collection of components
2722
+ * @public
2723
+ * @category Components Configuration
2724
+ * @example
2725
+ * ```js
2726
+ * const doorFactory = (properties, object) => ({
2727
+ * components: [new Door({ locked: properties.get("locked"), lever: properties.get("lever") })]
2728
+ * });
2729
+ * ```
2730
+ */
2731
+ type TiledObjectFactory = (properties: TiledObjectProperties, object: TiledObject) => Archetype | Component[];
2732
+ /**
2733
+ * Defines the entity to create for a Tiled object class. It can be an archetype, a collection of components,\
2734
+ * or a {@link TiledObjectFactory} function that builds either of them from the object's properties.
2735
+ * @public
2736
+ * @category Components Configuration
2737
+ */
2738
+ type TiledObjectBlueprint = Archetype | Component[] | TiledObjectFactory;
2661
2739
  /**
2662
2740
  * @public
2663
2741
  * @category Components Configuration
@@ -2666,15 +2744,55 @@ interface TiledTilemap {
2666
2744
  width: number;
2667
2745
  height: number;
2668
2746
  infinite: boolean;
2669
- layers: (TiledLayer | TiledObjectLayer)[];
2747
+ layers: (TiledLayer | TiledObjectLayer | TiledGroupLayer)[];
2670
2748
  renderorder: string;
2671
- tilesets: {
2672
- firstgid: number;
2673
- }[];
2749
+ tilesets: TiledTileset[];
2674
2750
  tilewidth: number;
2675
2751
  tileheight: number;
2676
2752
  properties?: TiledProperty[];
2677
2753
  }
2754
+ /**
2755
+ * @public
2756
+ * @category Components Configuration
2757
+ */
2758
+ interface TiledTileset {
2759
+ /** The id of the first tile of the tileset. The id of a tile is this value plus the id it has within the tileset */
2760
+ firstgid: number;
2761
+ /** Only present in external tilesets, which are not read by the engine */
2762
+ source?: string;
2763
+ name?: string;
2764
+ image?: string;
2765
+ columns?: number;
2766
+ tilecount?: number;
2767
+ tilewidth?: number;
2768
+ tileheight?: number;
2769
+ margin?: number;
2770
+ spacing?: number;
2771
+ /** Only the tiles with data of their own, such as animations or properties */
2772
+ tiles?: TiledTilesetTile[];
2773
+ }
2774
+ /**
2775
+ * @public
2776
+ * @category Components Configuration
2777
+ */
2778
+ interface TiledTilesetTile {
2779
+ /** The id of the tile within the tileset */
2780
+ id: number;
2781
+ animation?: TiledTileAnimationFrame[];
2782
+ objectgroup?: TiledObjectLayer;
2783
+ properties?: TiledProperty[];
2784
+ type?: string;
2785
+ }
2786
+ /**
2787
+ * @public
2788
+ * @category Components Configuration
2789
+ */
2790
+ interface TiledTileAnimationFrame {
2791
+ /** The duration of the frame in milliseconds */
2792
+ duration: number;
2793
+ /** The id of the tile to render, within the tileset */
2794
+ tileid: number;
2795
+ }
2678
2796
  /**
2679
2797
  * @public
2680
2798
  * @category Components Configuration
@@ -2721,9 +2839,29 @@ interface TiledObjectLayer {
2721
2839
  objects: TiledObject[];
2722
2840
  opacity: number;
2723
2841
  type: "objectgroup";
2724
- visible: true;
2842
+ visible: boolean;
2843
+ x: number;
2844
+ y: number;
2845
+ offsetx?: number;
2846
+ offsety?: number;
2847
+ properties?: TiledProperty[];
2848
+ }
2849
+ /**
2850
+ * A layer that groups other layers. Its offset and its visibility are applied to all of them.
2851
+ * @public
2852
+ * @category Components Configuration
2853
+ */
2854
+ interface TiledGroupLayer {
2855
+ id: number;
2856
+ name: string;
2857
+ type: "group";
2858
+ layers: (TiledLayer | TiledObjectLayer | TiledGroupLayer)[];
2859
+ opacity: number;
2860
+ visible: boolean;
2725
2861
  x: number;
2726
2862
  y: number;
2863
+ offsetx?: number;
2864
+ offsety?: number;
2727
2865
  properties?: TiledProperty[];
2728
2866
  }
2729
2867
  /**
@@ -2731,13 +2869,17 @@ interface TiledObjectLayer {
2731
2869
  * @category Components Configuration
2732
2870
  */
2733
2871
  interface TiledObject {
2734
- gid: number;
2872
+ /** Only present in tile objects. Their origin is the bottom-left corner, instead of the top-left corner */
2873
+ gid?: number;
2735
2874
  height: number;
2736
2875
  id: number;
2737
2876
  name: string;
2738
2877
  rotation: number;
2739
- type: string;
2740
- visible: true;
2878
+ /** The class of the object. Tiled 1.9 exports it as `class`, the other versions as `type` */
2879
+ type?: string;
2880
+ /** The class of the object, as exported by Tiled 1.9 */
2881
+ class?: string;
2882
+ visible: boolean;
2741
2883
  width: number;
2742
2884
  x: number;
2743
2885
  y: number;
@@ -2757,8 +2899,9 @@ interface TiledObject {
2757
2899
  */
2758
2900
  interface TiledProperty {
2759
2901
  name: string;
2760
- type: "int" | "bool" | "float" | "color" | "string";
2761
- value: number | string | boolean;
2902
+ type: "int" | "bool" | "float" | "color" | "string" | "file" | "object" | "class";
2903
+ /** Properties of type `object` hold the id of another Tiled object, and `class` properties hold a nested set of values */
2904
+ value: number | string | boolean | Record<string, unknown>;
2762
2905
  }
2763
2906
 
2764
2907
  /**
@@ -3317,6 +3460,11 @@ declare class TilemapCollider implements Collider {
3317
3460
  /** @internal */
3318
3461
  static componentName: string;
3319
3462
  constructor(options?: Partial<TilemapColliderOptions>);
3463
+ /**
3464
+ * Generates the collider shapes again, to apply the changes made to the tilemap at runtime.\
3465
+ * This operation is expensive, avoid calling it on every frame.
3466
+ */
3467
+ refresh(): void;
3320
3468
  }
3321
3469
 
3322
3470
  declare enum RenderDataType {
@@ -4366,6 +4514,7 @@ interface TilemapRendererOptions {
4366
4514
  maskColorMix: number;
4367
4515
  opacity: number;
4368
4516
  smooth: boolean;
4517
+ offset: Vector2;
4369
4518
  }
4370
4519
  /**
4371
4520
  * The TilemapRenderer component renders 2D tile-based maps to the screen.\
@@ -4427,13 +4576,23 @@ declare class TilemapRenderer {
4427
4576
  maskColorMix: number;
4428
4577
  /** TRUE for smooth pixels (not recommended for pixel art) */
4429
4578
  smooth: boolean;
4579
+ /** X-Y axis offset */
4580
+ offset: Vector2;
4430
4581
  /** @internal */
4431
4582
  _processed: boolean;
4432
4583
  /** @internal */
4584
+ _dataFromChunks: boolean;
4585
+ /** @internal */
4433
4586
  _renderData: TilemapRenderData[];
4434
4587
  /** @internal */
4435
4588
  static componentName: string;
4436
4589
  constructor(options?: Partial<TilemapRendererOptions>);
4590
+ /**
4591
+ * Processes the tilemap data again, to apply the changes made to it at runtime.\
4592
+ * The array that was generated from the other one is emptied, so it is generated again.\
4593
+ * This operation is expensive, avoid calling it on every frame.
4594
+ */
4595
+ refresh(): void;
4437
4596
  }
4438
4597
  /**
4439
4598
  * TileAnimation configuration
@@ -5236,4 +5395,4 @@ declare const SYMBOLS: {
5236
5395
  TimeManager: symbol;
5237
5396
  };
5238
5397
 
5239
- 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 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 };
5398
+ 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 };