@awesome-ecs/abstract 0.4.1 → 0.5.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/dist/components/component.d.ts +14 -2
- package/dist/components/identity-component.d.ts +18 -5
- package/dist/entities/entity-repository.d.ts +9 -1
- package/dist/entities/entity.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/pipelines/middleware.d.ts +2 -2
- package/dist/pipelines/pipeline.d.ts +1 -1
- package/dist/systems/system-middleware.d.ts +4 -0
- package/dist/systems/system-pipeline-context.d.ts +1 -0
- package/dist/systems/system-pipeline-type.d.ts +1 -2
- package/dist/systems/system-pipeline-type.js +0 -1
- package/dist/systems/system-pipeline-type.js.map +1 -1
- package/dist/systems/systems-module.d.ts +21 -0
- package/dist/systems/{system-runtime.js → systems-module.js} +1 -1
- package/dist/systems/systems-module.js.map +1 -0
- package/dist/systems/systems-runtime.d.ts +21 -0
- package/dist/systems/{system-pipeline.js → systems-runtime.js} +1 -1
- package/dist/systems/systems-runtime.js.map +1 -0
- package/package.json +2 -2
- package/dist/systems/system-pipeline.d.ts +0 -4
- package/dist/systems/system-pipeline.js.map +0 -1
- package/dist/systems/system-runtime.d.ts +0 -3
- package/dist/systems/system-runtime.js.map +0 -1
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export declare type
|
|
1
|
+
export declare type ComponentTypeUid = string | number;
|
|
2
|
+
/**
|
|
3
|
+
* The Component provides the main storage mechanism of Entity state, and can be accessed and modified by Systems.
|
|
4
|
+
*/
|
|
2
5
|
export interface IComponent {
|
|
3
|
-
|
|
6
|
+
/**
|
|
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.
|
|
11
|
+
*/
|
|
12
|
+
readonly componentType: ComponentTypeUid;
|
|
13
|
+
/**
|
|
14
|
+
* The serialization mechanism of this Component, when used to transfer it into a Snapshot, or used for logging the Component stored state.
|
|
15
|
+
*/
|
|
4
16
|
toJSON?(): string | object;
|
|
5
17
|
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { IComponent } from "./component";
|
|
2
2
|
import { EntityTypeUid, IEntityModel } from "../entities/entity";
|
|
3
|
-
import { IEntityProxy } from "
|
|
3
|
+
import { IEntityProxy } from "../entities/entity-proxy";
|
|
4
4
|
export declare enum BasicComponentType {
|
|
5
5
|
identity = "identity"
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Each Entity will have an Identity, containing basic information regarding what makes the current Entity unique.
|
|
9
|
+
*/
|
|
7
10
|
export interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The Entity Type that defines what Category type the Entity is part of. There can be multiple Entities sharing the same EntityType.
|
|
13
|
+
*/
|
|
14
|
+
readonly entityType: EntityTypeUid;
|
|
15
|
+
/**
|
|
16
|
+
* The Model is the basic information needed to create an Entity when it's first initialized.
|
|
17
|
+
* It provides a first snapshot of information needed for the successful creation of an Entity instance.
|
|
18
|
+
*/
|
|
19
|
+
readonly model: TModel;
|
|
20
|
+
/**
|
|
21
|
+
* The Entity proxies that this Entity will always be linked to.
|
|
22
|
+
* Proxies can be registered at runtime to the Entity, but these proxies will always be registered when the Entity is first initialized (thus, they are guaranteed to exist in the beginning of the Entity lifetime).
|
|
23
|
+
*/
|
|
24
|
+
readonly proxies?: IEntityProxy[];
|
|
12
25
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { EntityUid, EntityTypeUid, IEntity } from "./entity";
|
|
2
|
+
/**
|
|
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
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* The Entity Repository is the main storage for keeping track of existing Entities.
|
|
4
11
|
* It provides basic CRUD functionality.
|
|
@@ -6,7 +13,8 @@ import { EntityUid, EntityTypeUid, IEntity } from "./entity";
|
|
|
6
13
|
export interface IEntityRepository {
|
|
7
14
|
has(type: EntityTypeUid, uid: EntityUid): boolean;
|
|
8
15
|
get<TEntity extends IEntity>(type: EntityTypeUid, uid: EntityUid): TEntity;
|
|
9
|
-
|
|
16
|
+
getWithTime<TEntity extends IEntity>(type: EntityTypeUid, uid: EntityUid): StoredEntity<TEntity>;
|
|
17
|
+
getAll<TEntity extends IEntity>(type: EntityTypeUid): TEntity[];
|
|
10
18
|
set(entity: IEntity): void;
|
|
11
19
|
delete(entity: IEntity): void;
|
|
12
20
|
clear(entityType: EntityTypeUid): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IdentityComponent } from "../components/identity-component";
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentTypeUid, IComponent } from "../components/component";
|
|
3
3
|
import { IEntityProxy } from "./entity-proxy";
|
|
4
4
|
export declare type EntityTypeUid = string | number;
|
|
5
5
|
export declare type EntityUid = string | number;
|
|
@@ -10,7 +10,7 @@ export interface IEntityModel {
|
|
|
10
10
|
* An Entity is a container of Components and Entity Proxies. Only Systems can manipulate the internal state of the Entity.
|
|
11
11
|
*/
|
|
12
12
|
export interface IEntity {
|
|
13
|
-
readonly components: Map<
|
|
13
|
+
readonly components: Map<ComponentTypeUid, IComponent>;
|
|
14
14
|
readonly proxies: Map<EntityTypeUid, Map<EntityUid, IEntityProxy>>;
|
|
15
15
|
readonly identity: IdentityComponent<IEntityModel>;
|
|
16
16
|
readonly myProxy: IEntityProxy;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export * from './entities/entity-scheduler';
|
|
|
9
9
|
export * from './pipelines/middleware';
|
|
10
10
|
export * from './pipelines/pipeline';
|
|
11
11
|
export * from './systems/system-middleware';
|
|
12
|
-
export * from './systems/
|
|
12
|
+
export * from './systems/systems-module';
|
|
13
13
|
export * from './systems/system-pipeline-context';
|
|
14
14
|
export * from './systems/system-pipeline-type';
|
|
15
|
-
export * from './systems/
|
|
15
|
+
export * from './systems/systems-runtime';
|
|
16
16
|
export * from './utils/performance-timer';
|
package/dist/index.js
CHANGED
|
@@ -25,9 +25,9 @@ __exportStar(require("./entities/entity-scheduler"), exports);
|
|
|
25
25
|
__exportStar(require("./pipelines/middleware"), exports);
|
|
26
26
|
__exportStar(require("./pipelines/pipeline"), exports);
|
|
27
27
|
__exportStar(require("./systems/system-middleware"), exports);
|
|
28
|
-
__exportStar(require("./systems/
|
|
28
|
+
__exportStar(require("./systems/systems-module"), exports);
|
|
29
29
|
__exportStar(require("./systems/system-pipeline-context"), exports);
|
|
30
30
|
__exportStar(require("./systems/system-pipeline-type"), exports);
|
|
31
|
-
__exportStar(require("./systems/
|
|
31
|
+
__exportStar(require("./systems/systems-runtime"), exports);
|
|
32
32
|
__exportStar(require("./utils/performance-timer"), exports);
|
|
33
33
|
//# 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,0DAAuC;AACvC,0DAAuC;AACvC,0DAAuC;AACvC,+DAA4C;AAC5C,8DAA2C;AAE3C,yDAAsC;AACtC,uDAAoC;AAEpC,8DAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC;AACtC,kEAA+C;AAE/C,oDAAiC;AACjC,0DAAuC;AACvC,0DAAuC;AACvC,0DAAuC;AACvC,+DAA4C;AAC5C,8DAA2C;AAE3C,yDAAsC;AACtC,uDAAoC;AAEpC,8DAA2C;AAC3C,2DAAwC;AACxC,oEAAiD;AACjD,iEAA8C;AAC9C,4DAAyC;AAEzC,4DAAyC"}
|
|
@@ -11,7 +11,7 @@ export interface IMiddleware<TContext> {
|
|
|
11
11
|
* being met so this middleware's action should run.
|
|
12
12
|
* @param context The Context to determine whether the run condition is satisfied.
|
|
13
13
|
*/
|
|
14
|
-
shouldRun?(context: TContext): boolean;
|
|
14
|
+
shouldRun?(context: TContext): Promise<boolean> | boolean;
|
|
15
15
|
/**
|
|
16
16
|
* The function gets called as part of the pipeline, based on the registration order.
|
|
17
17
|
* @param context The Context can be read or updated. The Context holds all the state necessary for the execution of the middleware.
|
|
@@ -19,7 +19,7 @@ export interface IMiddleware<TContext> {
|
|
|
19
19
|
*/
|
|
20
20
|
action(context: TContext, stop: Stop): Promise<void> | void;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* This (optional) function gets called when the cleanup of the Pipeline is necessary, based on reverse order of Middleware registration.
|
|
23
23
|
* @param context Part of the Context should be cleaned, and any allocated resources in the Action, should be disposed.
|
|
24
24
|
*/
|
|
25
25
|
cleanup?(context: TContext): Promise<void> | void;
|
|
@@ -10,7 +10,7 @@ export interface IPipeline<TContext> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Execute the chain of middlewares, in the order they were added on a given Context.
|
|
12
12
|
*/
|
|
13
|
-
dispatch(context: TContext):
|
|
13
|
+
dispatch(context: TContext): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Runs the Cleanup function on all middlewares.
|
|
16
16
|
*/
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { IEntity } from "../entities/entity";
|
|
2
2
|
import { IMiddleware } from "../pipelines/middleware";
|
|
3
3
|
import { ISystemPipelineContext } from "./system-pipeline-context";
|
|
4
|
+
/**
|
|
5
|
+
* The SystemMiddleware is the basic System implementation that can be registered as a Middleware in a SystemPipeline.
|
|
6
|
+
* It provides a SystemPipelineContext to it's exposed methods.
|
|
7
|
+
*/
|
|
4
8
|
export declare type ISystemMiddleware<TEntity extends IEntity> = IMiddleware<ISystemPipelineContext<TEntity>>;
|
|
@@ -7,6 +7,5 @@ var SystemPipelineType;
|
|
|
7
7
|
SystemPipelineType["update"] = "update";
|
|
8
8
|
SystemPipelineType["render"] = "render";
|
|
9
9
|
SystemPipelineType["sync"] = "sync";
|
|
10
|
-
SystemPipelineType["dispatch"] = "dispatch";
|
|
11
10
|
})(SystemPipelineType = exports.SystemPipelineType || (exports.SystemPipelineType = {}));
|
|
12
11
|
//# sourceMappingURL=system-pipeline-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-pipeline-type.js","sourceRoot":"","sources":["../../src/systems/system-pipeline-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"system-pipeline-type.js","sourceRoot":"","sources":["../../src/systems/system-pipeline-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACf,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAK7B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IEntity } from "../entities/entity";
|
|
2
|
+
import { IEntityUpdate } from "../entities/entity-queue";
|
|
3
|
+
import { ISystemMiddleware } from "./system-middleware";
|
|
4
|
+
import { SystemPipelineType } from "./system-pipeline-type";
|
|
5
|
+
/**
|
|
6
|
+
* The SystemModule is the main way of registering and triggering the SystemMiddlewares registered for an Entity.
|
|
7
|
+
* It can handle EntityUpdate objects and decides which SystemPipelines to trigger based on the information in the EntityUpdate.
|
|
8
|
+
*/
|
|
9
|
+
export interface ISystemsModule {
|
|
10
|
+
/**
|
|
11
|
+
* The method allows triggering all registered SystemPipelines, to apply the changes from the provided EntityUpdate to an Entity instance.
|
|
12
|
+
* @param update The EntityUpdate containing the desired changes to be applied on an Entity instance.
|
|
13
|
+
*/
|
|
14
|
+
triggerSystems(update: IEntityUpdate): void | Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* @param type The SystemPipelineType to append the provided SystemMiddlewares to.
|
|
17
|
+
* @param systems The SystemMiddlewares will be registered in the provided SystemPipelineType in the same order as the provided array.
|
|
18
|
+
* The SystemMiddlewares will be appended to existing Pipelines to allow easy extension of existing behaviors.
|
|
19
|
+
*/
|
|
20
|
+
registerSystems(type: SystemPipelineType, systems: ISystemMiddleware<IEntity>[]): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systems-module.js","sourceRoot":"","sources":["../../src/systems/systems-module.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EntityTypeUid } from "../entities/entity";
|
|
2
|
+
import { ISystemsModule } from "./systems-module";
|
|
3
|
+
/**
|
|
4
|
+
* The System Runtime allows running a loop of Ticks.
|
|
5
|
+
*
|
|
6
|
+
* Each RunTick can process one or more Entity Updates, from the EntityQueue.
|
|
7
|
+
* We can have multiple implementations of a SystemRuntime, based on the use-case.
|
|
8
|
+
* A different implementation can be chosen at runtime, based for example on performance.
|
|
9
|
+
*/
|
|
10
|
+
export interface ISystemsRuntime {
|
|
11
|
+
/**
|
|
12
|
+
* Allows registering the SystemsModule that will be triggered for any EntityUpdate for the given EntityType.
|
|
13
|
+
* @param entityType The EntityType this module will be registered for.
|
|
14
|
+
* @param module The Module implementation that will be triggered when executing updates for the given EntityType.
|
|
15
|
+
*/
|
|
16
|
+
registerModule(entityType: EntityTypeUid, module: ISystemsModule): void;
|
|
17
|
+
/**
|
|
18
|
+
* The method allows for an Unit of Work implementation, and returns the remaining quantity of items scheduled to be processed next.
|
|
19
|
+
*/
|
|
20
|
+
runTick(): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systems-runtime.js","sourceRoot":"","sources":["../../src/systems/systems-runtime.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awesome-ecs/abstract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -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": "
|
|
35
|
+
"gitHead": "3e5a3223697d9f3618ff1517dce2b1f39b739d6f"
|
|
36
36
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"system-pipeline.js","sourceRoot":"","sources":["../../src/systems/system-pipeline.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"system-runtime.js","sourceRoot":"","sources":["../../src/systems/system-runtime.ts"],"names":[],"mappings":""}
|