angry-pixel 2.0.21 → 2.1.0

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
@@ -352,7 +352,7 @@ declare class Rectangle {
352
352
  * @param rect The target rectangle
353
353
  * @returns TRUE or FALSE
354
354
  */
355
- overlaps(rect: Rectangle): boolean;
355
+ intersects(rect: Rectangle): boolean;
356
356
  /**
357
357
  * Check if the target rectangle is contained
358
358
  *
@@ -367,6 +367,7 @@ declare class Rectangle {
367
367
  * @returns TRUE or FALSE
368
368
  */
369
369
  contains(vector: Vector2): boolean;
370
+ toString(): string;
370
371
  }
371
372
 
372
373
  /**
@@ -654,6 +655,81 @@ type SearchResult<T extends Component> = {
654
655
  type SearchCriteria = {
655
656
  [key: string]: any;
656
657
  };
658
+ /**
659
+ * This type represents an Entity Archetype
660
+ * @public
661
+ * @category Entity-Component-System
662
+ */
663
+ type Archetype = {
664
+ components: (ArchetypeComponent | Component)[];
665
+ children?: Archetype[];
666
+ enabled?: boolean;
667
+ };
668
+ /**
669
+ * This type represents an Entity Archetype Component
670
+ * @public
671
+ * @category Entity-Component-System
672
+ */
673
+ type ArchetypeComponent<T extends Component = Component> = {
674
+ type: ComponentType<T>;
675
+ data?: Partial<T>;
676
+ enabled?: boolean;
677
+ };
678
+ /**
679
+ * This interface is used for the creation of system classes. You will have to inject the dependencies you need manully.
680
+ * @public
681
+ * @category Entity-Component-System
682
+ * @example
683
+ * ```typescript
684
+ * class PlayerSystem implements System {
685
+ * @inject(Symbols.EntityManager) private readonly entityManager: EntityManager;
686
+ *
687
+ * public onUpdate() {
688
+ * this.entityManager.search(Player).forEach(({component, entity}) => {
689
+ * // do somethng
690
+ * });
691
+ * }
692
+ * }
693
+ * ```
694
+ */
695
+ interface System {
696
+ /**
697
+ * This method is called the first time the system is enabled
698
+ * @public
699
+ */
700
+ onCreate?(): void;
701
+ /**
702
+ * This method is called when the system is destroyed
703
+ * @public
704
+ */
705
+ onDestroy?(): void;
706
+ /**
707
+ * This method is called when the system is disabled
708
+ * @public
709
+ */
710
+ onDisabled?(): void;
711
+ /**
712
+ * This method is called when the system is enabled
713
+ * @public
714
+ */
715
+ onEnabled?(): void;
716
+ /**
717
+ * This method is called once every frame
718
+ * @public
719
+ */
720
+ onUpdate(): void;
721
+ }
722
+ /**
723
+ * This type represents a system class
724
+ * @public
725
+ * @category Entity-Component-System
726
+ */
727
+ type SystemType<T extends System = System> = {
728
+ new (...args: any[]): T;
729
+ };
730
+ /** @internal */
731
+ type SystemGroup = string | number | symbol;
732
+
657
733
  /**
658
734
  * The EntityManager manages the entities and components.\
659
735
  * It provides the necessary methods for reading and writing entities and components.
@@ -666,7 +742,10 @@ declare class EntityManager {
666
742
  private entities;
667
743
  private components;
668
744
  private disabledEntities;
745
+ private manuallyDisabledEntities;
669
746
  private disabledComponents;
747
+ private parentEntities;
748
+ private childEntities;
670
749
  /**
671
750
  * Creates an entity without component
672
751
  * @return The created Entity
@@ -677,6 +756,83 @@ declare class EntityManager {
677
756
  * ```
678
757
  */
679
758
  createEntity(): Entity;
759
+ /**
760
+ * Creates an Entity based on an Archetype
761
+ * @param archetype The Archetype to create the Entity
762
+ * @return The created Entity
763
+ * @public
764
+ * @example
765
+ * ```js
766
+ * // Using ArchetypeComponent to define components
767
+ * const entity = entityManager.createEntity({
768
+ * components: [
769
+ * {type: Transform, data: {position: new Vector2(100, 100)}},
770
+ * {type: SpriteRenderer, data: {image: "images/player.png"}},
771
+ * {type: Player},
772
+ * ],
773
+ * children: [
774
+ * {
775
+ * components: [
776
+ * {type: Transform, data: {position: new Vector2(8, 0)}},
777
+ * {type: SpriteRenderer, data: {image: "images/sword.png"}},
778
+ * {type: Weapon, data: {damage: 10}},
779
+ * ],
780
+ * },
781
+ * {
782
+ * components: [
783
+ * {type: Transform, data: {position: new Vector2(-8, 0)}},
784
+ * {type: SpriteRenderer, data: {image: "images/shield.png"}},
785
+ * {type: Shield, data: {defense: 5}, enabled: false},
786
+ * ],
787
+ * },
788
+ * {
789
+ * components: [
790
+ * {type: Transform, data: {position: new Vector2(8, 0)}},
791
+ * {type: SpriteRenderer, data: {image: "images/staf.png"}},
792
+ * {type: Staff, data: {mana: 5}},
793
+ * ],
794
+ * enabled: false,
795
+ * }
796
+ * ]
797
+ * });
798
+ * ```
799
+ * @example
800
+ * ```js
801
+ * // Using Component instances as templates
802
+ * const entity = entityManager.createEntity({
803
+ * components: [
804
+ * new Transform({position: new Vector2(100, 100)}),
805
+ * new SpriteRenderer({image: "images/player.png"}),
806
+ * new Player(),
807
+ * ],
808
+ * children: [
809
+ * {
810
+ * components: [
811
+ * new Transform({position: new Vector2(8, 0)}),
812
+ * new SpriteRenderer({image: "images/sword.png"}),
813
+ * new Weapon({damage: 10}),
814
+ * ],
815
+ * },
816
+ * {
817
+ * components: [
818
+ * new Transform({position: new Vector2(-8, 0)}),
819
+ * new SpriteRenderer({image: "images/shield.png"}),
820
+ * new Shield({defense: 5}),
821
+ * ],
822
+ * },
823
+ * {
824
+ * components: [
825
+ * new Transform({position: new Vector2(8, 0)}),
826
+ * new SpriteRenderer({image: "images/staf.png"}),
827
+ * new Staff({mana: 5}),
828
+ * ],
829
+ * enabled: false,
830
+ * }
831
+ * ]
832
+ * });
833
+ * ```
834
+ */
835
+ createEntity(archetype: Archetype): Entity;
680
836
  /**
681
837
  * Creates an Entity based on a collection of Component instances and ComponentTypes
682
838
  * @param components A collection of component instances and component classes
@@ -690,7 +846,9 @@ declare class EntityManager {
690
846
  * ]);
691
847
  * ```
692
848
  */
693
- createEntity(components: Array<ComponentType | Component>): Entity;
849
+ createEntity(components: Array<ComponentType | Component>, parent?: Entity): Entity;
850
+ private createEntityFromComponents;
851
+ private createEntityFromArchetype;
694
852
  /**
695
853
  * Creates multiple entities based on an array of component collections
696
854
  * @param componentsList An array of collections of component instances and component classes
@@ -698,20 +856,22 @@ declare class EntityManager {
698
856
  * @public
699
857
  * @example
700
858
  * ```js
701
- * const parent = [
859
+ * const player = [
702
860
  * new Transform({position: new Vector2(100, 100)}),
703
- * SpriteRenderer
861
+ * SpriteRenderer,
862
+ * Player
704
863
  * ];
705
864
  *
706
- * const child = [
707
- * new Transform({parent: parent[0]}),
708
- * SpriteRenderer
865
+ * const enemy = [
866
+ * new Transform({position: new Vector2(-100, 100)}),
867
+ * SpriteRenderer,
868
+ * Enemy
709
869
  * ];
710
870
  *
711
- * const entity = entityManager.createEntities([parent, child]);
871
+ * const entities = entityManager.createEntities([player, enemy]);
712
872
  * ```
713
873
  */
714
- createEntities(componentsList: Component[][]): Entity[];
874
+ createEntities(componentsList: Array<ComponentType | Component>[]): Entity[];
715
875
  /**
716
876
  * Removes an Entity and all its Components
717
877
  * @param entity The entity to remove
@@ -753,7 +913,11 @@ declare class EntityManager {
753
913
  */
754
914
  isEntityEnabled(entity: Entity): boolean;
755
915
  /**
756
- * Enables an Entity
916
+ * Enables an Entity.\
917
+ * The entity's components will be included in the `search` results\
918
+ * and therefore will be processed by their respective systems\
919
+ * (the engine built-in systems use the `search` method to retrieve the entities).
920
+ * If the entity has children, they will also be enabled, except for those that have been manually disabled.
757
921
  * @param entity The entity to be enabled
758
922
  * @public
759
923
  * @example
@@ -763,7 +927,11 @@ declare class EntityManager {
763
927
  */
764
928
  enableEntity(entity: Entity): void;
765
929
  /**
766
- * Disables an Entity
930
+ * Disables an entity.\
931
+ * The entity's components will not be included in the `search` results\
932
+ * and therefore will not be processed by their respective systems\
933
+ * (the engine built-in systems use the `search` method to retrieve the entities).
934
+ * If the entity has children, they will also be disabled.
767
935
  * @param entity The entity to be disabled
768
936
  * @public
769
937
  * @example
@@ -792,6 +960,60 @@ declare class EntityManager {
792
960
  * ```
793
961
  */
794
962
  enableEntitiesByComponent(componentType: ComponentType): void;
963
+ /**
964
+ * Sets a parent-child relationship between two entities
965
+ * @param child The child entity
966
+ * @param parent The parent entity
967
+ * @public
968
+ * @example
969
+ * ```js
970
+ * entityManager.setParent(child, parent);
971
+ * ```
972
+ */
973
+ setParent(child: Entity, parent: Entity): void;
974
+ /**
975
+ * Returns the parent entity of the child entity
976
+ * @param child
977
+ * @returns The parent entity
978
+ * @public
979
+ * @example
980
+ * ```js
981
+ * const parent = entityManager.getParent(child);
982
+ * ```
983
+ */
984
+ getParent(child: Entity): Entity;
985
+ /**
986
+ * Returns all child entities of the parent entity
987
+ * @param parent
988
+ * @returns A collection of child entities
989
+ * @public
990
+ * @example
991
+ * ```js
992
+ * const children = entityManager.getChildren(parent);
993
+ * ```
994
+ */
995
+ getChildren(parent: Entity): Entity[];
996
+ /**
997
+ * Removes the parent-child relationship between two entities
998
+ * @param child The child entity
999
+ * @public
1000
+ * @example
1001
+ * ```js
1002
+ * entityManager.removeParent(child);
1003
+ * ```
1004
+ */
1005
+ removeParent(child: Entity): void;
1006
+ /**
1007
+ * Removes a child entity from the parent entity
1008
+ * @param parent The parent entity
1009
+ * @param child The child entity
1010
+ * @public
1011
+ * @example
1012
+ * ```js
1013
+ * entityManager.removeChild(parent, child);
1014
+ * ```
1015
+ */
1016
+ removeChild(parent: Entity, child: Entity): void;
795
1017
  /**
796
1018
  * Adds a component to the entity
797
1019
  * @param entity The Entity to which the component will be added
@@ -949,6 +1171,18 @@ declare class EntityManager {
949
1171
  * ```
950
1172
  */
951
1173
  enableComponent<T extends Component>(entity: Entity, componentType: ComponentType<T>): void;
1174
+ /**
1175
+ * Returns the component of a parent entity, if it exists.
1176
+ * @param parent The parent entity
1177
+ * @param componentType The component class to search
1178
+ * @returns The instance of the component
1179
+ * @public
1180
+ * @example
1181
+ * ```js
1182
+ * const spriteRenderer = entityManager.getComponentFromParent(parent, SpriteRenderer);
1183
+ * ```
1184
+ */
1185
+ getComponentFromParent<T extends Component>(parent: Entity, componentType: ComponentType<T>): T | undefined;
952
1186
  /**
953
1187
  * Performs a search for entities given a component type.\
954
1188
  * This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.\
@@ -973,8 +1207,39 @@ declare class EntityManager {
973
1207
  * // do something with the component and entity
974
1208
  * })
975
1209
  * ```
1210
+ * @example
1211
+ * ```js
1212
+ * const searchResult = entityManager.search(Enemy, {status: "dead"}, true);
1213
+ * searchResult.forEach(({component, entity}) => {
1214
+ * // do something with the component and entity
1215
+ * })
1216
+ * ```
976
1217
  */
977
1218
  search<T extends Component>(componentType: ComponentType<T>, criteria?: SearchCriteria, includeDisabled?: boolean): SearchResult<T>[];
1219
+ /**
1220
+ * Performs a search for entities given a component type.\
1221
+ * This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.\
1222
+ * The second argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
1223
+ * @param componentType The component class
1224
+ * @param includeDisabled TRUE to incluide disabled entities and components, FALSE otherwise
1225
+ * @returns SearchResult
1226
+ * @public
1227
+ * @example
1228
+ * ```js
1229
+ * const searchResult = entityManager.search(SpriteRenderer);
1230
+ * searchResult.forEach(({component, entity}) => {
1231
+ * // do something with the component and entity
1232
+ * })
1233
+ * ```
1234
+ * @example
1235
+ * ```js
1236
+ * const searchResult = entityManager.search(Enemy, true);
1237
+ * searchResult.forEach(({component, entity}) => {
1238
+ * // do something with the component and entity
1239
+ * })
1240
+ * ```
1241
+ */
1242
+ search<T extends Component>(componentType: ComponentType<T>, includeDisabled?: boolean): SearchResult<T>[];
978
1243
  /**
979
1244
  * Performs an entity search given a collection of component types.\
980
1245
  * The entities found must have an instance of all the given component types.\
@@ -988,63 +1253,34 @@ declare class EntityManager {
988
1253
  * ```
989
1254
  */
990
1255
  searchEntitiesByComponents(componentTypes: ComponentType[]): Entity[];
991
- private getComponentTypeId;
992
- }
993
-
994
- /**
995
- * This interface is used for the creation of system classes. You will have to inject the dependencies you need manully.
996
- * @public
997
- * @category Entity-Component-System
998
- * @example
999
- * ```typescript
1000
- * class PlayerSystem implements System {
1001
- * @inject(Symbols.EntityManager) private readonly entityManager: EntityManager;
1002
- *
1003
- * public onUpdate() {
1004
- * this.entityManager.search(Player).forEach(({component, entity}) => {
1005
- * // do somethng
1006
- * });
1007
- * }
1008
- * }
1009
- * ```
1010
- */
1011
- interface System {
1012
- /**
1013
- * This method is called the first time the system is enabled
1014
- * @public
1015
- */
1016
- onCreate?(): void;
1017
- /**
1018
- * This method is called when the system is destroyed
1019
- * @public
1020
- */
1021
- onDestroy?(): void;
1022
- /**
1023
- * This method is called when the system is disabled
1024
- * @public
1025
- */
1026
- onDisabled?(): void;
1027
1256
  /**
1028
- * This method is called when the system is enabled
1029
- * @public
1030
- */
1031
- onEnabled?(): void;
1032
- /**
1033
- * This method is called once every frame
1257
+ * Performs a search for entities that have a component of the given type and are children of the parent entity.\
1258
+ * This method returns a collection of objects of type SearchResult, which has the entity found, and the instance of the component.\
1259
+ * The third argument determines if disabled entities or components are included in the search result,\its default value is FALSE.
1260
+ * @param parent The parent entity
1261
+ * @param componentType The component class
1262
+ * @param includeDisabled TRUE to incluide disabled entities and components, FALSE otherwise
1263
+ * @returns SearchResult
1034
1264
  * @public
1265
+ * @example
1266
+ * ```js
1267
+ * const searchResult = entityManager.searchInChildren(parent, SpriteRenderer);
1268
+ * searchResult.forEach(({component, entity}) => {
1269
+ * // do something with the component and entity
1270
+ * })
1271
+ * ```
1272
+ * @example
1273
+ * ```js
1274
+ * const searchResult = entityManager.searchInChildren(parent, SpriteRenderer, true);
1275
+ * searchResult.forEach(({component, entity}) => {
1276
+ * // do something with the component and entity
1277
+ * })
1278
+ * ```
1035
1279
  */
1036
- onUpdate(): void;
1280
+ searchInChildren<T extends Component>(parent: Entity, componentType: ComponentType<T>, includeDisabled?: boolean): SearchResult<T>[];
1281
+ private getComponentTypeId;
1037
1282
  }
1038
- /**
1039
- * This type represents a system class
1040
- * @public
1041
- * @category Entity-Component-System
1042
- */
1043
- type SystemType<T extends System = System> = {
1044
- new (...args: any[]): T;
1045
- };
1046
- /** @internal */
1047
- type SystemGroup = string | number | symbol;
1283
+
1048
1284
  /**
1049
1285
  * The SystemManager manages the systems.\
1050
1286
  * It provides the necessary methods for reading and writing systems.
@@ -1842,22 +2078,6 @@ declare enum ButtonShape {
1842
2078
  Circumference = 1
1843
2079
  }
1844
2080
 
1845
- /**
1846
- * @public
1847
- * @category Components
1848
- */
1849
- declare class Children {
1850
- entities: Entity[];
1851
- }
1852
-
1853
- /**
1854
- * @public
1855
- * @category Components
1856
- */
1857
- declare class Parent {
1858
- entity: Entity;
1859
- }
1860
-
1861
2081
  /**
1862
2082
  * @public
1863
2083
  * @category Components
@@ -1986,10 +2206,6 @@ interface TransformOptions {
1986
2206
  position: Vector2;
1987
2207
  scale: Vector2;
1988
2208
  rotation: number;
1989
- parent: Transform;
1990
- localPosition: Vector2;
1991
- localScale: Vector2;
1992
- localRotation: number;
1993
2209
  }
1994
2210
  /**
1995
2211
  * @public
@@ -2009,14 +2225,9 @@ declare class Transform {
2009
2225
  /** The real rotation in the simulated world. It has the same value as `rotation` property if there is no parent */
2010
2226
  localRotation: number;
2011
2227
  /** @internal */
2012
- _parentEntity: Entity;
2228
+ _awake: boolean;
2013
2229
  /** @internal */
2014
- _childEntities: Entity[];
2015
- private _parent;
2016
- /** The parent transform. The position property became relative to this transform */
2017
- get parent(): Transform;
2018
- /** The parent transform. The position property became relative to this transform */
2019
- set parent(parent: Transform);
2230
+ _parent: Transform;
2020
2231
  constructor(options?: Partial<TransformOptions>);
2021
2232
  }
2022
2233
 
@@ -3767,4 +3978,4 @@ declare const Symbols: {
3767
3978
  TimeManager: symbol;
3768
3979
  };
3769
3980
 
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 };
3981
+ export { Animation, type AnimationSlice, Animator, type AnimatorOptions, type Archetype, type ArchetypeComponent, AssetManager, AudioPlayer, type AudioPlayerAction, type AudioPlayerOptions, type AudioPlayerState, 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, 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, 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 };