@awesome-ecs/abstract 0.20.0 → 0.20.2
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/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js.map +1 -1
- package/dist/entities/index.cjs.map +1 -1
- package/dist/entities/index.d.cts +21 -4
- package/dist/entities/index.d.ts +21 -4
- package/dist/entities/index.js.map +1 -1
- package/dist/entity-repository-BlSpo-x2.d.ts +253 -0
- package/dist/entity-repository-DJ1xbvaN.d.cts +253 -0
- package/dist/factories/index.d.cts +40 -10
- package/dist/factories/index.d.ts +40 -10
- package/dist/index-B1KXekZD.d.ts +199 -0
- package/dist/index-CnlpX7ys.d.cts +199 -0
- package/dist/performance-timer-BVyl0SRs.d.cts +45 -0
- package/dist/performance-timer-BVyl0SRs.d.ts +45 -0
- package/dist/pipeline-BGsQiSer.d.ts +161 -0
- package/dist/pipeline-DunwPUPZ.d.cts +161 -0
- package/dist/pipelines/index.cjs.map +1 -1
- package/dist/pipelines/index.d.cts +23 -11
- package/dist/pipelines/index.d.ts +23 -11
- package/dist/pipelines/index.js.map +1 -1
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +58 -19
- package/dist/systems/index.d.ts +58 -19
- package/dist/systems/index.js.map +1 -1
- package/dist/systems-runtime-context-BTNdV8Z-.d.ts +330 -0
- package/dist/systems-runtime-context-DhtHMczN.d.cts +330 -0
- package/dist/types-cZ-1lGPD.d.cts +77 -0
- package/dist/types-cZ-1lGPD.d.ts +77 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +63 -3
- package/dist/utils/index.d.ts +63 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/entity-repository-BASmOrq7.d.ts +0 -120
- package/dist/entity-repository-DmfcUSrX.d.cts +0 -120
- package/dist/index-BPDsRt_F.d.ts +0 -117
- package/dist/index-DK2CXVZ8.d.cts +0 -117
- package/dist/performance-timer-XvdCbcAE.d.cts +0 -13
- package/dist/performance-timer-XvdCbcAE.d.ts +0 -13
- package/dist/pipeline-BowCAITe.d.cts +0 -83
- package/dist/pipeline-D43CXxWG.d.ts +0 -83
- package/dist/systems-runtime-context-B2ch9kB3.d.ts +0 -163
- package/dist/systems-runtime-context-C-PeYs1I.d.cts +0 -163
- package/dist/types-BNwBqRWY.d.cts +0 -22
- package/dist/types-BNwBqRWY.d.ts +0 -22
|
@@ -1,26 +1,56 @@
|
|
|
1
|
-
import { c as IEntity } from '../index-
|
|
2
|
-
import { I as ISystemsRuntimeContext, a as ISystemContext } from '../systems-runtime-context-
|
|
3
|
-
import { I as IPipelineContext, M as MiddlewareResult, a as IPipeline } from '../pipeline-
|
|
4
|
-
import '../types-
|
|
5
|
-
import '../entity-repository-
|
|
1
|
+
import { c as IEntity } from '../index-CnlpX7ys.cjs';
|
|
2
|
+
import { I as ISystemsRuntimeContext, a as ISystemContext } from '../systems-runtime-context-DhtHMczN.cjs';
|
|
3
|
+
import { I as IPipelineContext, M as MiddlewareResult, a as IPipeline } from '../pipeline-DunwPUPZ.cjs';
|
|
4
|
+
import '../types-cZ-1lGPD.cjs';
|
|
5
|
+
import '../entity-repository-DJ1xbvaN.cjs';
|
|
6
6
|
import '../utils/index.cjs';
|
|
7
|
-
import '../performance-timer-
|
|
7
|
+
import '../performance-timer-BVyl0SRs.cjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The IContextFactory
|
|
11
|
-
*
|
|
10
|
+
* The IContextFactory interface is used to create abstraction layers for quickly creating Pipeline Contexts.
|
|
11
|
+
* It helps to avoid manually resolving all dependencies when creating these contexts.
|
|
12
12
|
*/
|
|
13
13
|
interface IContextFactory {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new instance of ISystemsRuntimeContext.
|
|
16
|
+
*
|
|
17
|
+
* @template TEntity - The type of entity to be used in the runtime context. It must extend IEntity.
|
|
18
|
+
* @returns A new instance of ISystemsRuntimeContext with the specified entity type.
|
|
19
|
+
*/
|
|
14
20
|
createRuntimeContext<TEntity extends IEntity>(): ISystemsRuntimeContext<TEntity>;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
|
-
* The PipelineFactory
|
|
19
|
-
*
|
|
24
|
+
* The PipelineFactory interface provides methods to create different types of pipelines.
|
|
25
|
+
* It helps to quickly create IPipeline objects without manually resolving their dependencies.
|
|
20
26
|
*/
|
|
21
27
|
interface IPipelineFactory {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new pipeline with the specified context and result type.
|
|
30
|
+
*
|
|
31
|
+
* @template TContext - The type of the pipeline context. It must extend IPipelineContext.
|
|
32
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
33
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
34
|
+
* @returns A new instance of IPipeline with the specified context and result type.
|
|
35
|
+
*/
|
|
22
36
|
createPipeline<TContext extends IPipelineContext, TResult = MiddlewareResult>(name?: string): IPipeline<TContext, TResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new pipeline specifically for systems with the specified entity type and result type.
|
|
39
|
+
*
|
|
40
|
+
* @template TEntity - The type of the entity. It must extend IEntity.
|
|
41
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
42
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
43
|
+
* @returns A new instance of IPipeline with the specified system context and result type.
|
|
44
|
+
*/
|
|
23
45
|
createSystemsPipeline<TEntity extends IEntity, TResult = MiddlewareResult>(name?: string): IPipeline<ISystemContext<TEntity>, TResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new pipeline specifically for systems runtime with the specified entity type and result type.
|
|
48
|
+
*
|
|
49
|
+
* @template TEntity - The type of the entity. It must extend IEntity.
|
|
50
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
51
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
52
|
+
* @returns A new instance of IPipeline with the specified systems runtime context and result type.
|
|
53
|
+
*/
|
|
24
54
|
createRuntimePipeline<TEntity extends IEntity, TResult = MiddlewareResult>(name?: string): IPipeline<ISystemsRuntimeContext<TEntity>, TResult>;
|
|
25
55
|
}
|
|
26
56
|
|
|
@@ -1,26 +1,56 @@
|
|
|
1
|
-
import { c as IEntity } from '../index-
|
|
2
|
-
import { I as ISystemsRuntimeContext, a as ISystemContext } from '../systems-runtime-context-
|
|
3
|
-
import { I as IPipelineContext, M as MiddlewareResult, a as IPipeline } from '../pipeline-
|
|
4
|
-
import '../types-
|
|
5
|
-
import '../entity-repository-
|
|
1
|
+
import { c as IEntity } from '../index-B1KXekZD.js';
|
|
2
|
+
import { I as ISystemsRuntimeContext, a as ISystemContext } from '../systems-runtime-context-BTNdV8Z-.js';
|
|
3
|
+
import { I as IPipelineContext, M as MiddlewareResult, a as IPipeline } from '../pipeline-BGsQiSer.js';
|
|
4
|
+
import '../types-cZ-1lGPD.js';
|
|
5
|
+
import '../entity-repository-BlSpo-x2.js';
|
|
6
6
|
import '../utils/index.js';
|
|
7
|
-
import '../performance-timer-
|
|
7
|
+
import '../performance-timer-BVyl0SRs.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The IContextFactory
|
|
11
|
-
*
|
|
10
|
+
* The IContextFactory interface is used to create abstraction layers for quickly creating Pipeline Contexts.
|
|
11
|
+
* It helps to avoid manually resolving all dependencies when creating these contexts.
|
|
12
12
|
*/
|
|
13
13
|
interface IContextFactory {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new instance of ISystemsRuntimeContext.
|
|
16
|
+
*
|
|
17
|
+
* @template TEntity - The type of entity to be used in the runtime context. It must extend IEntity.
|
|
18
|
+
* @returns A new instance of ISystemsRuntimeContext with the specified entity type.
|
|
19
|
+
*/
|
|
14
20
|
createRuntimeContext<TEntity extends IEntity>(): ISystemsRuntimeContext<TEntity>;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
|
-
* The PipelineFactory
|
|
19
|
-
*
|
|
24
|
+
* The PipelineFactory interface provides methods to create different types of pipelines.
|
|
25
|
+
* It helps to quickly create IPipeline objects without manually resolving their dependencies.
|
|
20
26
|
*/
|
|
21
27
|
interface IPipelineFactory {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new pipeline with the specified context and result type.
|
|
30
|
+
*
|
|
31
|
+
* @template TContext - The type of the pipeline context. It must extend IPipelineContext.
|
|
32
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
33
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
34
|
+
* @returns A new instance of IPipeline with the specified context and result type.
|
|
35
|
+
*/
|
|
22
36
|
createPipeline<TContext extends IPipelineContext, TResult = MiddlewareResult>(name?: string): IPipeline<TContext, TResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new pipeline specifically for systems with the specified entity type and result type.
|
|
39
|
+
*
|
|
40
|
+
* @template TEntity - The type of the entity. It must extend IEntity.
|
|
41
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
42
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
43
|
+
* @returns A new instance of IPipeline with the specified system context and result type.
|
|
44
|
+
*/
|
|
23
45
|
createSystemsPipeline<TEntity extends IEntity, TResult = MiddlewareResult>(name?: string): IPipeline<ISystemContext<TEntity>, TResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new pipeline specifically for systems runtime with the specified entity type and result type.
|
|
48
|
+
*
|
|
49
|
+
* @template TEntity - The type of the entity. It must extend IEntity.
|
|
50
|
+
* @template TResult - The type of the result returned by the pipeline. Default is MiddlewareResult.
|
|
51
|
+
* @param name - Optional name for the pipeline. If not provided, a default name will be assigned.
|
|
52
|
+
* @returns A new instance of IPipeline with the specified systems runtime context and result type.
|
|
53
|
+
*/
|
|
24
54
|
createRuntimePipeline<TEntity extends IEntity, TResult = MiddlewareResult>(name?: string): IPipeline<ISystemsRuntimeContext<TEntity>, TResult>;
|
|
25
55
|
}
|
|
26
56
|
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { B as BooleanProps, I as Immutable } from './types-cZ-1lGPD.js';
|
|
2
|
+
|
|
3
|
+
type ComponentTypeUid = string | number;
|
|
4
|
+
/**
|
|
5
|
+
* The `IComponent` interface provides the main storage mechanism of `IEntity` state, and can be accessed and modified by `Systems`.
|
|
6
|
+
*
|
|
7
|
+
* The `IComponent` implementations should not contain any logic methods, apart from quick-access functionality.
|
|
8
|
+
*/
|
|
9
|
+
interface IComponent {
|
|
10
|
+
/**
|
|
11
|
+
* The `ComponentTypeUid` is a unique identifier for each Component type.
|
|
12
|
+
* @type {ComponentTypeUid}
|
|
13
|
+
*/
|
|
14
|
+
readonly componentType: ComponentTypeUid;
|
|
15
|
+
/**
|
|
16
|
+
* Specifies whether the Component state should be serialized as part of an `IEntitySnapshot`.
|
|
17
|
+
* This is useful if the state needs to be replicated or updated through remote updates (e.g., coming from the server or peers).
|
|
18
|
+
* @type {boolean}
|
|
19
|
+
*/
|
|
20
|
+
readonly isSerializable: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @optional
|
|
23
|
+
* Specifies the current version of the component.
|
|
24
|
+
* This is useful for keeping backwards-compatibility when the stored state might be of a different version.
|
|
25
|
+
* @type {number}
|
|
26
|
+
*/
|
|
27
|
+
readonly version?: number;
|
|
28
|
+
/**
|
|
29
|
+
* @optional
|
|
30
|
+
* The custom serialization function of this Component, used to transfer it into a Snapshot, or used for logging the Component stored state.
|
|
31
|
+
* If not provided, the standard `JSON.stringify()` functionality applies.
|
|
32
|
+
* @returns {string | object} The serialized form of the Component.
|
|
33
|
+
*/
|
|
34
|
+
toJSON?(): string | object;
|
|
35
|
+
/**
|
|
36
|
+
* Allows for custom logic when loading the current from an `IEntitySnapshot`.
|
|
37
|
+
* The default behavior simply overwrites the fields with the target state.
|
|
38
|
+
* @param {this} targetState The target state to load from.
|
|
39
|
+
*/
|
|
40
|
+
load?(targetState: this): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The `IEntityProxy` represents a pointer to another `Entity`.
|
|
45
|
+
*/
|
|
46
|
+
interface IEntityProxy {
|
|
47
|
+
/**
|
|
48
|
+
* The type of the entity that the proxy points to.
|
|
49
|
+
*/
|
|
50
|
+
readonly entityType: EntityTypeUid;
|
|
51
|
+
/**
|
|
52
|
+
* The unique identifier of the entity that the proxy points to.
|
|
53
|
+
*/
|
|
54
|
+
readonly entityUid: EntityUid;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A utility extension of `IEntityProxy`.
|
|
58
|
+
* Useful for providing strong `Type` information when using the IEntityProxy.
|
|
59
|
+
*
|
|
60
|
+
* @template TEntity - The type of the entity that the proxy points to.
|
|
61
|
+
*/
|
|
62
|
+
interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The `IEntityProxiesManager` is a helper to encapsulate logic for registering & removing Entity proxies.
|
|
66
|
+
*
|
|
67
|
+
* It handles the complexities of bi-directional registrations and offers an abstraction for the Proxy handling.
|
|
68
|
+
*/
|
|
69
|
+
interface IEntityProxiesManager {
|
|
70
|
+
/**
|
|
71
|
+
* Registers a single proxy for an entity.
|
|
72
|
+
*
|
|
73
|
+
* @param entity - The entity to register the proxy for.
|
|
74
|
+
* @param proxy - The proxy to register.
|
|
75
|
+
* @param cleanup - If true, any existing proxies of the same type will be removed before registering the new one.
|
|
76
|
+
*/
|
|
77
|
+
registerProxy(entity: IEntity, proxy: IEntityProxy, cleanup?: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* Registers multiple proxies for an entity.
|
|
80
|
+
*
|
|
81
|
+
* @param entity - The entity to register the proxies for.
|
|
82
|
+
* @param proxies - The proxies to register.
|
|
83
|
+
* @param cleanup - If true, any existing proxies of the same type will be removed before registering the new ones.
|
|
84
|
+
*/
|
|
85
|
+
registerProxies(entity: IEntity, proxies: IEntityProxy[], cleanup?: boolean): void;
|
|
86
|
+
/**
|
|
87
|
+
* Removes a single proxy from an entity.
|
|
88
|
+
*
|
|
89
|
+
* @param entity - The entity to remove the proxy from.
|
|
90
|
+
* @param proxy - The proxy to remove.
|
|
91
|
+
*/
|
|
92
|
+
removeProxy(entity: IEntity, proxy: IEntityProxy): void;
|
|
93
|
+
/**
|
|
94
|
+
* Removes all proxies from an entity, optionally filtering by proxy entity type.
|
|
95
|
+
*
|
|
96
|
+
* @param entity - The entity to remove the proxies from.
|
|
97
|
+
* @param proxyEntityType - The type of the proxy entity to filter by.
|
|
98
|
+
*/
|
|
99
|
+
removeProxies(entity: IEntity, proxyEntityType?: EntityTypeUid): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Represents the unique identifier for an entity type.
|
|
104
|
+
* Can be either a string or a number.
|
|
105
|
+
*/
|
|
106
|
+
type EntityTypeUid = string | number;
|
|
107
|
+
/**
|
|
108
|
+
* Represents the unique identifier for an entity.
|
|
109
|
+
* Can be either a string or a number.
|
|
110
|
+
*/
|
|
111
|
+
type EntityUid = string | number;
|
|
112
|
+
/**
|
|
113
|
+
* The `IEntityModel` represents the basic identity information about the current `IEntity`.
|
|
114
|
+
* It's mandatory for each Entity, and it contains the minimal-required information needed for instantiating the Entity.
|
|
115
|
+
*
|
|
116
|
+
* The Features property can be used to toggle Entity features on and off.
|
|
117
|
+
*
|
|
118
|
+
* @template TFeatures - A type that extends `BooleanProps<TFeatures>` to represent the features of the entity.
|
|
119
|
+
* Defaults to `unknown` if not provided.
|
|
120
|
+
*/
|
|
121
|
+
interface IEntityModel<TFeatures extends BooleanProps<TFeatures> = unknown> {
|
|
122
|
+
/**
|
|
123
|
+
* The unique identifier of the entity.
|
|
124
|
+
*/
|
|
125
|
+
readonly uid: EntityUid;
|
|
126
|
+
/**
|
|
127
|
+
* Optional features of the entity.
|
|
128
|
+
* The type of this property should extend `BooleanProps<TFeatures>`.
|
|
129
|
+
*/
|
|
130
|
+
readonly features?: TFeatures;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The `IEntity` interface represents a container of Components and Entity Proxies.
|
|
134
|
+
* It is designed to be immutable and only modifiable through System operations.
|
|
135
|
+
*
|
|
136
|
+
* Implementations of `IEntity` can contain quick-access methods for `Components` or `Proxies`,
|
|
137
|
+
* but should not contain any state-changing logic apart from quick-access functionality.
|
|
138
|
+
*/
|
|
139
|
+
interface IEntity {
|
|
140
|
+
/**
|
|
141
|
+
* A Map of Components associated with this Entity.
|
|
142
|
+
* The keys are ComponentTypeUid, and the values are IComponent instances.
|
|
143
|
+
*/
|
|
144
|
+
readonly components: Map<ComponentTypeUid, IComponent>;
|
|
145
|
+
/**
|
|
146
|
+
* A Map of Entity Proxies associated with this Entity.
|
|
147
|
+
* The outer Map's keys are EntityTypeUid, and the inner Map's keys are EntityUid.
|
|
148
|
+
* The values are IEntityProxy instances.
|
|
149
|
+
*/
|
|
150
|
+
readonly proxies: Map<EntityTypeUid, Map<EntityUid, IEntityProxy>>;
|
|
151
|
+
/**
|
|
152
|
+
* The IdentityComponent represents mandatory state any Entity needs to have.
|
|
153
|
+
* It is a readonly reference to an IdentityComponent instance, which contains the minimal-required information
|
|
154
|
+
* needed for instantiating the Entity.
|
|
155
|
+
*/
|
|
156
|
+
readonly identity: Readonly<IdentityComponent<IEntityModel>>;
|
|
157
|
+
/**
|
|
158
|
+
* A reference to the own Proxy of this Entity.
|
|
159
|
+
* It is a readonly reference to an IEntityProxy instance, which points to this Entity.
|
|
160
|
+
* This is useful for quick access of Proxy data.
|
|
161
|
+
*/
|
|
162
|
+
readonly myProxy: Readonly<IEntityProxy>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The `BasicComponentType` enum defines the types of basic components available.
|
|
167
|
+
*/
|
|
168
|
+
declare enum BasicComponentType {
|
|
169
|
+
identity = "identity"
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* IdentityComponent interface represents the basic information regarding what makes the current Entity unique.
|
|
173
|
+
* It extends the IComponent interface.
|
|
174
|
+
*
|
|
175
|
+
* @template TModel - The type of the model that extends IEntityModel.
|
|
176
|
+
*/
|
|
177
|
+
interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
|
|
178
|
+
/**
|
|
179
|
+
* The Entity Type that defines what Category type the Entity is part of.
|
|
180
|
+
* There can be multiple Entities sharing the same EntityType.
|
|
181
|
+
*/
|
|
182
|
+
readonly entityType: EntityTypeUid;
|
|
183
|
+
/**
|
|
184
|
+
* The Model is the basic information needed to create an `IEntity` when it's first initialized.
|
|
185
|
+
* It provides a first snapshot of information needed for the successful creation of an Entity instance.
|
|
186
|
+
*
|
|
187
|
+
* @type {Immutable<TModel>}
|
|
188
|
+
*/
|
|
189
|
+
readonly model: Immutable<TModel>;
|
|
190
|
+
/**
|
|
191
|
+
* Keeps track when the Entity's systems have ran last.
|
|
192
|
+
* Useful to calculate the `DeltaTime` between runs.
|
|
193
|
+
*
|
|
194
|
+
* @type {Date | undefined}
|
|
195
|
+
*/
|
|
196
|
+
readonly lastUpdated?: Date;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { BasicComponentType as B, type ComponentTypeUid as C, type EntityTypeUid as E, type IEntityProxy as I, type EntityUid as a, type IEntityModel as b, type IEntity as c, type EntityProxy as d, type IEntityProxiesManager as e, type IdentityComponent as f, type IComponent as g };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { B as BooleanProps, I as Immutable } from './types-cZ-1lGPD.cjs';
|
|
2
|
+
|
|
3
|
+
type ComponentTypeUid = string | number;
|
|
4
|
+
/**
|
|
5
|
+
* The `IComponent` interface provides the main storage mechanism of `IEntity` state, and can be accessed and modified by `Systems`.
|
|
6
|
+
*
|
|
7
|
+
* The `IComponent` implementations should not contain any logic methods, apart from quick-access functionality.
|
|
8
|
+
*/
|
|
9
|
+
interface IComponent {
|
|
10
|
+
/**
|
|
11
|
+
* The `ComponentTypeUid` is a unique identifier for each Component type.
|
|
12
|
+
* @type {ComponentTypeUid}
|
|
13
|
+
*/
|
|
14
|
+
readonly componentType: ComponentTypeUid;
|
|
15
|
+
/**
|
|
16
|
+
* Specifies whether the Component state should be serialized as part of an `IEntitySnapshot`.
|
|
17
|
+
* This is useful if the state needs to be replicated or updated through remote updates (e.g., coming from the server or peers).
|
|
18
|
+
* @type {boolean}
|
|
19
|
+
*/
|
|
20
|
+
readonly isSerializable: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @optional
|
|
23
|
+
* Specifies the current version of the component.
|
|
24
|
+
* This is useful for keeping backwards-compatibility when the stored state might be of a different version.
|
|
25
|
+
* @type {number}
|
|
26
|
+
*/
|
|
27
|
+
readonly version?: number;
|
|
28
|
+
/**
|
|
29
|
+
* @optional
|
|
30
|
+
* The custom serialization function of this Component, used to transfer it into a Snapshot, or used for logging the Component stored state.
|
|
31
|
+
* If not provided, the standard `JSON.stringify()` functionality applies.
|
|
32
|
+
* @returns {string | object} The serialized form of the Component.
|
|
33
|
+
*/
|
|
34
|
+
toJSON?(): string | object;
|
|
35
|
+
/**
|
|
36
|
+
* Allows for custom logic when loading the current from an `IEntitySnapshot`.
|
|
37
|
+
* The default behavior simply overwrites the fields with the target state.
|
|
38
|
+
* @param {this} targetState The target state to load from.
|
|
39
|
+
*/
|
|
40
|
+
load?(targetState: this): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The `IEntityProxy` represents a pointer to another `Entity`.
|
|
45
|
+
*/
|
|
46
|
+
interface IEntityProxy {
|
|
47
|
+
/**
|
|
48
|
+
* The type of the entity that the proxy points to.
|
|
49
|
+
*/
|
|
50
|
+
readonly entityType: EntityTypeUid;
|
|
51
|
+
/**
|
|
52
|
+
* The unique identifier of the entity that the proxy points to.
|
|
53
|
+
*/
|
|
54
|
+
readonly entityUid: EntityUid;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A utility extension of `IEntityProxy`.
|
|
58
|
+
* Useful for providing strong `Type` information when using the IEntityProxy.
|
|
59
|
+
*
|
|
60
|
+
* @template TEntity - The type of the entity that the proxy points to.
|
|
61
|
+
*/
|
|
62
|
+
interface EntityProxy<TEntity extends IEntity> extends IEntityProxy {
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The `IEntityProxiesManager` is a helper to encapsulate logic for registering & removing Entity proxies.
|
|
66
|
+
*
|
|
67
|
+
* It handles the complexities of bi-directional registrations and offers an abstraction for the Proxy handling.
|
|
68
|
+
*/
|
|
69
|
+
interface IEntityProxiesManager {
|
|
70
|
+
/**
|
|
71
|
+
* Registers a single proxy for an entity.
|
|
72
|
+
*
|
|
73
|
+
* @param entity - The entity to register the proxy for.
|
|
74
|
+
* @param proxy - The proxy to register.
|
|
75
|
+
* @param cleanup - If true, any existing proxies of the same type will be removed before registering the new one.
|
|
76
|
+
*/
|
|
77
|
+
registerProxy(entity: IEntity, proxy: IEntityProxy, cleanup?: boolean): void;
|
|
78
|
+
/**
|
|
79
|
+
* Registers multiple proxies for an entity.
|
|
80
|
+
*
|
|
81
|
+
* @param entity - The entity to register the proxies for.
|
|
82
|
+
* @param proxies - The proxies to register.
|
|
83
|
+
* @param cleanup - If true, any existing proxies of the same type will be removed before registering the new ones.
|
|
84
|
+
*/
|
|
85
|
+
registerProxies(entity: IEntity, proxies: IEntityProxy[], cleanup?: boolean): void;
|
|
86
|
+
/**
|
|
87
|
+
* Removes a single proxy from an entity.
|
|
88
|
+
*
|
|
89
|
+
* @param entity - The entity to remove the proxy from.
|
|
90
|
+
* @param proxy - The proxy to remove.
|
|
91
|
+
*/
|
|
92
|
+
removeProxy(entity: IEntity, proxy: IEntityProxy): void;
|
|
93
|
+
/**
|
|
94
|
+
* Removes all proxies from an entity, optionally filtering by proxy entity type.
|
|
95
|
+
*
|
|
96
|
+
* @param entity - The entity to remove the proxies from.
|
|
97
|
+
* @param proxyEntityType - The type of the proxy entity to filter by.
|
|
98
|
+
*/
|
|
99
|
+
removeProxies(entity: IEntity, proxyEntityType?: EntityTypeUid): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Represents the unique identifier for an entity type.
|
|
104
|
+
* Can be either a string or a number.
|
|
105
|
+
*/
|
|
106
|
+
type EntityTypeUid = string | number;
|
|
107
|
+
/**
|
|
108
|
+
* Represents the unique identifier for an entity.
|
|
109
|
+
* Can be either a string or a number.
|
|
110
|
+
*/
|
|
111
|
+
type EntityUid = string | number;
|
|
112
|
+
/**
|
|
113
|
+
* The `IEntityModel` represents the basic identity information about the current `IEntity`.
|
|
114
|
+
* It's mandatory for each Entity, and it contains the minimal-required information needed for instantiating the Entity.
|
|
115
|
+
*
|
|
116
|
+
* The Features property can be used to toggle Entity features on and off.
|
|
117
|
+
*
|
|
118
|
+
* @template TFeatures - A type that extends `BooleanProps<TFeatures>` to represent the features of the entity.
|
|
119
|
+
* Defaults to `unknown` if not provided.
|
|
120
|
+
*/
|
|
121
|
+
interface IEntityModel<TFeatures extends BooleanProps<TFeatures> = unknown> {
|
|
122
|
+
/**
|
|
123
|
+
* The unique identifier of the entity.
|
|
124
|
+
*/
|
|
125
|
+
readonly uid: EntityUid;
|
|
126
|
+
/**
|
|
127
|
+
* Optional features of the entity.
|
|
128
|
+
* The type of this property should extend `BooleanProps<TFeatures>`.
|
|
129
|
+
*/
|
|
130
|
+
readonly features?: TFeatures;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The `IEntity` interface represents a container of Components and Entity Proxies.
|
|
134
|
+
* It is designed to be immutable and only modifiable through System operations.
|
|
135
|
+
*
|
|
136
|
+
* Implementations of `IEntity` can contain quick-access methods for `Components` or `Proxies`,
|
|
137
|
+
* but should not contain any state-changing logic apart from quick-access functionality.
|
|
138
|
+
*/
|
|
139
|
+
interface IEntity {
|
|
140
|
+
/**
|
|
141
|
+
* A Map of Components associated with this Entity.
|
|
142
|
+
* The keys are ComponentTypeUid, and the values are IComponent instances.
|
|
143
|
+
*/
|
|
144
|
+
readonly components: Map<ComponentTypeUid, IComponent>;
|
|
145
|
+
/**
|
|
146
|
+
* A Map of Entity Proxies associated with this Entity.
|
|
147
|
+
* The outer Map's keys are EntityTypeUid, and the inner Map's keys are EntityUid.
|
|
148
|
+
* The values are IEntityProxy instances.
|
|
149
|
+
*/
|
|
150
|
+
readonly proxies: Map<EntityTypeUid, Map<EntityUid, IEntityProxy>>;
|
|
151
|
+
/**
|
|
152
|
+
* The IdentityComponent represents mandatory state any Entity needs to have.
|
|
153
|
+
* It is a readonly reference to an IdentityComponent instance, which contains the minimal-required information
|
|
154
|
+
* needed for instantiating the Entity.
|
|
155
|
+
*/
|
|
156
|
+
readonly identity: Readonly<IdentityComponent<IEntityModel>>;
|
|
157
|
+
/**
|
|
158
|
+
* A reference to the own Proxy of this Entity.
|
|
159
|
+
* It is a readonly reference to an IEntityProxy instance, which points to this Entity.
|
|
160
|
+
* This is useful for quick access of Proxy data.
|
|
161
|
+
*/
|
|
162
|
+
readonly myProxy: Readonly<IEntityProxy>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The `BasicComponentType` enum defines the types of basic components available.
|
|
167
|
+
*/
|
|
168
|
+
declare enum BasicComponentType {
|
|
169
|
+
identity = "identity"
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* IdentityComponent interface represents the basic information regarding what makes the current Entity unique.
|
|
173
|
+
* It extends the IComponent interface.
|
|
174
|
+
*
|
|
175
|
+
* @template TModel - The type of the model that extends IEntityModel.
|
|
176
|
+
*/
|
|
177
|
+
interface IdentityComponent<TModel extends IEntityModel> extends IComponent {
|
|
178
|
+
/**
|
|
179
|
+
* The Entity Type that defines what Category type the Entity is part of.
|
|
180
|
+
* There can be multiple Entities sharing the same EntityType.
|
|
181
|
+
*/
|
|
182
|
+
readonly entityType: EntityTypeUid;
|
|
183
|
+
/**
|
|
184
|
+
* The Model is the basic information needed to create an `IEntity` when it's first initialized.
|
|
185
|
+
* It provides a first snapshot of information needed for the successful creation of an Entity instance.
|
|
186
|
+
*
|
|
187
|
+
* @type {Immutable<TModel>}
|
|
188
|
+
*/
|
|
189
|
+
readonly model: Immutable<TModel>;
|
|
190
|
+
/**
|
|
191
|
+
* Keeps track when the Entity's systems have ran last.
|
|
192
|
+
* Useful to calculate the `DeltaTime` between runs.
|
|
193
|
+
*
|
|
194
|
+
* @type {Date | undefined}
|
|
195
|
+
*/
|
|
196
|
+
readonly lastUpdated?: Date;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { BasicComponentType as B, type ComponentTypeUid as C, type EntityTypeUid as E, type IEntityProxy as I, type EntityUid as a, type IEntityModel as b, type IEntity as c, type EntityProxy as d, type IEntityProxiesManager as e, type IdentityComponent as f, type IComponent as g };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A unique identifier for a timer.
|
|
3
|
+
*/
|
|
4
|
+
type PerformanceTimerUid = number;
|
|
5
|
+
/**
|
|
6
|
+
* A record of a timer's execution.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This interface represents the details of a timer's execution.
|
|
10
|
+
* It includes the timer's name, start timestamp, end timestamp, and the duration of the timer's execution in milliseconds.
|
|
11
|
+
*
|
|
12
|
+
* @property {string} name - The name of the timer.
|
|
13
|
+
* @property {number} startedAt - The timestamp when the timer started.
|
|
14
|
+
* @property {number} [endedAt] - The timestamp when the timer ended.
|
|
15
|
+
* @property {number} [msPassed] - The time in milliseconds that the timer was active.
|
|
16
|
+
*/
|
|
17
|
+
interface PerformanceTimeEntry {
|
|
18
|
+
name: string;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
endedAt?: number;
|
|
21
|
+
msPassed?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An interface for a performance timer.
|
|
25
|
+
* This interface provides methods to start and end timers,
|
|
26
|
+
* and retrieve information about their execution.
|
|
27
|
+
*/
|
|
28
|
+
interface IPerformanceTimer {
|
|
29
|
+
/**
|
|
30
|
+
* Starts a new timer with the given name.
|
|
31
|
+
* @param {string} name - The name of the timer.
|
|
32
|
+
* @returns {PerformanceTimerUid} - A unique identifier for the newly started timer.
|
|
33
|
+
*/
|
|
34
|
+
startTimer(name: string): PerformanceTimerUid;
|
|
35
|
+
/**
|
|
36
|
+
* Ends the timer with the given timerUid and returns a record of its execution.
|
|
37
|
+
* @param {PerformanceTimerUid} timerUid - The unique identifier of the timer to end.
|
|
38
|
+
* @returns {PerformanceTimeEntry} - A record of the timer's execution.
|
|
39
|
+
* The returned object contains the timer's name, start timestamp, end timestamp,
|
|
40
|
+
* and the duration of the timer's execution in milliseconds.
|
|
41
|
+
*/
|
|
42
|
+
endTimer(timerUid: PerformanceTimerUid): PerformanceTimeEntry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { IPerformanceTimer as I, PerformanceTimeEntry as P, PerformanceTimerUid as a };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A unique identifier for a timer.
|
|
3
|
+
*/
|
|
4
|
+
type PerformanceTimerUid = number;
|
|
5
|
+
/**
|
|
6
|
+
* A record of a timer's execution.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This interface represents the details of a timer's execution.
|
|
10
|
+
* It includes the timer's name, start timestamp, end timestamp, and the duration of the timer's execution in milliseconds.
|
|
11
|
+
*
|
|
12
|
+
* @property {string} name - The name of the timer.
|
|
13
|
+
* @property {number} startedAt - The timestamp when the timer started.
|
|
14
|
+
* @property {number} [endedAt] - The timestamp when the timer ended.
|
|
15
|
+
* @property {number} [msPassed] - The time in milliseconds that the timer was active.
|
|
16
|
+
*/
|
|
17
|
+
interface PerformanceTimeEntry {
|
|
18
|
+
name: string;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
endedAt?: number;
|
|
21
|
+
msPassed?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* An interface for a performance timer.
|
|
25
|
+
* This interface provides methods to start and end timers,
|
|
26
|
+
* and retrieve information about their execution.
|
|
27
|
+
*/
|
|
28
|
+
interface IPerformanceTimer {
|
|
29
|
+
/**
|
|
30
|
+
* Starts a new timer with the given name.
|
|
31
|
+
* @param {string} name - The name of the timer.
|
|
32
|
+
* @returns {PerformanceTimerUid} - A unique identifier for the newly started timer.
|
|
33
|
+
*/
|
|
34
|
+
startTimer(name: string): PerformanceTimerUid;
|
|
35
|
+
/**
|
|
36
|
+
* Ends the timer with the given timerUid and returns a record of its execution.
|
|
37
|
+
* @param {PerformanceTimerUid} timerUid - The unique identifier of the timer to end.
|
|
38
|
+
* @returns {PerformanceTimeEntry} - A record of the timer's execution.
|
|
39
|
+
* The returned object contains the timer's name, start timestamp, end timestamp,
|
|
40
|
+
* and the duration of the timer's execution in milliseconds.
|
|
41
|
+
*/
|
|
42
|
+
endTimer(timerUid: PerformanceTimerUid): PerformanceTimeEntry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type { IPerformanceTimer as I, PerformanceTimeEntry as P, PerformanceTimerUid as a };
|