@perplexdotgg/mecs 0.5.0 → 0.5.1

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 CHANGED
@@ -16,7 +16,7 @@ MECS focuses on the developer's experience in their IDE, especially around auto-
16
16
 
17
17
  <details>
18
18
  <summary>Side note: Why not use SoA design?</summary>
19
- While SoA can achieve better performance in the best cases, it tends to be unwieldy, especially for nested fields, and generally ECS implementations lack auto-complete for components and properties. For larger game projecting, remembering all component names and their properties is quite difficult. Using JS getters with SoA (to achieve auto complete) gives much worse overall performance than AoS.
19
+ While SoA can achieve better performance in the best cases, it tends to be unwieldy, especially for nested fields, and generally ECS implementations lack auto-complete for components and properties. For larger game projects, remembering all component names and their properties is quite difficult. Using JS getters with SoA (to achieve auto complete) gives much worse overall performance than AoS.
20
20
  </details>
21
21
 
22
22
  ---
package/build/index.d.ts CHANGED
@@ -64,6 +64,16 @@ declare type ComponentMapInputListItems<CM extends ComponentMap> = Partial<{
64
64
  [K in keyof CM as LowercaseFirstLetter<K>]: ResolveEntityInputListItems<ComponentInput<ExtractMonomorphClass<CM[K]>>, CM>;
65
65
  }>;
66
66
 
67
+ declare type ComponentsWithEntities<E, CM extends ComponentMap> = {
68
+ [K in keyof CM as ExtractMonomorphClass<CM[K]> extends MonomorphClass<infer P, infer I, infer M> ? LowercaseFirstLetter<K> : never]: {
69
+ [Symbol.iterator](): IterableIterator<[WithPool<InstanceType<ExtractMonomorphClass<CM[K]>>>, E]>;
70
+ };
71
+ };
72
+
73
+ declare type ComponentsWithEntitiesCallable<E, CM extends ComponentMap> = ComponentsWithEntities<E, CM> & {
74
+ <Self extends abstract new (...args: any) => any>(this: Self): ComponentsWithEntities<InstanceType<Self>, CM>;
75
+ };
76
+
67
77
  declare type ComponentTypeFromMonomorphClass<T> = T extends MonomorphClass<infer P, any, any> ? PropertyDefinitionClassProperties<P> : never;
68
78
 
69
79
  export declare function createEntityClass<C>(options?: EntityCodeGenerationOptions): <CM extends ComponentMap, QM extends QueryMap<CM>, I extends ComponentMapInput<CM> = ComponentMapInput<CM>>(componentMap: CM, queries?: QM) => EntityClassWithStatics<C, CM, QM, I>;
@@ -84,6 +94,8 @@ declare interface EntityBaseProperties<CM extends ComponentMap, I extends any =
84
94
  reset(data?: PartialRecursive<I>, updateQueryMemberships?: boolean, pool?: EntityPoolClass<this>): void;
85
95
  destroy(updateQueryMemberships?: boolean): void;
86
96
  isDestroyed(): boolean;
97
+ poolIndex: number;
98
+ pool: EntityPoolClass<this>;
87
99
  }
88
100
 
89
101
  export declare type EntityClass<CM extends ComponentMap, I extends ComponentMapInput<CM> = ComponentMapInput<CM>, QM extends QueryMap<CM> = QueryMap<CM>, E extends EntityInstance<CM, I> = EntityInstance<CM, I>> = EntityConstructor<QM, E, I, CM>;
@@ -121,11 +133,7 @@ export declare interface EntityConstructor<QM extends QueryMap<CM>, E extends En
121
133
  __typescriptOnlyInputType: I;
122
134
  pool: PoolCallable<E>;
123
135
  queries: QueriesCallable<E, QM, CM>;
124
- componentsWithEntities: {
125
- [K in keyof CM as ExtractMonomorphClass<CM[K]> extends MonomorphClass<infer P, infer I, infer M> ? LowercaseFirstLetter<K> : never]: {
126
- [Symbol.iterator](): IterableIterator<[WithPool<InstanceType<ExtractMonomorphClass<CM[K]>>>, E]>;
127
- };
128
- };
136
+ componentsWithEntities: ComponentsWithEntitiesCallable<E, CM>;
129
137
  components: {
130
138
  [K in keyof CM as ExtractMonomorphClass<CM[K]> extends MonomorphClass<infer P, infer I, infer M> ? LowercaseFirstLetter<K> : never]: PoolClass<ExtractMonomorphClass<CM[K]>>;
131
139
  };
package/build/mecs.js CHANGED
@@ -1033,9 +1033,23 @@ function getEntityClassCode(componentMap, queries, options) {
1033
1033
  theClass.componentToEntity = componentToEntity;
1034
1034
  theClass.componentIndices = componentIndices;
1035
1035
  theClass.components = componentPools;
1036
- theClass.componentsWithEntities = {
1036
+
1037
+ const componentsWithEntities = {
1037
1038
  ${componentWithEntityIteratorFunctionsCode}
1038
1039
  };
1040
+ const componentsWithEntityCallable = new Proxy(function () { return componentsWithEntityCallable; }, {
1041
+ get(_target, prop) {
1042
+ if (prop in componentsWithEntities) {
1043
+ return componentsWithEntities[prop];
1044
+ }
1045
+ return undefined;
1046
+ },
1047
+ set(_target, prop, value) {
1048
+ componentsWithEntities[prop] = value;
1049
+ return true;
1050
+ },
1051
+ });
1052
+ theClass.componentsWithEntities = componentsWithEntityCallable;
1039
1053
 
1040
1054
  theClass.create = function(data, updateQueryMemberships = true, pool = this.pool) {
1041
1055
  if (pool.freeIndices.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perplexdotgg/mecs",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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",