@dcl/ecs 7.0.1 → 7.0.2-3570171208.commit-a7ab97a

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.
@@ -56,6 +56,11 @@ function preEngine() {
56
56
  }
57
57
  return component;
58
58
  }
59
+ function getComponentOrNull(componentId) {
60
+ return (componentsDefinition.get(componentId) ??
61
+ /* istanbul ignore next */
62
+ null);
63
+ }
59
64
  function* getEntitiesWith(...components) {
60
65
  for (const [entity, ...groupComp] of getComponentDefGroup(...components)) {
61
66
  yield [entity, ...groupComp.map((c) => c.get(entity))];
@@ -95,6 +100,7 @@ function preEngine() {
95
100
  defineComponentFromSchema,
96
101
  getEntitiesWith,
97
102
  getComponent,
103
+ getComponentOrNull,
98
104
  removeComponentDefinition
99
105
  };
100
106
  }
@@ -161,6 +167,7 @@ export function Engine() {
161
167
  defineComponentFromSchema: engine.defineComponentFromSchema,
162
168
  getEntitiesWith: engine.getEntitiesWith,
163
169
  getComponent: engine.getComponent,
170
+ getComponentOrNull: engine.getComponentOrNull,
164
171
  removeComponentDefinition: engine.removeComponentDefinition,
165
172
  update,
166
173
  RootEntity: 0,
@@ -109,6 +109,16 @@ export declare type IEngine = {
109
109
  * ```
110
110
  */
111
111
  getComponent<T extends ISchema>(componentId: number): CompDef<T>;
112
+ /**
113
+ * Get the component definition from the component id.
114
+ * @param componentId - component number used to identify the component descriptor
115
+ * @returns the component definition or null if its not founded
116
+ * ```ts
117
+ * const StateComponentId = 10023
118
+ * const StateComponent = engine.getComponent(StateComponentId)
119
+ * ```
120
+ */
121
+ getComponentOrNull<T extends ISchema>(componentId: number): CompDef<T> | null;
112
122
  /**
113
123
  * Get a iterator of entities that has all the component requested.
114
124
  * @param components - a list of component definitions
@@ -1,7 +1,7 @@
1
1
  import type { IEngine } from '../../engine';
2
2
  import { Entity } from '../../engine/entity';
3
3
  import { Transport } from './types';
4
- export declare function crdtSceneSystem(engine: Pick<IEngine, 'getComponent'>): {
4
+ export declare function crdtSceneSystem(engine: Pick<IEngine, 'getComponentOrNull'>): {
5
5
  createMessages: (dirtyMap: Map<Entity, Set<number>>) => void;
6
6
  receiveMessages: () => void;
7
7
  addTransport: (transport: Transport) => void;
@@ -70,8 +70,12 @@ export function crdtSceneSystem(engine) {
70
70
  data: data || null,
71
71
  timestamp: timestamp
72
72
  };
73
- const component = engine.getComponent(componentId);
73
+ const component = engine.getComponentOrNull(componentId);
74
74
  const current = crdtClient.processMessage(crdtMessage);
75
+ /* istanbul ignore next */
76
+ if (!component)
77
+ // TODO: TEST
78
+ continue;
75
79
  // CRDT outdated message. Resend this message through the wire
76
80
  if (crdtMessage !== current) {
77
81
  const type = component.has(entity)
@@ -112,7 +116,11 @@ export function crdtSceneSystem(engine) {
112
116
  const buffer = createByteBuffer();
113
117
  for (const [entity, componentsId] of dirtyMap) {
114
118
  for (const componentId of componentsId) {
115
- const component = engine.getComponent(componentId);
119
+ const component = engine.getComponentOrNull(componentId);
120
+ /* istanbul ignore next */
121
+ if (!component)
122
+ // TODO: test coverage
123
+ continue;
116
124
  const entityComponent = component.has(entity)
117
125
  ? component.toBinary(entity).toBinary()
118
126
  : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
- "version": "7.0.1",
3
+ "version": "7.0.2-3570171208.commit-a7ab97a",
4
4
  "description": "Decentraland ECS",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -35,5 +35,5 @@
35
35
  "dist",
36
36
  "etc"
37
37
  ],
38
- "commit": "fb5b256656ad93683c9df90b7d7d360486c68fb0"
38
+ "commit": "a7ab97aa9d8bdf66cfc414e3884ef7163d912fae"
39
39
  }