@perplexdotgg/mecs 0.3.0 → 0.3.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/README.md +12 -8
- package/build/index.d.ts +14 -12
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -192,9 +192,9 @@ const entity1 = Entity.create({
|
|
|
192
192
|
},
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
// now entity1 is of the Entity class, and entity1.
|
|
195
|
+
// now entity1 is of the Entity class, and entity1.globalTransform is of the Transform class
|
|
196
196
|
// so you can call methods on it like so:
|
|
197
|
-
entity1.
|
|
197
|
+
entity1.globalTransform.composeMatrix();
|
|
198
198
|
|
|
199
199
|
const entity2 = Entity.create({
|
|
200
200
|
projectile: {
|
|
@@ -203,7 +203,7 @@ const entity2 = Entity.create({
|
|
|
203
203
|
},
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
// destroy() to return
|
|
206
|
+
// you can use destroy() to return an entity to the pool, it will automatically be re-used later
|
|
207
207
|
// this iterates on all components to remove them first, and triggers queries just
|
|
208
208
|
// before the component(s) needed for the query are deleted
|
|
209
209
|
// each destroyed component also gets recycled in its own component pool
|
|
@@ -248,7 +248,7 @@ const components = {
|
|
|
248
248
|
// component config options here, see "Customizing Components" below
|
|
249
249
|
},
|
|
250
250
|
|
|
251
|
-
}
|
|
251
|
+
};
|
|
252
252
|
|
|
253
253
|
const queries = {};
|
|
254
254
|
|
|
@@ -381,7 +381,7 @@ Entity.queries.projectiles.beforeEntityRemoved.removeListener(someListener);
|
|
|
381
381
|
```
|
|
382
382
|
|
|
383
383
|
### Components that reference Entities
|
|
384
|
-
You can have components that reference other entities, by using Monomorph's `LazyReferenceType` and `LazyReferenceListType
|
|
384
|
+
You can have components that reference other entities, by using Monomorph's `LazyReferenceType` and `LazyReferenceListType`. This will usually 'just work', but in some situations you may also need to use MECS's `LazyComponent`. See the Typescript tests in [`tests/componentsWithEntityReferences.test.ts`](https://codeberg.org/perplexdotgg/mecs/src/branch/main/tests/componentsWithEntityReferences.test.ts) and [`tests/lazyComponentsWithEntityReferences.test.ts`](https://codeberg.org/perplexdotgg/mecs/src/branch/main/tests/lazyComponentsWithEntityReferences.test.ts) for examples. Below is a simple Javascript example:
|
|
385
385
|
|
|
386
386
|
```js
|
|
387
387
|
const turretProps = {
|
|
@@ -393,11 +393,15 @@ const turretProps = {
|
|
|
393
393
|
class Turret extends createClass(turretProps) {}
|
|
394
394
|
|
|
395
395
|
const components = {
|
|
396
|
-
turret:
|
|
396
|
+
turret: Turret,
|
|
397
|
+
// or the lazy loaded version:
|
|
398
|
+
// turret: LazyComponent(() => Turret),
|
|
397
399
|
|
|
398
400
|
// alternatively, you can use a component config object for further customization:
|
|
399
401
|
turret: {
|
|
400
|
-
monomorphClass:
|
|
402
|
+
monomorphClass: Turret,
|
|
403
|
+
// or the lazy loaded version:
|
|
404
|
+
// monomorphClass: LazyComponent(() => Turret),
|
|
401
405
|
|
|
402
406
|
// other config options here, for example:
|
|
403
407
|
afterComponentAdded: (turretInstance, entity, componentKey) => {
|
|
@@ -407,7 +411,7 @@ const components = {
|
|
|
407
411
|
},
|
|
408
412
|
},
|
|
409
413
|
};
|
|
410
|
-
class Entity extends createEntityClass()(components,
|
|
414
|
+
class Entity extends createEntityClass()(components, queries) {}
|
|
411
415
|
```
|
|
412
416
|
|
|
413
417
|
|
package/build/index.d.ts
CHANGED
|
@@ -43,13 +43,17 @@ declare type ComponentMapClassProperties<CM> = {
|
|
|
43
43
|
[K in keyof CM as LowercaseFirstLetter<K>]?: ExtractMonomorphClass<CM[K]> extends MonomorphClass<infer P, infer I, infer M> ? M : ExtractMonomorphClass<CM[K]>;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export declare
|
|
46
|
+
export declare type ComponentMapInput<CM extends ComponentMap> = Partial<{
|
|
47
|
+
[K in keyof CM as LowercaseFirstLetter<K>]: ComponentInput<ExtractMonomorphClass<CM[K]>>;
|
|
48
|
+
}>;
|
|
49
|
+
|
|
50
|
+
export declare function createEntityClass<C>(options?: EntityCodeGenerationOptions): <CM extends ComponentMap, QM extends QueryMap<C, CM>, I extends ComponentMapInput<CM> = ComponentMapInput<CM>>(componentMap: CM, queries?: QM) => EntityClassWithStatics<C, CM, QM, I>;
|
|
47
51
|
|
|
48
|
-
export declare type CreateEntityFunction<C, CM extends ComponentMap, I extends
|
|
52
|
+
export declare type CreateEntityFunction<C, CM extends ComponentMap, I extends ComponentMapInput<CM>> = (data?: I, pool?: EntityPoolClass<C>) => EntityInstanceWithPool<CM, I, C>;
|
|
49
53
|
|
|
50
54
|
declare type ElementOfArray<T> = T extends (infer E)[] ? E : never;
|
|
51
55
|
|
|
52
|
-
declare interface EntityBaseProperties<CM extends ComponentMap, I extends
|
|
56
|
+
declare interface EntityBaseProperties<CM extends ComponentMap, I extends any = ComponentMapInput<CM>> {
|
|
53
57
|
componentMap: CM;
|
|
54
58
|
__typescriptOnlyInputType: I;
|
|
55
59
|
addComponent: <CCK extends LowercaseFirstLetter<keyof CM>, CC extends CM[OriginalComponentKey<CCK, CM>] = CM[OriginalComponentKey<CCK, CM>]>(...a: (undefined extends ComponentInput<ExtractMonomorphClass<CC>> ? [key: CCK, data?: ComponentInput<ExtractMonomorphClass<CC>>] : [key: CCK, data: ComponentInput<ExtractMonomorphClass<CC>>])) => void;
|
|
@@ -60,9 +64,9 @@ declare interface EntityBaseProperties<CM extends ComponentMap, I extends Entity
|
|
|
60
64
|
isDestroyed(): boolean;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
export declare type EntityClass<CM extends ComponentMap, I extends
|
|
67
|
+
export declare type EntityClass<CM extends ComponentMap, I extends ComponentMapInput<CM> = ComponentMapInput<CM>, QM extends QueryMap<any, CM> = QueryMap<any, CM>, E extends EntityInstance<CM, I> = EntityInstance<CM, I>> = EntityConstructor<QM, E, I, CM>;
|
|
64
68
|
|
|
65
|
-
export declare type EntityClassWithStatics<C, CM extends ComponentMap, QM extends QueryMap<C, CM>, I extends
|
|
69
|
+
export declare type EntityClassWithStatics<C, CM extends ComponentMap, QM extends QueryMap<C, CM>, I extends ComponentMapInput<CM> = ComponentMapInput<CM>> = EntityClass<CM, I, QM> & {
|
|
66
70
|
create: CreateEntityFunction<C, CM, I>;
|
|
67
71
|
Pool: NoInfer<EntityPoolClass<C>>;
|
|
68
72
|
};
|
|
@@ -88,7 +92,7 @@ declare type EntityCodeGenerationOptions = {
|
|
|
88
92
|
skipSafetyChecks?: boolean;
|
|
89
93
|
};
|
|
90
94
|
|
|
91
|
-
export declare interface EntityConstructor<QM extends QueryMap<any, CM>, E extends EntityInstance<CM, I>, I extends
|
|
95
|
+
export declare interface EntityConstructor<QM extends QueryMap<any, CM>, E extends EntityInstance<CM, I>, I extends any, CM extends ComponentMap> {
|
|
92
96
|
new (data: I): E;
|
|
93
97
|
componentMap: CM;
|
|
94
98
|
__typescriptOnlyInputType: I;
|
|
@@ -118,13 +122,11 @@ export declare interface EntityConstructor<QM extends QueryMap<any, CM>, E exten
|
|
|
118
122
|
};
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
export declare type EntityInput<
|
|
122
|
-
[K in keyof CM as LowercaseFirstLetter<K>]: ComponentInput<ExtractMonomorphClass<CM[K]>>;
|
|
123
|
-
}>;
|
|
125
|
+
export declare type EntityInput<X extends ComponentMap | EntityClass<any, any, any, any> | EntityInstanceWithPool<any, any, any> | EntityInstance<any, any>> = X extends ComponentMap ? ComponentMapInput<X> : X extends EntityConstructor<infer QM, infer E, infer I, infer CM> ? I : X extends EntityInstanceWithPool<infer CM, infer I, infer E> ? I : X extends EntityInstance<infer CM, infer I> ? I : never;
|
|
124
126
|
|
|
125
|
-
export declare type EntityInstance<CM extends ComponentMap, I extends
|
|
127
|
+
export declare type EntityInstance<CM extends ComponentMap, I extends any = ComponentMapInput<CM>> = ComponentMapClassProperties<CM> & EntityBaseProperties<CM, I>;
|
|
126
128
|
|
|
127
|
-
export declare type EntityInstanceWithPool<CM extends ComponentMap, I extends
|
|
129
|
+
export declare type EntityInstanceWithPool<CM extends ComponentMap, I extends ComponentMapInput<CM>, E> = NoInfer<E & {
|
|
128
130
|
pool: EntityPoolClass<E> | null;
|
|
129
131
|
createInPool(data?: I): EntityInstanceWithPool<CM, I, E>;
|
|
130
132
|
}>;
|
|
@@ -148,7 +150,7 @@ export declare interface EntityPoolClass<M> {
|
|
|
148
150
|
/** how many non-destroyed objects are in this pool, i.e. how many would be iterated on */
|
|
149
151
|
length: number;
|
|
150
152
|
[Symbol.iterator](): IterableIterator<WithPool<M>>;
|
|
151
|
-
create(data?: M extends EntityInstance<infer CM, infer I> ?
|
|
153
|
+
create(data?: M extends EntityInstance<infer CM, infer I> ? ComponentMapInput<CM> : undefined): M extends EntityInstanceWithPool<infer CM, infer I, any> ? EntityInstanceWithPool<CM, I, M> : never;
|
|
152
154
|
toArray(array: NumberArray, startOffset?: number): number;
|
|
153
155
|
fromArray(array: NumberArray, startOffset?: number, classConstructor?: new (...args: any[]) => M): number;
|
|
154
156
|
fromArrayNoReferences(array: NumberArray, startOffset?: number, classConstructor?: new (...args: any[]) => M): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perplexdotgg/mecs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "MECS - Monomorph ECS - A high-performance Entity Component System for TypeScript and JavaScript projects, designed for games and simulations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"bench": "vitest bench"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"monomorph": "^1.5.
|
|
31
|
+
"monomorph": "^1.5.6"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
|
34
34
|
"monomorph": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^25.0.1",
|
|
40
|
-
"monomorph": "^1.5.
|
|
40
|
+
"monomorph": "^1.5.6",
|
|
41
41
|
"ts-node": "^10.9.2",
|
|
42
42
|
"tslib": "^2.8.1",
|
|
43
43
|
"typescript": "^5.9.3",
|