@dcl/ecs 7.23.4-26770223094.commit-52b9415 → 7.23.4-26955626649.commit-5d040fd

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.
@@ -6,6 +6,7 @@ import { CompositeDefinition } from './proto/gen/composite.gen';
6
6
  export type { CompositeDefinition, ComponentData, CompositeComponent, CompositeComponent_DataEntry, InstanceCompositeOptions, CompositeProvider, CompositeRootType, CompositeResource };
7
7
  export { EntityMappingMode };
8
8
  export { getCompositeRootComponent };
9
+ export { setCompositeProvider, getCompositeProvider } from './provider-registry';
9
10
  /**
10
11
  * @public
11
12
  * @deprecated composite is not being supported so far, please do not use this feature
@@ -31,14 +32,16 @@ export declare namespace Composite {
31
32
  /** @public */
32
33
  function toBinary(composite: Composite.Definition): Uint8Array;
33
34
  /**
34
- * Instance a composite and returns its root entity
35
- * @param compositeData - state serialized by the CRDT protocol
36
- * @param getNextAvailableEntity - function that gives unused entities
37
- * @param rootEntity - (optional) suggested mapped rootEntity for the composite
35
+ * Instance a composite and return its root entity.
36
+ * @param engine - the engine that will own the new entities
37
+ * @param compositeData - the composite resource to instance
38
+ * @param compositeProvider - provider used to resolve nested composite references
39
+ * @param options - instancing options (`rootEntity`, `entityMapping`, `alreadyRequestedSrc`)
40
+ * @returns the root entity of the instanced composite
38
41
  *
39
42
  * @public
40
43
  */
41
- function instance(engine: IEngine, compositeData: Composite.Resource, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): void;
44
+ function instance(engine: IEngine, compositeData: Composite.Resource, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): import("../engine").Entity;
42
45
  /**
43
46
  * Resolve and normalize a composite path
44
47
  * @param src - the source path
@@ -4,6 +4,7 @@ import { resolveComposite } from './path';
4
4
  import { CompositeDefinition } from './proto/gen/composite.gen';
5
5
  export { EntityMappingMode };
6
6
  export { getCompositeRootComponent };
7
+ export { setCompositeProvider, getCompositeProvider } from './provider-registry';
7
8
  /**
8
9
  * @public
9
10
  * @deprecated composite is not being supported so far, please do not use this feature
@@ -31,15 +32,17 @@ export var Composite;
31
32
  }
32
33
  Composite.toBinary = toBinary;
33
34
  /**
34
- * Instance a composite and returns its root entity
35
- * @param compositeData - state serialized by the CRDT protocol
36
- * @param getNextAvailableEntity - function that gives unused entities
37
- * @param rootEntity - (optional) suggested mapped rootEntity for the composite
35
+ * Instance a composite and return its root entity.
36
+ * @param engine - the engine that will own the new entities
37
+ * @param compositeData - the composite resource to instance
38
+ * @param compositeProvider - provider used to resolve nested composite references
39
+ * @param options - instancing options (`rootEntity`, `entityMapping`, `alreadyRequestedSrc`)
40
+ * @returns the root entity of the instanced composite
38
41
  *
39
42
  * @public
40
43
  */
41
44
  /*#__PURE__*/ function instance(engine, compositeData, compositeProvider, options = {}) {
42
- instanceComposite(engine, compositeData, compositeProvider, options);
45
+ return instanceComposite(engine, compositeData, compositeProvider, options);
43
46
  }
44
47
  Composite.instance = instance;
45
48
  /**
@@ -13,6 +13,11 @@ export type CompositeResource = {
13
13
  */
14
14
  export type CompositeProvider = {
15
15
  getCompositeOrNull(src: string): CompositeResource | null;
16
+ loadComposite?: (src: string) => Promise<CompositeResource>;
17
+ schemas?: Iterable<{
18
+ name: string;
19
+ jsonSchema: any;
20
+ }>;
16
21
  };
17
22
  /** @public */
18
23
  export declare enum EntityMappingMode {
@@ -43,7 +43,7 @@ export function getComponentDefinition(engine, component) {
43
43
  return engine.defineComponentFromSchema(component.name, Schemas.fromJson(component.jsonSchema));
44
44
  }
45
45
  else {
46
- throw new Error(`${component.name} is not defined and there is no schema to define it.`);
46
+ throw new Error(`Composite references undefined component "${component.name}". Ensure provider.schemas was registered pre-seal via setCompositeProvider().`);
47
47
  }
48
48
  }
49
49
  else {
@@ -84,6 +84,7 @@ export function instanceComposite(engine, compositeResource, compositeProvider,
84
84
  const compositeDirectoryPath = path.dirname(path.resolve(compositeResource.src));
85
85
  const TransformComponentNumber = componentNumberFromName('core::Transform');
86
86
  const CompositeRootComponent = getCompositeRootComponent(engine);
87
+ let hadNestedComposite = false;
87
88
  // Key => EntityNumber from the composite
88
89
  // Value => EntityNumber in current engine
89
90
  const mappedEntities = new Map();
@@ -99,23 +100,29 @@ export function instanceComposite(engine, compositeResource, compositeProvider,
99
100
  // If there are more composite inside this one, we instance first.
100
101
  // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
101
102
  // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
102
- const childrenComposite = compositeResource.composite.components.find((item) => item.name === CompositeRootComponent.componentName);
103
- if (childrenComposite) {
104
- for (const [childCompositeEntity, compositeRawData] of childrenComposite.data) {
105
- const childComposite = getComponentValue(CompositeRootComponent, compositeRawData);
106
- const childCompositePath = path.resolveComposite(childComposite.src, compositeDirectoryPath);
107
- const childCompositeResource = compositeProvider.getCompositeOrNull(childCompositePath);
108
- const targetEntity = getCompositeEntity(childCompositeEntity);
109
- if (childCompositeResource) {
110
- if (alreadyRequestedSrc.has(childCompositeResource.src) ||
111
- childCompositeResource.src === compositeResource.src) {
112
- throw new Error(`Composite ${compositeResource.src} has a recursive instanciation while try to instance ${childCompositeResource.src}. Previous instances: ${alreadyRequestedSrc.toString()}`);
103
+ if (CompositeRootComponent) {
104
+ const childrenComposite = compositeResource.composite.components.find((item) => item.name === CompositeRootComponent.componentName);
105
+ if (childrenComposite) {
106
+ for (const [childCompositeEntity, compositeRawData] of childrenComposite.data) {
107
+ const childComposite = getComponentValue(CompositeRootComponent, compositeRawData);
108
+ const childCompositePath = path.resolveComposite(childComposite.src, compositeDirectoryPath);
109
+ const childCompositeResource = compositeProvider.getCompositeOrNull(childCompositePath);
110
+ const targetEntity = getCompositeEntity(childCompositeEntity);
111
+ if (childCompositeResource) {
112
+ if (alreadyRequestedSrc.has(childCompositeResource.src) ||
113
+ childCompositeResource.src === compositeResource.src) {
114
+ throw new Error(`Composite ${compositeResource.src} has a recursive instanciation while try to instance ${childCompositeResource.src}. Previous instances: ${alreadyRequestedSrc.toString()}`);
115
+ }
116
+ hadNestedComposite = true;
117
+ instanceComposite(engine, childCompositeResource, compositeProvider, {
118
+ rootEntity: targetEntity,
119
+ alreadyRequestedSrc: new Set(alreadyRequestedSrc).add(childCompositeResource.src),
120
+ entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
121
+ });
122
+ }
123
+ else {
124
+ console.warn(`Composite "${compositeResource.src}" references missing nested composite "${childCompositePath}". Skipping; the spawned subtree will be incomplete.`);
113
125
  }
114
- instanceComposite(engine, childCompositeResource, compositeProvider, {
115
- rootEntity: targetEntity,
116
- alreadyRequestedSrc: new Set(alreadyRequestedSrc).add(childCompositeResource.src),
117
- entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
118
- });
119
126
  }
120
127
  }
121
128
  }
@@ -123,7 +130,7 @@ export function instanceComposite(engine, compositeResource, compositeProvider,
123
130
  // Then, we copy the all rest of the components (skipping the Composite ones)
124
131
  for (const component of compositeResource.composite.components) {
125
132
  // We already instanced the composite
126
- if (component.name === CompositeRootComponent.componentName)
133
+ if (CompositeRootComponent && component.name === CompositeRootComponent.componentName)
127
134
  continue;
128
135
  // ## 3a ##
129
136
  // We find the component definition
@@ -159,13 +166,15 @@ export function instanceComposite(engine, compositeResource, compositeProvider,
159
166
  }
160
167
  }
161
168
  }
162
- const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
163
- for (const [entitySource, targetEntity] of mappedEntities) {
164
- composite.entities.push({
165
- src: entitySource,
166
- dest: targetEntity
167
- });
169
+ if (hadNestedComposite) {
170
+ const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
171
+ for (const [entitySource, targetEntity] of mappedEntities) {
172
+ composite.entities.push({
173
+ src: entitySource,
174
+ dest: targetEntity
175
+ });
176
+ }
177
+ composite.src = compositeResource.src;
168
178
  }
169
- composite.src = compositeResource.src;
170
179
  return compositeRootEntity;
171
180
  }
@@ -0,0 +1,15 @@
1
+ import type { IEngine } from '../engine';
2
+ import type { CompositeProvider } from './instance';
3
+ /**
4
+ * Register the composite provider used to resolve composite files. Also registers
5
+ * any `provider.schemas` on the engine pre-seal so composites that reference those
6
+ * components can be instanced without further setup.
7
+ * @public
8
+ */
9
+ export declare function setCompositeProvider(engine: IEngine, provider: CompositeProvider): void;
10
+ /**
11
+ * Get the composite provider registered via setCompositeProvider. Returns null if
12
+ * no provider has been set.
13
+ * @public
14
+ */
15
+ export declare function getCompositeProvider(): CompositeProvider | null;
@@ -0,0 +1,32 @@
1
+ import { Schemas } from '../schemas';
2
+ import { getCompositeRootComponent } from './components';
3
+ let currentProvider = null;
4
+ /**
5
+ * Register the composite provider used to resolve composite files. Also registers
6
+ * any `provider.schemas` on the engine pre-seal so composites that reference those
7
+ * components can be instanced without further setup.
8
+ * @public
9
+ */
10
+ export function setCompositeProvider(engine, provider) {
11
+ currentProvider = provider;
12
+ // Define composite::root pre-seal. setCompositeProvider runs at module-load,
13
+ // so this guarantees the component exists before the engine seals — composites
14
+ // instanced at runtime (post-seal) would otherwise trip the seal when
15
+ // instanceComposite looks it up via getCompositeRootComponent.
16
+ getCompositeRootComponent(engine);
17
+ if (!provider.schemas)
18
+ return;
19
+ for (const { name, jsonSchema } of provider.schemas) {
20
+ if (engine.getComponentOrNull(name))
21
+ continue;
22
+ engine.defineComponentFromSchema(name, Schemas.fromJson(jsonSchema));
23
+ }
24
+ }
25
+ /**
26
+ * Get the composite provider registered via setCompositeProvider. Returns null if
27
+ * no provider has been set.
28
+ * @public
29
+ */
30
+ export function getCompositeProvider() {
31
+ return currentProvider;
32
+ }
@@ -236,7 +236,7 @@ export function Engine(options) {
236
236
  const deletedEntites = partialEngine.entityContainer.releaseRemovedEntities();
237
237
  await crdtSystem.sendMessages(deletedEntites);
238
238
  }
239
- return {
239
+ const engineInstance = {
240
240
  _id: Date.now(),
241
241
  addEntity: partialEngine.addEntity,
242
242
  removeEntity: partialEngine.removeEntity,
@@ -264,4 +264,5 @@ export function Engine(options) {
264
264
  addTransport: crdtSystem.addTransport,
265
265
  entityContainer: partialEngine.entityContainer
266
266
  };
267
+ return engineInstance;
267
268
  }
@@ -6,6 +6,7 @@ import { CompositeDefinition } from './proto/gen/composite.gen';
6
6
  export type { CompositeDefinition, ComponentData, CompositeComponent, CompositeComponent_DataEntry, InstanceCompositeOptions, CompositeProvider, CompositeRootType, CompositeResource };
7
7
  export { EntityMappingMode };
8
8
  export { getCompositeRootComponent };
9
+ export { setCompositeProvider, getCompositeProvider } from './provider-registry';
9
10
  /**
10
11
  * @public
11
12
  * @deprecated composite is not being supported so far, please do not use this feature
@@ -31,14 +32,16 @@ export declare namespace Composite {
31
32
  /** @public */
32
33
  function toBinary(composite: Composite.Definition): Uint8Array;
33
34
  /**
34
- * Instance a composite and returns its root entity
35
- * @param compositeData - state serialized by the CRDT protocol
36
- * @param getNextAvailableEntity - function that gives unused entities
37
- * @param rootEntity - (optional) suggested mapped rootEntity for the composite
35
+ * Instance a composite and return its root entity.
36
+ * @param engine - the engine that will own the new entities
37
+ * @param compositeData - the composite resource to instance
38
+ * @param compositeProvider - provider used to resolve nested composite references
39
+ * @param options - instancing options (`rootEntity`, `entityMapping`, `alreadyRequestedSrc`)
40
+ * @returns the root entity of the instanced composite
38
41
  *
39
42
  * @public
40
43
  */
41
- function instance(engine: IEngine, compositeData: Composite.Resource, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): void;
44
+ function instance(engine: IEngine, compositeData: Composite.Resource, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): import("../engine").Entity;
42
45
  /**
43
46
  * Resolve and normalize a composite path
44
47
  * @param src - the source path
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Composite = exports.getCompositeRootComponent = exports.EntityMappingMode = void 0;
3
+ exports.Composite = exports.getCompositeProvider = exports.setCompositeProvider = exports.getCompositeRootComponent = exports.EntityMappingMode = void 0;
4
4
  const components_1 = require("./components");
5
5
  Object.defineProperty(exports, "getCompositeRootComponent", { enumerable: true, get: function () { return components_1.getCompositeRootComponent; } });
6
6
  const instance_1 = require("./instance");
7
7
  Object.defineProperty(exports, "EntityMappingMode", { enumerable: true, get: function () { return instance_1.EntityMappingMode; } });
8
8
  const path_1 = require("./path");
9
9
  const composite_gen_1 = require("./proto/gen/composite.gen");
10
+ var provider_registry_1 = require("./provider-registry");
11
+ Object.defineProperty(exports, "setCompositeProvider", { enumerable: true, get: function () { return provider_registry_1.setCompositeProvider; } });
12
+ Object.defineProperty(exports, "getCompositeProvider", { enumerable: true, get: function () { return provider_registry_1.getCompositeProvider; } });
10
13
  /**
11
14
  * @public
12
15
  * @deprecated composite is not being supported so far, please do not use this feature
@@ -34,15 +37,17 @@ var Composite;
34
37
  }
35
38
  Composite.toBinary = toBinary;
36
39
  /**
37
- * Instance a composite and returns its root entity
38
- * @param compositeData - state serialized by the CRDT protocol
39
- * @param getNextAvailableEntity - function that gives unused entities
40
- * @param rootEntity - (optional) suggested mapped rootEntity for the composite
40
+ * Instance a composite and return its root entity.
41
+ * @param engine - the engine that will own the new entities
42
+ * @param compositeData - the composite resource to instance
43
+ * @param compositeProvider - provider used to resolve nested composite references
44
+ * @param options - instancing options (`rootEntity`, `entityMapping`, `alreadyRequestedSrc`)
45
+ * @returns the root entity of the instanced composite
41
46
  *
42
47
  * @public
43
48
  */
44
49
  /*#__PURE__*/ function instance(engine, compositeData, compositeProvider, options = {}) {
45
- (0, instance_1.instanceComposite)(engine, compositeData, compositeProvider, options);
50
+ return (0, instance_1.instanceComposite)(engine, compositeData, compositeProvider, options);
46
51
  }
47
52
  Composite.instance = instance;
48
53
  /**
@@ -13,6 +13,11 @@ export type CompositeResource = {
13
13
  */
14
14
  export type CompositeProvider = {
15
15
  getCompositeOrNull(src: string): CompositeResource | null;
16
+ loadComposite?: (src: string) => Promise<CompositeResource>;
17
+ schemas?: Iterable<{
18
+ name: string;
19
+ jsonSchema: any;
20
+ }>;
16
21
  };
17
22
  /** @public */
18
23
  export declare enum EntityMappingMode {
@@ -70,7 +70,7 @@ function getComponentDefinition(engine, component) {
70
70
  return engine.defineComponentFromSchema(component.name, schemas_1.Schemas.fromJson(component.jsonSchema));
71
71
  }
72
72
  else {
73
- throw new Error(`${component.name} is not defined and there is no schema to define it.`);
73
+ throw new Error(`Composite references undefined component "${component.name}". Ensure provider.schemas was registered pre-seal via setCompositeProvider().`);
74
74
  }
75
75
  }
76
76
  else {
@@ -113,6 +113,7 @@ function instanceComposite(engine, compositeResource, compositeProvider, options
113
113
  const compositeDirectoryPath = path.dirname(path.resolve(compositeResource.src));
114
114
  const TransformComponentNumber = (0, component_number_1.componentNumberFromName)('core::Transform');
115
115
  const CompositeRootComponent = (0, components_2.getCompositeRootComponent)(engine);
116
+ let hadNestedComposite = false;
116
117
  // Key => EntityNumber from the composite
117
118
  // Value => EntityNumber in current engine
118
119
  const mappedEntities = new Map();
@@ -128,23 +129,29 @@ function instanceComposite(engine, compositeResource, compositeProvider, options
128
129
  // If there are more composite inside this one, we instance first.
129
130
  // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
130
131
  // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
131
- const childrenComposite = compositeResource.composite.components.find((item) => item.name === CompositeRootComponent.componentName);
132
- if (childrenComposite) {
133
- for (const [childCompositeEntity, compositeRawData] of childrenComposite.data) {
134
- const childComposite = getComponentValue(CompositeRootComponent, compositeRawData);
135
- const childCompositePath = path.resolveComposite(childComposite.src, compositeDirectoryPath);
136
- const childCompositeResource = compositeProvider.getCompositeOrNull(childCompositePath);
137
- const targetEntity = getCompositeEntity(childCompositeEntity);
138
- if (childCompositeResource) {
139
- if (alreadyRequestedSrc.has(childCompositeResource.src) ||
140
- childCompositeResource.src === compositeResource.src) {
141
- throw new Error(`Composite ${compositeResource.src} has a recursive instanciation while try to instance ${childCompositeResource.src}. Previous instances: ${alreadyRequestedSrc.toString()}`);
132
+ if (CompositeRootComponent) {
133
+ const childrenComposite = compositeResource.composite.components.find((item) => item.name === CompositeRootComponent.componentName);
134
+ if (childrenComposite) {
135
+ for (const [childCompositeEntity, compositeRawData] of childrenComposite.data) {
136
+ const childComposite = getComponentValue(CompositeRootComponent, compositeRawData);
137
+ const childCompositePath = path.resolveComposite(childComposite.src, compositeDirectoryPath);
138
+ const childCompositeResource = compositeProvider.getCompositeOrNull(childCompositePath);
139
+ const targetEntity = getCompositeEntity(childCompositeEntity);
140
+ if (childCompositeResource) {
141
+ if (alreadyRequestedSrc.has(childCompositeResource.src) ||
142
+ childCompositeResource.src === compositeResource.src) {
143
+ throw new Error(`Composite ${compositeResource.src} has a recursive instanciation while try to instance ${childCompositeResource.src}. Previous instances: ${alreadyRequestedSrc.toString()}`);
144
+ }
145
+ hadNestedComposite = true;
146
+ instanceComposite(engine, childCompositeResource, compositeProvider, {
147
+ rootEntity: targetEntity,
148
+ alreadyRequestedSrc: new Set(alreadyRequestedSrc).add(childCompositeResource.src),
149
+ entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
150
+ });
151
+ }
152
+ else {
153
+ console.warn(`Composite "${compositeResource.src}" references missing nested composite "${childCompositePath}". Skipping; the spawned subtree will be incomplete.`);
142
154
  }
143
- instanceComposite(engine, childCompositeResource, compositeProvider, {
144
- rootEntity: targetEntity,
145
- alreadyRequestedSrc: new Set(alreadyRequestedSrc).add(childCompositeResource.src),
146
- entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
147
- });
148
155
  }
149
156
  }
150
157
  }
@@ -152,7 +159,7 @@ function instanceComposite(engine, compositeResource, compositeProvider, options
152
159
  // Then, we copy the all rest of the components (skipping the Composite ones)
153
160
  for (const component of compositeResource.composite.components) {
154
161
  // We already instanced the composite
155
- if (component.name === CompositeRootComponent.componentName)
162
+ if (CompositeRootComponent && component.name === CompositeRootComponent.componentName)
156
163
  continue;
157
164
  // ## 3a ##
158
165
  // We find the component definition
@@ -188,14 +195,16 @@ function instanceComposite(engine, compositeResource, compositeProvider, options
188
195
  }
189
196
  }
190
197
  }
191
- const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
192
- for (const [entitySource, targetEntity] of mappedEntities) {
193
- composite.entities.push({
194
- src: entitySource,
195
- dest: targetEntity
196
- });
198
+ if (hadNestedComposite) {
199
+ const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
200
+ for (const [entitySource, targetEntity] of mappedEntities) {
201
+ composite.entities.push({
202
+ src: entitySource,
203
+ dest: targetEntity
204
+ });
205
+ }
206
+ composite.src = compositeResource.src;
197
207
  }
198
- composite.src = compositeResource.src;
199
208
  return compositeRootEntity;
200
209
  }
201
210
  exports.instanceComposite = instanceComposite;
@@ -0,0 +1,15 @@
1
+ import type { IEngine } from '../engine';
2
+ import type { CompositeProvider } from './instance';
3
+ /**
4
+ * Register the composite provider used to resolve composite files. Also registers
5
+ * any `provider.schemas` on the engine pre-seal so composites that reference those
6
+ * components can be instanced without further setup.
7
+ * @public
8
+ */
9
+ export declare function setCompositeProvider(engine: IEngine, provider: CompositeProvider): void;
10
+ /**
11
+ * Get the composite provider registered via setCompositeProvider. Returns null if
12
+ * no provider has been set.
13
+ * @public
14
+ */
15
+ export declare function getCompositeProvider(): CompositeProvider | null;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompositeProvider = exports.setCompositeProvider = void 0;
4
+ const schemas_1 = require("../schemas");
5
+ const components_1 = require("./components");
6
+ let currentProvider = null;
7
+ /**
8
+ * Register the composite provider used to resolve composite files. Also registers
9
+ * any `provider.schemas` on the engine pre-seal so composites that reference those
10
+ * components can be instanced without further setup.
11
+ * @public
12
+ */
13
+ function setCompositeProvider(engine, provider) {
14
+ currentProvider = provider;
15
+ // Define composite::root pre-seal. setCompositeProvider runs at module-load,
16
+ // so this guarantees the component exists before the engine seals — composites
17
+ // instanced at runtime (post-seal) would otherwise trip the seal when
18
+ // instanceComposite looks it up via getCompositeRootComponent.
19
+ (0, components_1.getCompositeRootComponent)(engine);
20
+ if (!provider.schemas)
21
+ return;
22
+ for (const { name, jsonSchema } of provider.schemas) {
23
+ if (engine.getComponentOrNull(name))
24
+ continue;
25
+ engine.defineComponentFromSchema(name, schemas_1.Schemas.fromJson(jsonSchema));
26
+ }
27
+ }
28
+ exports.setCompositeProvider = setCompositeProvider;
29
+ /**
30
+ * Get the composite provider registered via setCompositeProvider. Returns null if
31
+ * no provider has been set.
32
+ * @public
33
+ */
34
+ function getCompositeProvider() {
35
+ return currentProvider;
36
+ }
37
+ exports.getCompositeProvider = getCompositeProvider;
@@ -265,7 +265,7 @@ function Engine(options) {
265
265
  const deletedEntites = partialEngine.entityContainer.releaseRemovedEntities();
266
266
  await crdtSystem.sendMessages(deletedEntites);
267
267
  }
268
- return {
268
+ const engineInstance = {
269
269
  _id: Date.now(),
270
270
  addEntity: partialEngine.addEntity,
271
271
  removeEntity: partialEngine.removeEntity,
@@ -293,5 +293,6 @@ function Engine(options) {
293
293
  addTransport: crdtSystem.addTransport,
294
294
  entityContainer: partialEngine.entityContainer
295
295
  };
296
+ return engineInstance;
296
297
  }
297
298
  exports.Engine = Engine;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.23.4-26770223094.commit-52b9415",
4
+ "version": "7.23.4-26955626649.commit-5d040fd",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/ecs/issues",
7
7
  "files": [
@@ -34,5 +34,5 @@
34
34
  "dependencies": {},
35
35
  "types": "./dist/index.d.ts",
36
36
  "typings": "./dist/index.d.ts",
37
- "commit": "52b9415ebab8c77313e9fbc0725fd2e5f916d3c3"
37
+ "commit": "5d040fd6fe9e018eb005a5c2a85e3419e1ea87a4"
38
38
  }