@awesome-ecs/abstract 0.20.1 → 0.21.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.
Files changed (48) hide show
  1. package/README.md +129 -0
  2. package/dist/components/index.cjs.map +1 -1
  3. package/dist/components/index.d.cts +2 -2
  4. package/dist/components/index.d.ts +2 -2
  5. package/dist/components/index.js.map +1 -1
  6. package/dist/entities/index.cjs.map +1 -1
  7. package/dist/entities/index.d.cts +21 -4
  8. package/dist/entities/index.d.ts +21 -4
  9. package/dist/entities/index.js.map +1 -1
  10. package/dist/entity-repository-BlSpo-x2.d.ts +253 -0
  11. package/dist/entity-repository-DJ1xbvaN.d.cts +253 -0
  12. package/dist/factories/index.d.cts +41 -13
  13. package/dist/factories/index.d.ts +41 -13
  14. package/dist/index-B1KXekZD.d.ts +199 -0
  15. package/dist/index-CnlpX7ys.d.cts +199 -0
  16. package/dist/performance-timer-BVyl0SRs.d.cts +45 -0
  17. package/dist/performance-timer-BVyl0SRs.d.ts +45 -0
  18. package/dist/pipeline-9bVMwJKD.d.ts +161 -0
  19. package/dist/pipeline-CzwetuCd.d.cts +161 -0
  20. package/dist/pipelines/index.cjs.map +1 -1
  21. package/dist/pipelines/index.d.cts +61 -16
  22. package/dist/pipelines/index.d.ts +61 -16
  23. package/dist/pipelines/index.js.map +1 -1
  24. package/dist/systems/index.cjs.map +1 -1
  25. package/dist/systems/index.d.cts +76 -24
  26. package/dist/systems/index.d.ts +76 -24
  27. package/dist/systems/index.js.map +1 -1
  28. package/dist/systems-runtime-context-Bz9hIdKT.d.cts +330 -0
  29. package/dist/systems-runtime-context-C_Tsvoym.d.ts +330 -0
  30. package/dist/types-cZ-1lGPD.d.cts +77 -0
  31. package/dist/types-cZ-1lGPD.d.ts +77 -0
  32. package/dist/utils/index.cjs.map +1 -1
  33. package/dist/utils/index.d.cts +63 -3
  34. package/dist/utils/index.d.ts +63 -3
  35. package/dist/utils/index.js.map +1 -1
  36. package/package.json +2 -2
  37. package/dist/entity-repository-BASmOrq7.d.ts +0 -120
  38. package/dist/entity-repository-DmfcUSrX.d.cts +0 -120
  39. package/dist/index-BPDsRt_F.d.ts +0 -117
  40. package/dist/index-DK2CXVZ8.d.cts +0 -117
  41. package/dist/performance-timer-XvdCbcAE.d.cts +0 -13
  42. package/dist/performance-timer-XvdCbcAE.d.ts +0 -13
  43. package/dist/pipeline-BowCAITe.d.cts +0 -83
  44. package/dist/pipeline-D43CXxWG.d.ts +0 -83
  45. package/dist/systems-runtime-context-CDVzeB9f.d.ts +0 -162
  46. package/dist/systems-runtime-context-CpgxOdc8.d.cts +0 -162
  47. package/dist/types-BNwBqRWY.d.cts +0 -22
  48. package/dist/types-BNwBqRWY.d.ts +0 -22
package/README.md CHANGED
@@ -5,6 +5,30 @@
5
5
  The Entity-Component-System is a well-known Architecture type used for responsive, complex applications, not only restricted to the Web.
6
6
  It's mostly associated with Game Engines, because of it's way of segregating Behavior from State, and allowing fine-control of the Runtime.
7
7
 
8
+ ## Real-World Usage Patterns
9
+
10
+ Based on the analysis of real-world usage in project-anchor, here are the key patterns that have proven effective:
11
+
12
+ ### Component Patterns
13
+
14
+ - **Component Type Enumeration**: Components are identified using a `ComponentType` enum, making component retrieval and identification type-safe and consistent
15
+ - **Specialized Component Focus**: Components focus on specific concerns (e.g., `CoordinatesComponent`, `RenderingComponent`, `AssetsComponent`)
16
+ - **Component Serialization**: Components can be marked with `isSerializable` to control which components get synchronized with external systems
17
+ - **Component Factories**: Using factory patterns to create and configure components with standard defaults
18
+
19
+ ### Entity Patterns
20
+
21
+ - **Type-Safe Entity Access**: Entities expose strongly-typed getters for their components
22
+ - **Entity Proxies**: Entities use proxy objects to reference other entities, maintaining relationships while avoiding direct dependencies
23
+ - **Entity Type Enumeration**: Entities are categorized using an `EntityType` enum
24
+ - **Entity Hierarchy**: Entities often form hierarchical relationships (e.g., scene → grid → tile)
25
+
26
+ ### System Organization
27
+
28
+ - **System Pipelines**: Systems are organized into distinct pipelines (initialize, update, render) that execute in sequence
29
+ - **System Modules**: Systems are grouped in modules that target specific entity types
30
+ - **Middleware Approach**: Systems implement the middleware pattern for clean, composable behavior
31
+
8
32
  ## Building blocks
9
33
 
10
34
  ### Entities
@@ -97,3 +121,108 @@ The Render Systems can be skipped from the Runtime, if needed. That can be usefu
97
121
  The Dispatch Systems are built-in Systems in the Awesome ECS, and will take care of Dispatching Actions, Scheduling Entity updates, or synchronizing the Entity Repository with the latest Entity State in the current Context.
98
122
 
99
123
  The Dispatch Systems, as well as any other Runtime Stage, can be extended as needed by registering more System Middlewares in the Stage Pipeline.
124
+
125
+ ## Integration Examples
126
+
127
+ ### Component Definition Example
128
+
129
+ ```typescript
130
+ import { IComponent } from "@awesome-ecs/abstract";
131
+ import { ComponentType } from "../abstract/components/component-type";
132
+
133
+ export class CoordinatesComponent implements IComponent {
134
+ readonly componentType = ComponentType.coordinates;
135
+ readonly isSerializable = false;
136
+
137
+ // Component state
138
+ private coordinates: GridCoordinates;
139
+
140
+ // Component methods
141
+ setTileRadius(value: SpaceMeasurement) {
142
+ this.coordinates = new GridCoordinates(value);
143
+ }
144
+
145
+ getCenterPointFor(position: GridPosition): GridPoint {
146
+ return this.coordinates.getCenterPointFor(position);
147
+ }
148
+ }
149
+ ```
150
+
151
+ ### Entity Definition Example
152
+
153
+ ```typescript
154
+ import { EntityBase } from "@awesome-ecs/core";
155
+ import { EntityProxy, EntityUid, IEntityModel, IEntityProxy } from "@awesome-ecs/abstract";
156
+ import { ComponentType } from "../abstract/components/component-type";
157
+ import { EntityType } from "../abstract/entities/entity-type";
158
+
159
+ export class GridEntity extends EntityBase<GridModel> {
160
+ // Entity proxies for relationships
161
+ get sceneProxy(): EntityProxy<SceneEntity> {
162
+ return this.getProxy(EntityType.scene);
163
+ }
164
+
165
+ get buildingProxies(): IterableIterator<EntityProxy<BuildingEntity>> {
166
+ return this.getProxies(EntityType.building);
167
+ }
168
+
169
+ // Component accessors
170
+ get coordinates(): CoordinatesComponent {
171
+ return this.getComponent(ComponentType.coordinates);
172
+ }
173
+
174
+ get rendering(): RenderingComponent<GridRenderingContext> {
175
+ return this.getComponent(ComponentType.rendering);
176
+ }
177
+ }
178
+ ```
179
+
180
+ ### System Module Example
181
+
182
+ ```typescript
183
+ import { SystemPipelineType } from "@awesome-ecs/abstract";
184
+ import { LocalSystemsModuleBase } from "../abstract/systems/system-module-base";
185
+
186
+ export class GridSystemsModule extends LocalSystemsModuleBase<GridEntity> {
187
+ constructor(
188
+ // Systems injected via dependency injection
189
+ gridContainerInitializerSystem: GridContainerInitializerSystem,
190
+ gridCoordinatesInitializerSystem: GridCoordinatesInitializerSystem,
191
+ gridPerimeterRenderingSystem: GridPerimeterRenderingSystem
192
+ ) {
193
+ super();
194
+
195
+ // Register systems for different pipeline stages
196
+ this.registerSystems(SystemPipelineType.initialize, [
197
+ gridContainerInitializerSystem,
198
+ gridCoordinatesInitializerSystem
199
+ ]);
200
+
201
+ this.registerSystems(SystemPipelineType.render, [
202
+ gridPerimeterRenderingSystem
203
+ ]);
204
+ }
205
+
206
+ // Entity factory method
207
+ protected initEntity(model: GridModel): GridEntity {
208
+ // Create and return entity instance
209
+ const entity = new GridEntity(
210
+ ComponentFactory.identity(EntityType.grid, model),
211
+ [
212
+ ComponentFactory.coordinates(),
213
+ ComponentFactory.rendering()
214
+ ],
215
+ [
216
+ // Entity relationships via proxies
217
+ model.parent,
218
+ {
219
+ entityType: EntityType.scene,
220
+ entityUid: IdGenerator.sceneUid(),
221
+ }
222
+ ]
223
+ );
224
+
225
+ return entity;
226
+ }
227
+ }
228
+ ```
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/index.ts","../../src/components/identity-component.ts"],"sourcesContent":["export * from './component';\nexport * from './identity-component';\n","import { IComponent } from './component';\nimport { EntityTypeUid, IEntityModel } from '../entities/entity';\nimport { Immutable } from '../utils/types';\n\nexport enum BasicComponentType {\n identity = 'identity',\n}\n\n/**\n * The `IdentityComponent` contains basic information regarding what makes the current Entity unique.\n */\nexport interface IdentityComponent<TModel extends IEntityModel> extends IComponent {\n /**\n * The Entity Type that defines what Category type the Entity is part of. There can be multiple Entities sharing the same EntityType.\n */\n readonly entityType: EntityTypeUid;\n\n /**\n * The Model is the basic information needed to create an `IEntity` when it's first initialized.\n * It provides a first snapshot of information needed for the successful creation of an Entity instance.\n */\n readonly model: Immutable<TModel>;\n\n /**\n * Keeps track when the Entity's systems have ran last. Useful to calculate the `DeltaTime` between runs.\n */\n readonly lastUpdated?: Date;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;","names":["BasicComponentType"]}
1
+ {"version":3,"sources":["../../src/components/index.ts","../../src/components/identity-component.ts"],"sourcesContent":["export * from './component';\nexport * from './identity-component';\n","import { EntityTypeUid, IEntityModel } from '../entities/entity';\nimport { Immutable } from '../utils/types';\nimport { IComponent } from './component';\n\n/**\n * The `BasicComponentType` enum defines the types of basic components available.\n */\nexport enum BasicComponentType {\n identity = 'identity'\n}\n\n/**\n * IdentityComponent interface represents the basic information regarding what makes the current Entity unique.\n * It extends the IComponent interface.\n *\n * @template TModel - The type of the model that extends IEntityModel.\n */\nexport interface IdentityComponent<TModel extends IEntityModel> extends IComponent {\n /**\n * The Entity Type that defines what Category type the Entity is part of.\n * There can be multiple Entities sharing the same EntityType.\n */\n readonly entityType: EntityTypeUid;\n\n /**\n * The Model is the basic information needed to create an `IEntity` when it's first initialized.\n * It provides a first snapshot of information needed for the successful creation of an Entity instance.\n *\n * @type {Immutable<TModel>}\n */\n readonly model: Immutable<TModel>;\n\n /**\n * Keeps track when the Entity's systems have ran last.\n * Useful to calculate the `DeltaTime` between runs.\n *\n * @type {Date | undefined}\n */\n readonly lastUpdated?: Date;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;","names":["BasicComponentType"]}
@@ -1,2 +1,2 @@
1
- export { B as BasicComponentType, C as ComponentTypeUid, g as IComponent, f as IdentityComponent } from '../index-DK2CXVZ8.cjs';
2
- import '../types-BNwBqRWY.cjs';
1
+ export { B as BasicComponentType, C as ComponentTypeUid, g as IComponent, f as IdentityComponent } from '../index-CnlpX7ys.cjs';
2
+ import '../types-cZ-1lGPD.cjs';
@@ -1,2 +1,2 @@
1
- export { B as BasicComponentType, C as ComponentTypeUid, g as IComponent, f as IdentityComponent } from '../index-BPDsRt_F.js';
2
- import '../types-BNwBqRWY.js';
1
+ export { B as BasicComponentType, C as ComponentTypeUid, g as IComponent, f as IdentityComponent } from '../index-B1KXekZD.js';
2
+ import '../types-cZ-1lGPD.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/identity-component.ts"],"sourcesContent":["import { IComponent } from './component';\nimport { EntityTypeUid, IEntityModel } from '../entities/entity';\nimport { Immutable } from '../utils/types';\n\nexport enum BasicComponentType {\n identity = 'identity',\n}\n\n/**\n * The `IdentityComponent` contains basic information regarding what makes the current Entity unique.\n */\nexport interface IdentityComponent<TModel extends IEntityModel> extends IComponent {\n /**\n * The Entity Type that defines what Category type the Entity is part of. There can be multiple Entities sharing the same EntityType.\n */\n readonly entityType: EntityTypeUid;\n\n /**\n * The Model is the basic information needed to create an `IEntity` when it's first initialized.\n * It provides a first snapshot of information needed for the successful creation of an Entity instance.\n */\n readonly model: Immutable<TModel>;\n\n /**\n * Keeps track when the Entity's systems have ran last. Useful to calculate the `DeltaTime` between runs.\n */\n readonly lastUpdated?: Date;\n}\n"],"mappings":";AAIO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;","names":["BasicComponentType"]}
1
+ {"version":3,"sources":["../../src/components/identity-component.ts"],"sourcesContent":["import { EntityTypeUid, IEntityModel } from '../entities/entity';\nimport { Immutable } from '../utils/types';\nimport { IComponent } from './component';\n\n/**\n * The `BasicComponentType` enum defines the types of basic components available.\n */\nexport enum BasicComponentType {\n identity = 'identity'\n}\n\n/**\n * IdentityComponent interface represents the basic information regarding what makes the current Entity unique.\n * It extends the IComponent interface.\n *\n * @template TModel - The type of the model that extends IEntityModel.\n */\nexport interface IdentityComponent<TModel extends IEntityModel> extends IComponent {\n /**\n * The Entity Type that defines what Category type the Entity is part of.\n * There can be multiple Entities sharing the same EntityType.\n */\n readonly entityType: EntityTypeUid;\n\n /**\n * The Model is the basic information needed to create an `IEntity` when it's first initialized.\n * It provides a first snapshot of information needed for the successful creation of an Entity instance.\n *\n * @type {Immutable<TModel>}\n */\n readonly model: Immutable<TModel>;\n\n /**\n * Keeps track when the Entity's systems have ran last.\n * Useful to calculate the `DeltaTime` between runs.\n *\n * @type {Date | undefined}\n */\n readonly lastUpdated?: Date;\n}\n"],"mappings":";AAOO,IAAK,qBAAL,kBAAKA,wBAAL;AACL,EAAAA,oBAAA,cAAW;AADD,SAAAA;AAAA,GAAA;","names":["BasicComponentType"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entities/index.ts","../../src/entities/entity-queue.ts"],"sourcesContent":["export * from './entity';\nexport * from './entity-events';\nexport * from './entity-proxies';\nexport * from './entity-queue';\nexport * from './entity-repository';\nexport * from './entity-scheduler';\nexport * from './entity-snapshot';\n","import { IEntityModel } from './entity';\nimport { IEntityProxy } from './entity-proxies';\nimport { IEntitySnapshot } from './entity-snapshot';\n\n/**\n * The `EntityUpdateType` specifies whether the current should `update` or `remove` the Entity.\n */\nexport enum EntityUpdateType {\n update = 'update',\n remove = 'remove',\n}\n\n/**\n * The `IEntityUpdate` represents an Entity update that should be applied over an (existing) Entity.\n */\nexport interface IEntityUpdate {\n type: EntityUpdateType;\n entity: IEntityProxy;\n model?: IEntityModel;\n snapshot?: IEntitySnapshot;\n}\n\n/**\n * The `IEntityUpdateQueue` is the main mechanism to queue and retrieve `EntityUpdate` instances.\n *\n * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.\n */\nexport interface IEntityUpdateQueue {\n readonly size: number;\n\n enqueue(change: IEntityUpdate): void;\n dequeue(): IEntityUpdate;\n\n peek(): IEntityUpdate;\n clear(): void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;","names":["EntityUpdateType"]}
1
+ {"version":3,"sources":["../../src/entities/index.ts","../../src/entities/entity-queue.ts"],"sourcesContent":["export * from './entity';\nexport * from './entity-events';\nexport * from './entity-proxies';\nexport * from './entity-queue';\nexport * from './entity-repository';\nexport * from './entity-scheduler';\nexport * from './entity-snapshot';\n","import { IEntityModel } from './entity';\nimport { IEntityProxy } from './entity-proxies';\nimport { IEntitySnapshot } from './entity-snapshot';\n\n/**\n * The `EntityUpdateType` enum specifies whether the current Entity should be `updated` or `removed`.\n */\nexport enum EntityUpdateType {\n update = 'update',\n remove = 'remove'\n}\n\n/**\n * The `IEntityUpdate` interface represents an Entity update that should be applied over an existing Entity.\n */\nexport interface IEntityUpdate {\n /**\n * The type of the update, which can be either `update` or `remove`.\n */\n type: EntityUpdateType;\n\n /**\n * The proxy of the Entity that needs to be updated.\n */\n entity: IEntityProxy;\n\n /**\n * Optional. The model of the Entity that needs to be updated.\n */\n model?: IEntityModel;\n\n /**\n * Optional. The snapshot of the Entity that needs to be updated.\n */\n snapshot?: IEntitySnapshot;\n}\n\n/**\n * The `IEntityUpdateQueue` interface is the main mechanism to queue and retrieve `EntityUpdate` instances.\n *\n * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.\n */\nexport interface IEntityUpdateQueue {\n /**\n * The number of `EntityUpdate` instances currently in the queue.\n */\n readonly size: number;\n\n /**\n * Adds an `EntityUpdate` instance to the end of the queue.\n * @param change - The `EntityUpdate` instance to be added.\n */\n enqueue(change: IEntityUpdate): void;\n\n /**\n * Removes and returns the `EntityUpdate` instance at the front of the queue.\n * @returns The `EntityUpdate` instance at the front of the queue.\n */\n dequeue(): IEntityUpdate;\n\n /**\n * Returns the `EntityUpdate` instance at the front of the queue without removing it.\n * @returns The `EntityUpdate` instance at the front of the queue.\n */\n peek(): IEntityUpdate;\n\n /**\n * Removes all `EntityUpdate` instances from the queue.\n */\n clear(): void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;","names":["EntityUpdateType"]}
@@ -1,7 +1,7 @@
1
- import { I as IEntityProxy } from '../index-DK2CXVZ8.cjs';
2
- export { d as EntityProxy, E as EntityTypeUid, a as EntityUid, c as IEntity, b as IEntityModel, e as IEntityProxiesManager } from '../index-DK2CXVZ8.cjs';
3
- export { a as EntityEventSubscriptionFilter, E as EntityEventUid, e as EntityUpdateType, b as IEntityEvent, d as IEntityEventsDispatcher, c as IEntityEventsManager, h as IEntityRepository, i as IEntitySnapshot, j as IEntitySnapshotProvider, f as IEntityUpdate, g as IEntityUpdateQueue, I as IEventData } from '../entity-repository-DmfcUSrX.cjs';
4
- import '../types-BNwBqRWY.cjs';
1
+ import { I as IEntityProxy } from '../index-CnlpX7ys.cjs';
2
+ export { d as EntityProxy, E as EntityTypeUid, a as EntityUid, c as IEntity, b as IEntityModel, e as IEntityProxiesManager } from '../index-CnlpX7ys.cjs';
3
+ export { a as EntityEventSubscriptionFilter, E as EntityEventUid, e as EntityUpdateType, b as IEntityEvent, d as IEntityEventsDispatcher, c as IEntityEventsManager, h as IEntityRepository, i as IEntitySnapshot, j as IEntitySnapshotProvider, f as IEntityUpdate, g as IEntityUpdateQueue, I as IEventData } from '../entity-repository-DJ1xbvaN.cjs';
4
+ import '../types-cZ-1lGPD.cjs';
5
5
 
6
6
  /**
7
7
  * The `IEntityScheduler` is the main way of queuing `IEntityUpdate` instances on an Interval (based on time or a custom implementation).
@@ -9,8 +9,25 @@ import '../types-BNwBqRWY.cjs';
9
9
  * It usually reads the Entities from the `IEntityRepository`, and uses the `IEntityUpdateQueue` to enqueue Entity updates.
10
10
  */
11
11
  interface IEntityScheduler {
12
+ /**
13
+ * Schedules an entity for updates at a specified interval.
14
+ *
15
+ * @param entityProxy - The entity to schedule for updates.
16
+ * @param intervalMs - The interval at which to schedule updates, in milliseconds. If not provided, the default interval will be used.
17
+ */
12
18
  schedule(entityProxy: IEntityProxy, intervalMs?: number): void;
19
+ /**
20
+ * Removes an entity from the scheduler.
21
+ *
22
+ * @param entityProxy - The entity to remove from the scheduler.
23
+ */
13
24
  remove(entityProxy: IEntityProxy): void;
25
+ /**
26
+ * Checks if an entity is currently scheduled for updates.
27
+ *
28
+ * @param entityProxy - The entity to check.
29
+ * @returns `true` if the entity is scheduled, `false` otherwise.
30
+ */
14
31
  has(entityProxy: IEntityProxy): boolean;
15
32
  }
16
33
 
@@ -1,7 +1,7 @@
1
- import { I as IEntityProxy } from '../index-BPDsRt_F.js';
2
- export { d as EntityProxy, E as EntityTypeUid, a as EntityUid, c as IEntity, b as IEntityModel, e as IEntityProxiesManager } from '../index-BPDsRt_F.js';
3
- export { a as EntityEventSubscriptionFilter, E as EntityEventUid, e as EntityUpdateType, b as IEntityEvent, d as IEntityEventsDispatcher, c as IEntityEventsManager, h as IEntityRepository, i as IEntitySnapshot, j as IEntitySnapshotProvider, f as IEntityUpdate, g as IEntityUpdateQueue, I as IEventData } from '../entity-repository-BASmOrq7.js';
4
- import '../types-BNwBqRWY.js';
1
+ import { I as IEntityProxy } from '../index-B1KXekZD.js';
2
+ export { d as EntityProxy, E as EntityTypeUid, a as EntityUid, c as IEntity, b as IEntityModel, e as IEntityProxiesManager } from '../index-B1KXekZD.js';
3
+ export { a as EntityEventSubscriptionFilter, E as EntityEventUid, e as EntityUpdateType, b as IEntityEvent, d as IEntityEventsDispatcher, c as IEntityEventsManager, h as IEntityRepository, i as IEntitySnapshot, j as IEntitySnapshotProvider, f as IEntityUpdate, g as IEntityUpdateQueue, I as IEventData } from '../entity-repository-BlSpo-x2.js';
4
+ import '../types-cZ-1lGPD.js';
5
5
 
6
6
  /**
7
7
  * The `IEntityScheduler` is the main way of queuing `IEntityUpdate` instances on an Interval (based on time or a custom implementation).
@@ -9,8 +9,25 @@ import '../types-BNwBqRWY.js';
9
9
  * It usually reads the Entities from the `IEntityRepository`, and uses the `IEntityUpdateQueue` to enqueue Entity updates.
10
10
  */
11
11
  interface IEntityScheduler {
12
+ /**
13
+ * Schedules an entity for updates at a specified interval.
14
+ *
15
+ * @param entityProxy - The entity to schedule for updates.
16
+ * @param intervalMs - The interval at which to schedule updates, in milliseconds. If not provided, the default interval will be used.
17
+ */
12
18
  schedule(entityProxy: IEntityProxy, intervalMs?: number): void;
19
+ /**
20
+ * Removes an entity from the scheduler.
21
+ *
22
+ * @param entityProxy - The entity to remove from the scheduler.
23
+ */
13
24
  remove(entityProxy: IEntityProxy): void;
25
+ /**
26
+ * Checks if an entity is currently scheduled for updates.
27
+ *
28
+ * @param entityProxy - The entity to check.
29
+ * @returns `true` if the entity is scheduled, `false` otherwise.
30
+ */
14
31
  has(entityProxy: IEntityProxy): boolean;
15
32
  }
16
33
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entities/entity-queue.ts"],"sourcesContent":["import { IEntityModel } from './entity';\nimport { IEntityProxy } from './entity-proxies';\nimport { IEntitySnapshot } from './entity-snapshot';\n\n/**\n * The `EntityUpdateType` specifies whether the current should `update` or `remove` the Entity.\n */\nexport enum EntityUpdateType {\n update = 'update',\n remove = 'remove',\n}\n\n/**\n * The `IEntityUpdate` represents an Entity update that should be applied over an (existing) Entity.\n */\nexport interface IEntityUpdate {\n type: EntityUpdateType;\n entity: IEntityProxy;\n model?: IEntityModel;\n snapshot?: IEntitySnapshot;\n}\n\n/**\n * The `IEntityUpdateQueue` is the main mechanism to queue and retrieve `EntityUpdate` instances.\n *\n * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.\n */\nexport interface IEntityUpdateQueue {\n readonly size: number;\n\n enqueue(change: IEntityUpdate): void;\n dequeue(): IEntityUpdate;\n\n peek(): IEntityUpdate;\n clear(): void;\n}\n"],"mappings":";AAOO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;","names":["EntityUpdateType"]}
1
+ {"version":3,"sources":["../../src/entities/entity-queue.ts"],"sourcesContent":["import { IEntityModel } from './entity';\nimport { IEntityProxy } from './entity-proxies';\nimport { IEntitySnapshot } from './entity-snapshot';\n\n/**\n * The `EntityUpdateType` enum specifies whether the current Entity should be `updated` or `removed`.\n */\nexport enum EntityUpdateType {\n update = 'update',\n remove = 'remove'\n}\n\n/**\n * The `IEntityUpdate` interface represents an Entity update that should be applied over an existing Entity.\n */\nexport interface IEntityUpdate {\n /**\n * The type of the update, which can be either `update` or `remove`.\n */\n type: EntityUpdateType;\n\n /**\n * The proxy of the Entity that needs to be updated.\n */\n entity: IEntityProxy;\n\n /**\n * Optional. The model of the Entity that needs to be updated.\n */\n model?: IEntityModel;\n\n /**\n * Optional. The snapshot of the Entity that needs to be updated.\n */\n snapshot?: IEntitySnapshot;\n}\n\n/**\n * The `IEntityUpdateQueue` interface is the main mechanism to queue and retrieve `EntityUpdate` instances.\n *\n * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.\n */\nexport interface IEntityUpdateQueue {\n /**\n * The number of `EntityUpdate` instances currently in the queue.\n */\n readonly size: number;\n\n /**\n * Adds an `EntityUpdate` instance to the end of the queue.\n * @param change - The `EntityUpdate` instance to be added.\n */\n enqueue(change: IEntityUpdate): void;\n\n /**\n * Removes and returns the `EntityUpdate` instance at the front of the queue.\n * @returns The `EntityUpdate` instance at the front of the queue.\n */\n dequeue(): IEntityUpdate;\n\n /**\n * Returns the `EntityUpdate` instance at the front of the queue without removing it.\n * @returns The `EntityUpdate` instance at the front of the queue.\n */\n peek(): IEntityUpdate;\n\n /**\n * Removes all `EntityUpdate` instances from the queue.\n */\n clear(): void;\n}\n"],"mappings":";AAOO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,YAAS;AACT,EAAAA,kBAAA,YAAS;AAFC,SAAAA;AAAA,GAAA;","names":["EntityUpdateType"]}
@@ -0,0 +1,253 @@
1
+ import { I as IEntityProxy, f as IdentityComponent, b as IEntityModel, g as IComponent, c as IEntity, E as EntityTypeUid } from './index-B1KXekZD.js';
2
+
3
+ /**
4
+ * Represents a unique identifier for an entity event.
5
+ * Can be either a string or a number.
6
+ */
7
+ type EntityEventUid = string | number;
8
+ /**
9
+ * A filter function for entity event subscriptions.
10
+ * Returns true if the event should be processed, false otherwise.
11
+ */
12
+ type EntityEventSubscriptionFilter = (event: IEntityEvent<IEventData>) => boolean;
13
+ /**
14
+ * The `IEventData` interface represents the data associated with an entity event.
15
+ * It contains at least the `Event Unique Identifier`.
16
+ */
17
+ interface IEventData {
18
+ uid: EntityEventUid;
19
+ }
20
+ /**
21
+ * The `IEntityEvent` interface represents a basic building block for a Publish/Subscribe pattern.
22
+ * It is used to synchronize state between multiple entities.
23
+ *
24
+ * The events are scheduled as part of the `EntityUpdate` model.
25
+ * Systems subscribe and receive updates with the events included in their `SystemContext`.
26
+ */
27
+ interface IEntityEvent<TEventData extends IEventData> {
28
+ origin: IEntityProxy;
29
+ target?: IEntityProxy;
30
+ data: TEventData;
31
+ }
32
+ /**
33
+ * The `IEntityEventsManager` interface represents a Publish/Subscribe broker for `IEntityEvent` instances.
34
+ * It keeps track of entity subscriptions (as part of the Observer design pattern).
35
+ */
36
+ interface IEntityEventsManager {
37
+ /**
38
+ * Subscribes an entity to a specific event.
39
+ * @param uid - The unique identifier of the event.
40
+ * @param entity - The entity subscribing to the event.
41
+ * @param filter - An optional filter function to determine if the event should be processed.
42
+ */
43
+ subscribe(uid: EntityEventUid, entity: IEntityProxy, filter?: EntityEventSubscriptionFilter): void;
44
+ /**
45
+ * Unsubscribes an entity from a specific event.
46
+ * @param uid - The unique identifier of the event.
47
+ * @param entity - The entity unsubscribing from the event.
48
+ */
49
+ unsubscribe(uid: EntityEventUid, entity: IEntityProxy): void;
50
+ /**
51
+ * Retrieves the entities subscribed to a specific event.
52
+ * @param event - The event to retrieve subscriptions for.
53
+ * @returns An array of entities subscribed to the event.
54
+ */
55
+ getSubscriptions(event: IEntityEvent<IEventData>): IEntityProxy[];
56
+ /**
57
+ * Retrieves the unique identifiers of events subscribed to by a specific entity.
58
+ * @param entity - The entity to retrieve subscriptions for.
59
+ * @returns An array of unique identifiers of events subscribed to by the entity.
60
+ */
61
+ getSubscriptionsForEntity(entity: IEntityProxy): EntityEventUid[];
62
+ /**
63
+ * Removes all subscriptions for all entities.
64
+ */
65
+ clearSubscriptions(): void;
66
+ /**
67
+ * Removes all subscriptions for a specific event.
68
+ * @param uid - The unique identifier of the event to remove subscriptions from.
69
+ */
70
+ clearSubscriptionsForEvent(uid: EntityEventUid): void;
71
+ /**
72
+ * Removes all subscriptions for a specific entity.
73
+ * @param entity - The entity to remove subscriptions from.
74
+ */
75
+ clearSubscriptionsForEntity(entity: IEntityProxy): void;
76
+ }
77
+ /**
78
+ * The `IEntityEventsDispatcher` interface represents the main access point for dispatching events to entities.
79
+ * It can leverage the `IEntityEventsManager` to find subscribers and the `IEntityUpdateQueue` to register events
80
+ * into each observer entity's next update.
81
+ */
82
+ interface IEntityEventsDispatcher {
83
+ /**
84
+ * Dispatches a single event to entities.
85
+ * @param event - The event to dispatch.
86
+ * @param targets - The entities to dispatch the event to.
87
+ */
88
+ dispatchEvent(event: IEntityEvent<IEventData>, ...targets: IEntityProxy[]): void;
89
+ /**
90
+ * Dispatches multiple events to entities.
91
+ * @param events - The events to dispatch.
92
+ * @param targets - The entities to dispatch the events to.
93
+ */
94
+ dispatchEvents(events: IEntityEvent<IEventData>[], ...targets: IEntityProxy[]): void;
95
+ }
96
+
97
+ /**
98
+ * The `IEntitySnapshot` interface represents a serializable state of an Entity.
99
+ * It can contain the full or partial state of the Entity, including its identity, components, proxies, and events.
100
+ * This interface is used to capture Entity state changes (deltas) or update existing Entity with changes from a remote source.
101
+ */
102
+ interface IEntitySnapshot {
103
+ /**
104
+ * The identity of the Entity.
105
+ */
106
+ readonly identity?: Readonly<IdentityComponent<IEntityModel>>;
107
+ /**
108
+ * An array of components associated with the Entity.
109
+ */
110
+ readonly components?: IComponent[];
111
+ /**
112
+ * An array of proxies associated with the Entity.
113
+ */
114
+ readonly proxies?: IEntityProxy[];
115
+ /**
116
+ * An array of events associated with the Entity.
117
+ */
118
+ readonly events?: IEntityEvent<IEventData>[];
119
+ }
120
+ /**
121
+ * The `IEntitySnapshotProvider` interface is the main provider for creating and updating Entity snapshots.
122
+ * It provides methods to apply a snapshot to an Entity and to create a snapshot from an Entity.
123
+ */
124
+ interface IEntitySnapshotProvider {
125
+ /**
126
+ * Applies a snapshot to an Entity.
127
+ * This method updates the Entity's state based on the provided snapshot.
128
+ *
129
+ * @param entity - The Entity to apply the snapshot to.
130
+ * @param snapshot - The snapshot to apply to the Entity.
131
+ */
132
+ applySnapshot(entity: IEntity, snapshot: IEntitySnapshot): void;
133
+ /**
134
+ * Creates a snapshot from an Entity.
135
+ * This method captures the current state of the Entity and returns it as a snapshot.
136
+ *
137
+ * @param entity - The Entity to create a snapshot from.
138
+ * @returns The created snapshot.
139
+ */
140
+ createSnapshot(entity: IEntity): IEntitySnapshot;
141
+ }
142
+
143
+ /**
144
+ * The `EntityUpdateType` enum specifies whether the current Entity should be `updated` or `removed`.
145
+ */
146
+ declare enum EntityUpdateType {
147
+ update = "update",
148
+ remove = "remove"
149
+ }
150
+ /**
151
+ * The `IEntityUpdate` interface represents an Entity update that should be applied over an existing Entity.
152
+ */
153
+ interface IEntityUpdate {
154
+ /**
155
+ * The type of the update, which can be either `update` or `remove`.
156
+ */
157
+ type: EntityUpdateType;
158
+ /**
159
+ * The proxy of the Entity that needs to be updated.
160
+ */
161
+ entity: IEntityProxy;
162
+ /**
163
+ * Optional. The model of the Entity that needs to be updated.
164
+ */
165
+ model?: IEntityModel;
166
+ /**
167
+ * Optional. The snapshot of the Entity that needs to be updated.
168
+ */
169
+ snapshot?: IEntitySnapshot;
170
+ }
171
+ /**
172
+ * The `IEntityUpdateQueue` interface is the main mechanism to queue and retrieve `EntityUpdate` instances.
173
+ *
174
+ * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.
175
+ */
176
+ interface IEntityUpdateQueue {
177
+ /**
178
+ * The number of `EntityUpdate` instances currently in the queue.
179
+ */
180
+ readonly size: number;
181
+ /**
182
+ * Adds an `EntityUpdate` instance to the end of the queue.
183
+ * @param change - The `EntityUpdate` instance to be added.
184
+ */
185
+ enqueue(change: IEntityUpdate): void;
186
+ /**
187
+ * Removes and returns the `EntityUpdate` instance at the front of the queue.
188
+ * @returns The `EntityUpdate` instance at the front of the queue.
189
+ */
190
+ dequeue(): IEntityUpdate;
191
+ /**
192
+ * Returns the `EntityUpdate` instance at the front of the queue without removing it.
193
+ * @returns The `EntityUpdate` instance at the front of the queue.
194
+ */
195
+ peek(): IEntityUpdate;
196
+ /**
197
+ * Removes all `EntityUpdate` instances from the queue.
198
+ */
199
+ clear(): void;
200
+ }
201
+
202
+ /**
203
+ * The `IEntityRepository` is the central storage for keeping track of existing Entities.
204
+ * It provides basic CRUD functionality.
205
+ */
206
+ interface IEntityRepository {
207
+ /**
208
+ * Returns the number of entities in the repository.
209
+ */
210
+ readonly size: number;
211
+ /**
212
+ * Checks if the repository contains an entity represented by the given proxy.
213
+ * @param proxy - The proxy of the entity to check.
214
+ * @returns True if the repository contains the entity, false otherwise.
215
+ */
216
+ has(proxy: IEntityProxy): boolean;
217
+ /**
218
+ * Retrieves an entity from the repository by its proxy.
219
+ * @template TEntity - The type of the entity to retrieve.
220
+ * @param proxy - The proxy of the entity to retrieve.
221
+ * @returns The retrieved entity.
222
+ */
223
+ get<TEntity extends IEntity>(proxy: IEntityProxy): TEntity;
224
+ /**
225
+ * Retrieves all entities of a specific type from the repository.
226
+ * @template TEntity - The type of the entities to retrieve.
227
+ * @param entityType - The type UID of the entities to retrieve.
228
+ * @returns An array of the retrieved entities.
229
+ */
230
+ getAll<TEntity extends IEntity>(entityType: EntityTypeUid): TEntity[];
231
+ /**
232
+ * Iterator over all entities in the repository.
233
+ * @returns An iterator of all entities in the repository.
234
+ */
235
+ listAll(): IterableIterator<IEntity>;
236
+ /**
237
+ * Adds or updates an entity in the repository.
238
+ * @param entity - The entity to add or update.
239
+ */
240
+ set(entity: IEntity): void;
241
+ /**
242
+ * Deletes an entity from the repository by its proxy.
243
+ * @param proxy - The proxy of the entity to delete.
244
+ */
245
+ delete(proxy: IEntityProxy): void;
246
+ /**
247
+ * Clears all entities of a specific type from the repository.
248
+ * @param entityType - The type UID of the entities to clear.
249
+ */
250
+ clear(entityType: EntityTypeUid): void;
251
+ }
252
+
253
+ export { type EntityEventUid as E, type IEventData as I, type EntityEventSubscriptionFilter as a, type IEntityEvent as b, type IEntityEventsManager as c, type IEntityEventsDispatcher as d, EntityUpdateType as e, type IEntityUpdate as f, type IEntityUpdateQueue as g, type IEntityRepository as h, type IEntitySnapshot as i, type IEntitySnapshotProvider as j };