@awesome-ecs/abstract 0.8.0 → 0.9.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 (32) hide show
  1. package/dist/components/component.d.ts +25 -6
  2. package/dist/components/identity-component.d.ts +6 -2
  3. package/dist/entities/entity-events.d.ts +11 -9
  4. package/dist/entities/entity-proxies.d.ts +25 -0
  5. package/dist/entities/{entity-proxy.js → entity-proxies.js} +1 -1
  6. package/dist/entities/entity-proxies.js.map +1 -0
  7. package/dist/entities/entity-queue.d.ts +7 -6
  8. package/dist/entities/entity-queue.js +1 -1
  9. package/dist/entities/entity-repository.d.ts +8 -17
  10. package/dist/entities/entity-scheduler.d.ts +4 -4
  11. package/dist/entities/entity-snapshot.d.ts +24 -0
  12. package/dist/entities/entity-snapshot.js +3 -0
  13. package/dist/entities/entity-snapshot.js.map +1 -0
  14. package/dist/entities/entity.d.ts +16 -2
  15. package/dist/index.d.ts +4 -1
  16. package/dist/index.js +4 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/systems/context/system-context-events.d.ts +1 -1
  19. package/dist/systems/context/system-context-proxies.d.ts +1 -1
  20. package/dist/systems/context/system-context-repository.d.ts +6 -5
  21. package/dist/systems/context/system-context-scheduler.d.ts +1 -1
  22. package/dist/systems/context/system-context-snapshot.d.ts +10 -0
  23. package/dist/systems/context/system-context-snapshot.js +3 -0
  24. package/dist/systems/context/system-context-snapshot.js.map +1 -0
  25. package/dist/systems/system-pipeline-context.d.ts +2 -0
  26. package/dist/systems/systems-runtime.d.ts +4 -10
  27. package/dist/utils/json-serializer.d.ts +7 -0
  28. package/dist/utils/json-serializer.js +4 -0
  29. package/dist/utils/json-serializer.js.map +1 -0
  30. package/package.json +3 -3
  31. package/dist/entities/entity-proxy.d.ts +0 -14
  32. package/dist/entities/entity-proxy.js.map +0 -1
@@ -1,17 +1,36 @@
1
1
  export declare type ComponentTypeUid = string | number;
2
2
  /**
3
- * The Component provides the main storage mechanism of Entity state, and can be accessed and modified by Systems.
3
+ * The `IComponent` provides the main storage mechanism of `IEntity` state, and can be accessed and modified by Systems.
4
+ *
5
+ * The `IComponent` implementations should not contain any logic methods, apart from quick-access functionality.
4
6
  */
5
7
  export interface IComponent {
6
8
  /**
7
- * The ComponentType is an Unique identifier for each Component type.
8
- *
9
- * It's possible to have multiple instances of the same Component type across different Entities,
10
- * but only one Component type can exist on one Entity.
9
+ * The `ComponentTypeUid` is an Unique Identifier for each Component type.
11
10
  */
12
11
  readonly componentType: ComponentTypeUid;
13
12
  /**
14
- * The serialization mechanism of this Component, when used to transfer it into a Snapshot, or used for logging the Component stored state.
13
+ * Specifies whether the Component state should be serialized as part of an `IEntitySnapshot`.
14
+ * Useful if the state needs to be replicated or updated through remote updates (e.g. coming from the server or peers).
15
+ */
16
+ readonly isSerializable: boolean;
17
+ /**
18
+ * @optional
19
+ * Specifies the current version of the component.
20
+ * Useful for keeping backwards-compatibility when the stored state might be of a different version.
21
+ */
22
+ readonly version?: number;
23
+ /**
24
+ * @optional
25
+ * The custom serialization function of this Component, used to transfer it into a Snapshot, or used for logging the Component stored state.
26
+ * If not provided, the standard `JSON.stringify()` functionality applies.
15
27
  */
16
28
  toJSON?(): string | object;
29
+ /**
30
+ * Allows for custom logic when loading the current from an `IEntitySnapshot`.
31
+ *
32
+ * The default behavior simply overwrites the fields with the target state.
33
+ * @param component The target component state to apply.
34
+ */
35
+ load?(targetState: this): void;
17
36
  }
@@ -4,7 +4,7 @@ export declare enum BasicComponentType {
4
4
  identity = "identity"
5
5
  }
6
6
  /**
7
- * Each Entity will have an Identity, containing basic information regarding what makes the current Entity unique.
7
+ * The `IdentityComponent` contains basic information regarding what makes the current Entity unique.
8
8
  */
9
9
  export interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
10
10
  /**
@@ -12,8 +12,12 @@ export interface IdentityComponent<TModel extends IEntityModel> extends ICompone
12
12
  */
13
13
  readonly entityType: EntityTypeUid;
14
14
  /**
15
- * The Model is the basic information needed to create an Entity when it's first initialized.
15
+ * The Model is the basic information needed to create an `IEntity` when it's first initialized.
16
16
  * It provides a first snapshot of information needed for the successful creation of an Entity instance.
17
17
  */
18
18
  readonly model: TModel;
19
+ /**
20
+ * Keeps track when the Entity's systems have ran last. Useful to calculate the `DeltaTime` between runs.
21
+ */
22
+ readonly lastUpdated: Date;
19
23
  }
@@ -1,15 +1,16 @@
1
- import { IEntityProxy } from "./entity-proxy";
1
+ import { IEntityProxy } from "./entity-proxies";
2
2
  export declare type EntityEventUid = string | number;
3
3
  export declare type EntityEventSubscriptionFilter = (event: IEntityEvent<IEventData>) => boolean;
4
+ /**
5
+ * The `IEventData` contains the event-specific state. At the very least, it contains the `Event Unique Identifier`.
6
+ */
4
7
  export interface IEventData {
5
8
  uid: EntityEventUid;
6
9
  }
7
10
  /**
8
- * Entity Events represent the basic building blocks for a Pub/Sub pattern, to synchronize
9
- * state between multiple Entities.
11
+ * The `IEntityEvent` represents the basic building block for a Pub/Sub pattern, to synchronize state between multiple Entities.
10
12
  *
11
- * The Events are past actions that already happened within a state. They are scheduled as part of the EntityUpdate model.
12
- * Other Systems subscribe and receive updates with the Events included in their SystemContext model.
13
+ * The Events are scheduled as part of the `EntityUpdate` model. Systems subscribe and receive updates with the Events included in their `SystemContext`.
13
14
  */
14
15
  export interface IEntityEvent<TEventData extends IEventData> {
15
16
  origin: IEntityProxy;
@@ -17,7 +18,8 @@ export interface IEntityEvent<TEventData extends IEventData> {
17
18
  data: TEventData;
18
19
  }
19
20
  /**
20
- * The EntityEventsManager represents the Pub/Sub broker for EntityEvents.
21
+ * The `IEntityEventsManager` represents the Pub/Sub broker for `IEntityEvent` instances.
22
+ * It keeps track of Entity Subscriptions (as part of the Observer design-pattern).
21
23
  */
22
24
  export interface IEntityEventsManager {
23
25
  subscribe(uid: EntityEventUid, entity: IEntityProxy, filter?: EntityEventSubscriptionFilter): void;
@@ -26,10 +28,10 @@ export interface IEntityEventsManager {
26
28
  clearSubscriptions(uid?: EntityEventUid): void;
27
29
  }
28
30
  /**
29
- * The EntityEventsDispatcher is the main access point for dispatching events to Entities.
31
+ * The `IEntityEventsDispatcher` is the main access point for dispatching events to Entities.
30
32
  *
31
- * It can leverage the IEntityEvents manager to find Subscribers, and the IEntityUpdateQueue to register events
32
- * into the Entity's next update.
33
+ * It can leverage the `IEntityEventsManager` to find Subscribers, and the `IEntityUpdateQueue` to register events
34
+ * into each Observer Entity's next update.
33
35
  */
34
36
  export interface IEntityEventsDispatcher {
35
37
  dispatchEvent(event: IEntityEvent<IEventData>, ...targets: IEntityProxy[]): void;
@@ -0,0 +1,25 @@
1
+ import { EntityTypeUid, EntityUid, IEntity } from "./entity";
2
+ /**
3
+ * The `IEntityProxy` represents a pointer to another `Entity`.
4
+ */
5
+ export interface IEntityProxy {
6
+ readonly entityType: EntityTypeUid;
7
+ readonly entityUid: EntityUid;
8
+ }
9
+ /**
10
+ * A utility extension of `IEntityProxy`.
11
+ * Useful for providing strong `Type` information when using the IEntityProxy.
12
+ */
13
+ export interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {
14
+ }
15
+ /**
16
+ * The `IEntityProxiesManager` is a helper to encapsulate logic for registering & removing Entity proxies.
17
+ *
18
+ * It handles the complexities of bi-directional registrations and offers an abstraction for the Proxy handling.
19
+ */
20
+ export interface IEntityProxiesManager {
21
+ registerProxy(entity: IEntity, proxy: IEntityProxy, cleanup?: boolean): void;
22
+ registerProxies(entity: IEntity, proxies: IEntityProxy[], cleanup?: boolean): void;
23
+ removeProxy(entity: IEntity, proxy: IEntityProxy): void;
24
+ removeProxies(entity: IEntity, proxyEntityType?: EntityTypeUid): void;
25
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=entity-proxy.js.map
3
+ //# sourceMappingURL=entity-proxies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-proxies.js","sourceRoot":"","sources":["../../src/entities/entity-proxies.ts"],"names":[],"mappings":""}
@@ -1,24 +1,25 @@
1
1
  import { IEntityModel } from "./entity";
2
- import { IEntityEvent, IEventData } from "./entity-events";
3
- import { IEntityProxy } from "./entity-proxy";
2
+ import { IEntityProxy } from "./entity-proxies";
3
+ import { IEntitySnapshot } from "./entity-snapshot";
4
4
  /**
5
- * The Entity update state for this change.
5
+ * The `EntityUpdateType` specifies whether the current should `update` or `remove` the Entity.
6
6
  */
7
7
  export declare enum EntityUpdateType {
8
8
  update = "update",
9
9
  remove = "remove"
10
10
  }
11
11
  /**
12
- * Represents an Entity update that should be applied over an (existing) Entity.
12
+ * The `IEntityUpdate` represents an Entity update that should be applied over an (existing) Entity.
13
13
  */
14
14
  export interface IEntityUpdate {
15
15
  type: EntityUpdateType;
16
16
  entity: IEntityProxy;
17
17
  model?: IEntityModel;
18
- events?: IEntityEvent<IEventData>[];
18
+ snapshot?: IEntitySnapshot;
19
19
  }
20
20
  /**
21
- * The Entity Updates will be queued up, and can be picked up in order.
21
+ * The `IEntityUpdateQueue` is the main mechanism to queue and retrieve `EntityUpdate` instances.
22
+ *
22
23
  * The interface can be implemented using a simple queue mechanism, or perhaps, a Priority Queue.
23
24
  */
24
25
  export interface IEntityUpdateQueue {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EntityUpdateType = void 0;
4
4
  /**
5
- * The Entity update state for this change.
5
+ * The `EntityUpdateType` specifies whether the current should `update` or `remove` the Entity.
6
6
  */
7
7
  var EntityUpdateType;
8
8
  (function (EntityUpdateType) {
@@ -1,24 +1,15 @@
1
- import { EntityUid, EntityTypeUid, IEntity } from "./entity";
1
+ import { EntityTypeUid, IEntity } from "./entity";
2
+ import { IEntityProxy } from "./entity-proxies";
2
3
  /**
3
- * The Entity Repository internal structure. Holds the Entity as well as LastUpdate time.
4
- */
5
- export interface StoredEntity<TEntity extends IEntity> {
6
- entity: TEntity;
7
- lastUpdate: Date;
8
- }
9
- /**
10
- * The Entity Repository is the main storage for keeping track of existing Entities.
4
+ * The `IEntityRepository` is the central storage for keeping track of existing Entities.
11
5
  * It provides basic CRUD functionality.
12
6
  */
13
7
  export interface IEntityRepository {
14
- has(type: EntityTypeUid, uid: EntityUid): boolean;
15
- get<TEntity extends IEntity>(type: EntityTypeUid, uid: EntityUid): TEntity;
16
- getWithTime<TEntity extends IEntity>(type: EntityTypeUid, uid: EntityUid): StoredEntity<TEntity>;
17
- getAll<TEntity extends IEntity>(type: EntityTypeUid): TEntity[];
18
- listAll(): StoredEntity<IEntity>[];
8
+ has(proxy: IEntityProxy): boolean;
9
+ get<TEntity extends IEntity>(proxy: IEntityProxy): TEntity;
10
+ getAll<TEntity extends IEntity>(entityType: EntityTypeUid): TEntity[];
11
+ listAll(): IEntity[];
19
12
  set(entity: IEntity): void;
20
- delete(type: EntityTypeUid, uid: EntityUid): void;
13
+ delete(proxy: IEntityProxy): void;
21
14
  clear(entityType: EntityTypeUid): void;
22
- onEntitySetCallback?: (entity: IEntity) => void;
23
- onEntityDeletedCallback?: (entity: IEntity) => void;
24
15
  }
@@ -1,8 +1,8 @@
1
- import { IEntityProxy } from "./entity-proxy";
1
+ import { IEntityProxy } from "./entity-proxies";
2
2
  /**
3
- * The Entity Scheduler is the main way of scheduling Entity Updates on a Time Interval.
4
- * It usually reads the Entities from the Entity Repository,
5
- * and uses the Entity Update Queue to enqueue Entity updates.
3
+ * The `IEntityScheduler` is the main way of queuing `IEntityUpdate` instances on an Interval (based on time or a custom implementation).
4
+ *
5
+ * It usually reads the Entities from the `IEntityRepository`, and uses the `IEntityUpdateQueue` to enqueue Entity updates.
6
6
  */
7
7
  export interface IEntityScheduler {
8
8
  schedule(entityProxy: IEntityProxy, intervalMs?: number): void;
@@ -0,0 +1,24 @@
1
+ import { IdentityComponent } from "../components/identity-component";
2
+ import { IComponent } from "../components/component";
3
+ import { IEntityProxy } from "./entity-proxies";
4
+ import { IEntity, IEntityModel } from "./entity";
5
+ import { IEntityEvent, IEventData } from "./entity-events";
6
+ /**
7
+ * The `IEntitySnapshot` contains the full or partial serializable state of an Entity.
8
+ *
9
+ * It can be used to capture Entity state changes (deltas) or update existing Entity with changes coming from a remote source (e.g. server or other peers).
10
+ */
11
+ export interface IEntitySnapshot {
12
+ readonly identity?: Readonly<IdentityComponent<IEntityModel>>;
13
+ readonly components?: IComponent[];
14
+ readonly proxies?: IEntityProxy[];
15
+ readonly events?: IEntityEvent<IEventData>[];
16
+ }
17
+ /**
18
+ * The `IEntitySnapshotProvider` is the main provider for both creating snapshots for an Entity,
19
+ * as well as updating Entity state based off an `IEntitySnapshot`.
20
+ */
21
+ export interface IEntitySnapshotProvider {
22
+ applySnapshot(entity: IEntity, snapshot: IEntitySnapshot): void;
23
+ createSnapshot(entity: IEntity): IEntitySnapshot;
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=entity-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-snapshot.js","sourceRoot":"","sources":["../../src/entities/entity-snapshot.ts"],"names":[],"mappings":""}
@@ -1,17 +1,31 @@
1
1
  import { IdentityComponent } from "../components/identity-component";
2
2
  import { ComponentTypeUid, IComponent } from "../components/component";
3
- import { IEntityProxy } from "./entity-proxy";
3
+ import { IEntityProxy } from "./entity-proxies";
4
4
  export declare type EntityTypeUid = string | number;
5
5
  export declare type EntityUid = string | number;
6
+ /**
7
+ * The `IEntityModel` represents the basic identity information about the current `IEntity`.
8
+ * It's mandatory for each Entity, and it contains the minimal-required information needed for instantiating the Entity.
9
+ */
6
10
  export interface IEntityModel {
7
11
  readonly uid: EntityUid;
8
12
  }
9
13
  /**
10
- * An Entity is a container of Components and Entity Proxies. Only Systems can manipulate the internal state of the Entity.
14
+ * The `IEntity` is basically a container of Components and Entity Proxies.
15
+ * Only Systems can manipulate the internal state of the Entity, by altering its Components' data.
16
+ *
17
+ * The implementations of `IEntity` can contain quick-access methods for `Components` or `Proxies` but should not contain any logic
18
+ * apart from quick-access functionality.
11
19
  */
12
20
  export interface IEntity {
13
21
  readonly components: ReadonlyMap<ComponentTypeUid, IComponent>;
14
22
  readonly proxies: Map<EntityTypeUid, Map<EntityUid, IEntityProxy>>;
23
+ /**
24
+ * The IdentityComponent represents mandatory state any Entity needs to have.
25
+ */
15
26
  readonly identity: Readonly<IdentityComponent<IEntityModel>>;
27
+ /**
28
+ * Own Proxy reference, points to this Entity. Useful for quick access of Proxy data.
29
+ */
16
30
  readonly myProxy: Readonly<IEntityProxy>;
17
31
  }
package/dist/index.d.ts CHANGED
@@ -2,10 +2,11 @@ export * from './components/component';
2
2
  export * from './components/identity-component';
3
3
  export * from './entities/entity';
4
4
  export * from './entities/entity-events';
5
- export * from './entities/entity-proxy';
5
+ export * from './entities/entity-proxies';
6
6
  export * from './entities/entity-queue';
7
7
  export * from './entities/entity-repository';
8
8
  export * from './entities/entity-scheduler';
9
+ export * from './entities/entity-snapshot';
9
10
  export * from './factories/context-factory';
10
11
  export * from './factories/pipeline-factory';
11
12
  export * from './factories/runtime-factory';
@@ -21,6 +22,7 @@ export * from './systems/context/system-context-events';
21
22
  export * from './systems/context/system-context-proxies';
22
23
  export * from './systems/context/system-context-repository';
23
24
  export * from './systems/context/system-context-scheduler';
25
+ export * from './systems/context/system-context-snapshot';
24
26
  export * from './systems/runtime/systems-runtime-context';
25
27
  export * from './systems/runtime/systems-runtime-middleware';
26
28
  export * from './systems/system-pipeline-middleware';
@@ -28,5 +30,6 @@ export * from './systems/system-pipeline-context';
28
30
  export * from './systems/system-pipeline-type';
29
31
  export * from './systems/systems-module';
30
32
  export * from './systems/systems-runtime';
33
+ export * from './utils/json-serializer';
31
34
  export * from './utils/performance-timer';
32
35
  export * from './utils/types';
package/dist/index.js CHANGED
@@ -18,10 +18,11 @@ __exportStar(require("./components/component"), exports);
18
18
  __exportStar(require("./components/identity-component"), exports);
19
19
  __exportStar(require("./entities/entity"), exports);
20
20
  __exportStar(require("./entities/entity-events"), exports);
21
- __exportStar(require("./entities/entity-proxy"), exports);
21
+ __exportStar(require("./entities/entity-proxies"), exports);
22
22
  __exportStar(require("./entities/entity-queue"), exports);
23
23
  __exportStar(require("./entities/entity-repository"), exports);
24
24
  __exportStar(require("./entities/entity-scheduler"), exports);
25
+ __exportStar(require("./entities/entity-snapshot"), exports);
25
26
  __exportStar(require("./factories/context-factory"), exports);
26
27
  __exportStar(require("./factories/pipeline-factory"), exports);
27
28
  __exportStar(require("./factories/runtime-factory"), exports);
@@ -37,6 +38,7 @@ __exportStar(require("./systems/context/system-context-events"), exports);
37
38
  __exportStar(require("./systems/context/system-context-proxies"), exports);
38
39
  __exportStar(require("./systems/context/system-context-repository"), exports);
39
40
  __exportStar(require("./systems/context/system-context-scheduler"), exports);
41
+ __exportStar(require("./systems/context/system-context-snapshot"), exports);
40
42
  __exportStar(require("./systems/runtime/systems-runtime-context"), exports);
41
43
  __exportStar(require("./systems/runtime/systems-runtime-middleware"), exports);
42
44
  __exportStar(require("./systems/system-pipeline-middleware"), exports);
@@ -44,6 +46,7 @@ __exportStar(require("./systems/system-pipeline-context"), exports);
44
46
  __exportStar(require("./systems/system-pipeline-type"), exports);
45
47
  __exportStar(require("./systems/systems-module"), exports);
46
48
  __exportStar(require("./systems/systems-runtime"), exports);
49
+ __exportStar(require("./utils/json-serializer"), exports);
47
50
  __exportStar(require("./utils/performance-timer"), exports);
48
51
  __exportStar(require("./utils/types"), exports);
49
52
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,kEAA+C;AAE/C,oDAAiC;AACjC,2DAAwC;AACxC,0DAAuC;AACvC,0DAAuC;AACvC,+DAA4C;AAC5C,8DAA2C;AAE3C,8DAA2C;AAC3C,+DAA4C;AAC5C,8DAA2C;AAE3C,6DAA0C;AAC1C,2DAAwC;AACxC,2DAAwC;AAExC,yDAAsC;AACtC,gEAA6C;AAC7C,8DAA2C;AAC3C,uDAAoC;AACpC,4DAAyC;AAEzC,0EAAuD;AACvD,2EAAwD;AACxD,8EAA2D;AAC3D,6EAA0D;AAE1D,4EAAyD;AACzD,+EAA4D;AAE5D,uEAAoD;AACpD,oEAAiD;AACjD,iEAA8C;AAC9C,2DAAwC;AACxC,4DAAyC;AAEzC,4DAAyC;AACzC,gDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,kEAA+C;AAE/C,oDAAiC;AACjC,2DAAwC;AACxC,4DAAyC;AACzC,0DAAuC;AACvC,+DAA4C;AAC5C,8DAA2C;AAC3C,6DAA0C;AAE1C,8DAA2C;AAC3C,+DAA4C;AAC5C,8DAA2C;AAE3C,6DAA0C;AAC1C,2DAAwC;AACxC,2DAAwC;AAExC,yDAAsC;AACtC,gEAA6C;AAC7C,8DAA2C;AAC3C,uDAAoC;AACpC,4DAAyC;AAEzC,0EAAuD;AACvD,2EAAwD;AACxD,8EAA2D;AAC3D,6EAA0D;AAC1D,4EAAyD;AAEzD,4EAAyD;AACzD,+EAA4D;AAE5D,uEAAoD;AACpD,oEAAiD;AACjD,iEAA8C;AAC9C,2DAAwC;AACxC,4DAAyC;AAEzC,0DAAuC;AACvC,4DAAyC;AACzC,gDAA6B"}
@@ -1,5 +1,5 @@
1
1
  import { EntityEventUid, IEntityEvent, IEventData } from "../../entities/entity-events";
2
- import { IEntityProxy } from "../../entities/entity-proxy";
2
+ import { IEntityProxy } from "../../entities/entity-proxies";
3
3
  /**
4
4
  * The ISystemContextEvents is the access point for Event related APIs.
5
5
  * The access is made in a SystemMiddleware through the provided ISystemPipelineContext.
@@ -1,5 +1,5 @@
1
1
  import { EntityTypeUid } from "../../entities/entity";
2
- import { IEntityProxy } from "../../entities/entity-proxy";
2
+ import { IEntityProxy } from "../../entities/entity-proxies";
3
3
  /**
4
4
  * The ISystemContextProxies is the access point for EntityProxy related APIs.
5
5
  * The access is made in a SystemMiddleware through the provided ISystemPipelineContext.
@@ -1,12 +1,13 @@
1
1
  import { EntityTypeUid, IEntityModel, IEntity } from "../../entities/entity";
2
- import { IEntityEvent, IEventData } from "../../entities/entity-events";
3
- import { EntityProxy, IEntityProxy } from "../../entities/entity-proxy";
2
+ import { EntityProxy, IEntityProxy } from "../../entities/entity-proxies";
3
+ import { IEntitySnapshot } from "../../entities/entity-snapshot";
4
4
  /**
5
- * The ISystemContextRepository is the access point for EntityRepository related APIs.
6
- * The access is made in a SystemMiddleware through the provided ISystemPipelineContext.
5
+ * The `ISystemContextRepository` is the access point for the `IEntityRepository` related APIs.
6
+ *
7
+ * The access is made in an `ISystemMiddleware` through the provided `ISystemPipelineContext`.
7
8
  */
8
9
  export interface ISystemContextRepository {
9
- addEntity(entityType: EntityTypeUid, model: IEntityModel, events?: IEntityEvent<IEventData>[]): void;
10
+ addEntity(entityType: EntityTypeUid, model: IEntityModel, snapshot?: IEntitySnapshot): void;
10
11
  getEntity<TEntity extends IEntity>(proxy: EntityProxy<TEntity>): TEntity;
11
12
  updateEntity(target?: IEntityProxy): void;
12
13
  removeEntity(target: IEntityProxy): void;
@@ -1,4 +1,4 @@
1
- import { IEntityProxy } from "../../entities/entity-proxy";
1
+ import { IEntityProxy } from "../../entities/entity-proxies";
2
2
  /**
3
3
  * The ISystemContextRepository is the access point for Scheduler related APIs.
4
4
  * The access is made in a SystemMiddleware through the provided ISystemPipelineContext.
@@ -0,0 +1,10 @@
1
+ import { IEntitySnapshot } from "../../entities/entity-snapshot";
2
+ /**
3
+ * The ISystemContextSnapshot is the access point for Snapshot related APIs.
4
+ * The access is made in a SystemMiddleware through the provided ISystemPipelineContext.
5
+ */
6
+ export interface ISystemContextSnapshot {
7
+ readonly appliedSnapshot: IEntitySnapshot;
8
+ applySnapshot(snapshot: IEntitySnapshot): void;
9
+ createSnapshot(): IEntitySnapshot;
10
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=system-context-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-context-snapshot.js","sourceRoot":"","sources":["../../../src/systems/context/system-context-snapshot.ts"],"names":[],"mappings":""}
@@ -3,6 +3,7 @@ import { ISystemContextEvents } from "./context/system-context-events";
3
3
  import { ISystemContextProxies } from "./context/system-context-proxies";
4
4
  import { ISystemContextRepository } from "./context/system-context-repository";
5
5
  import { ISystemContextScheduler } from "./context/system-context-scheduler";
6
+ import { ISystemContextSnapshot } from "./context/system-context-snapshot";
6
7
  /**
7
8
  * The ISystemPipelineContext is the Context passed to a SystemMiddleware as part of the Pipeline Dispatch.
8
9
  * It's an abstraction layer so that the Middleware code won't have explicit dependencies on other parts of the ECS.
@@ -16,4 +17,5 @@ export interface ISystemPipelineContext<TEntity extends IEntity> {
16
17
  readonly proxies: Readonly<ISystemContextProxies>;
17
18
  readonly repository: Readonly<ISystemContextRepository>;
18
19
  readonly scheduler: Readonly<ISystemContextScheduler>;
20
+ readonly snapshot: Readonly<ISystemContextSnapshot>;
19
21
  }
@@ -1,6 +1,5 @@
1
- import { EntityTypeUid, IEntity } from "../entities/entity";
1
+ import { IEntityUpdate } from "../entities/entity-queue";
2
2
  import { IRuntimeResult } from "../runtime/runtime-result";
3
- import { ISystemsModule } from "./systems-module";
4
3
  /**
5
4
  * The System Runtime allows running a loop of Ticks.
6
5
  *
@@ -10,13 +9,8 @@ import { ISystemsModule } from "./systems-module";
10
9
  */
11
10
  export interface ISystemsRuntime {
12
11
  /**
13
- * Allows registering the SystemsModule that will be triggered for any EntityUpdate for the given EntityType.
14
- * @param entityType The EntityType this module will be registered for.
15
- * @param module The Module implementation that will be triggered when executing updates for the given EntityType.
12
+ * The method should trigger the SystemsModule logic for the provided IEntityUpdate.
13
+ * If no EntityUpdate is given, the SystemRuntime implementation can choose to dequeue one from the IEntityUpdateQueue.
16
14
  */
17
- registerModule<TEntity extends IEntity>(entityType: EntityTypeUid, module: ISystemsModule<TEntity>): void;
18
- /**
19
- * The method allows for an Unit of Work implementation, and returns the remaining quantity of items scheduled to be processed next.
20
- */
21
- runTick(): IRuntimeResult | Promise<IRuntimeResult>;
15
+ runTick(update?: IEntityUpdate): IRuntimeResult | Promise<IRuntimeResult>;
22
16
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A custom `IJsonSerializer` implementation can provide different ways of serializing objects.
3
+ */
4
+ export interface IJsonSerializer {
5
+ serializeCustom(value: object): string;
6
+ parseCustom<TObject>(text: string): TObject;
7
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=json-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-serializer.js","sourceRoot":"","sources":["../../src/utils/json-serializer.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesome-ecs/abstract",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A comprehensive Entity-Component-System (ECS) Architecture implementation. Abstract components.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "devDependencies": {
11
- "typescript": "^4.7.4"
11
+ "typescript": "^4.8.2"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "rimraf ./dist && npx tsc --build"
@@ -32,5 +32,5 @@
32
32
  "url": "https://github.com/andreicojocaru/awesome-ecs/issues"
33
33
  },
34
34
  "homepage": "https://github.com/andreicojocaru/awesome-ecs#readme",
35
- "gitHead": "866b983e2f2bf56d3d6c5646c38c65429a5a7259"
35
+ "gitHead": "592915c8f5a8c76360ad6459a5bad0e3995bcba9"
36
36
  }
@@ -1,14 +0,0 @@
1
- import { EntityTypeUid, EntityUid, IEntity } from "./entity";
2
- /**
3
- * Represents a pointer to another Entity.
4
- */
5
- export interface IEntityProxy {
6
- readonly entityType: EntityTypeUid;
7
- readonly entityUid: EntityUid;
8
- }
9
- /**
10
- * A utility extension of IEntityProxy.
11
- * Useful for providing Type information when using the IEntityProxy.
12
- */
13
- export interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {
14
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity-proxy.js","sourceRoot":"","sources":["../../src/entities/entity-proxy.ts"],"names":[],"mappings":""}