@dcl/ecs 7.23.4-26723618219.commit-ea97433 → 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.
- package/dist/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.d.ts +8 -0
- package/dist/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.js +10 -1
- package/dist/composite/index.d.ts +8 -5
- package/dist/composite/index.js +8 -5
- package/dist/composite/instance.d.ts +5 -0
- package/dist/composite/instance.js +34 -25
- package/dist/composite/provider-registry.d.ts +15 -0
- package/dist/composite/provider-registry.js +32 -0
- package/dist/engine/index.js +2 -1
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.d.ts +8 -0
- package/dist-cjs/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.js +10 -1
- package/dist-cjs/composite/index.d.ts +8 -5
- package/dist-cjs/composite/index.js +11 -6
- package/dist-cjs/composite/instance.d.ts +5 -0
- package/dist-cjs/composite/instance.js +34 -25
- package/dist-cjs/composite/provider-registry.d.ts +15 -0
- package/dist-cjs/composite/provider-registry.js +37 -0
- package/dist-cjs/engine/index.js +2 -1
- package/package.json +2 -2
package/dist/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export interface PBUiCanvasInformation {
|
|
|
19
19
|
* on the contrary, if the chat UI is shown, the rect would be smaller.
|
|
20
20
|
*/
|
|
21
21
|
interactableArea: BorderRect | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* informs the sdk about the screen inset area (safe margins). these are the
|
|
24
|
+
* insets from each edge of the screen that are reserved by the device or
|
|
25
|
+
* platform UI (for example: the notch, status bar, home indicator, or rounded
|
|
26
|
+
* corners on mobile). scenes should avoid placing critical UI within these
|
|
27
|
+
* insets to ensure it is not occluded. on desktop this is typically (0, 0, 0, 0).
|
|
28
|
+
*/
|
|
29
|
+
screenInsetArea?: BorderRect | undefined;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* @public
|
package/dist/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.js
CHANGED
|
@@ -3,7 +3,7 @@ import _m0 from "protobufjs/minimal";
|
|
|
3
3
|
import { BorderRect } from "../../common/border_rect.gen";
|
|
4
4
|
const protobufPackageSarasa = "decentraland.sdk.components";
|
|
5
5
|
function createBasePBUiCanvasInformation() {
|
|
6
|
-
return { devicePixelRatio: 0, width: 0, height: 0, interactableArea: undefined };
|
|
6
|
+
return { devicePixelRatio: 0, width: 0, height: 0, interactableArea: undefined, screenInsetArea: undefined };
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* @public
|
|
@@ -23,6 +23,9 @@ export var PBUiCanvasInformation;
|
|
|
23
23
|
if (message.interactableArea !== undefined) {
|
|
24
24
|
BorderRect.encode(message.interactableArea, writer.uint32(34).fork()).ldelim();
|
|
25
25
|
}
|
|
26
|
+
if (message.screenInsetArea !== undefined) {
|
|
27
|
+
BorderRect.encode(message.screenInsetArea, writer.uint32(42).fork()).ldelim();
|
|
28
|
+
}
|
|
26
29
|
return writer;
|
|
27
30
|
}
|
|
28
31
|
PBUiCanvasInformation.encode = encode;
|
|
@@ -57,6 +60,12 @@ export var PBUiCanvasInformation;
|
|
|
57
60
|
}
|
|
58
61
|
message.interactableArea = BorderRect.decode(reader, reader.uint32());
|
|
59
62
|
continue;
|
|
63
|
+
case 5:
|
|
64
|
+
if (tag !== 42) {
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
message.screenInsetArea = BorderRect.decode(reader, reader.uint32());
|
|
68
|
+
continue;
|
|
60
69
|
}
|
|
61
70
|
if ((tag & 7) === 4 || tag === 0) {
|
|
62
71
|
break;
|
|
@@ -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
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
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):
|
|
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
|
package/dist/composite/index.js
CHANGED
|
@@ -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
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
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(
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
childCompositeResource.src
|
|
112
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
}
|
package/dist/engine/index.js
CHANGED
|
@@ -236,7 +236,7 @@ export function Engine(options) {
|
|
|
236
236
|
const deletedEntites = partialEngine.entityContainer.releaseRemovedEntities();
|
|
237
237
|
await crdtSystem.sendMessages(deletedEntites);
|
|
238
238
|
}
|
|
239
|
-
|
|
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
|
}
|
package/dist-cjs/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.d.ts
CHANGED
|
@@ -19,6 +19,14 @@ export interface PBUiCanvasInformation {
|
|
|
19
19
|
* on the contrary, if the chat UI is shown, the rect would be smaller.
|
|
20
20
|
*/
|
|
21
21
|
interactableArea: BorderRect | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* informs the sdk about the screen inset area (safe margins). these are the
|
|
24
|
+
* insets from each edge of the screen that are reserved by the device or
|
|
25
|
+
* platform UI (for example: the notch, status bar, home indicator, or rounded
|
|
26
|
+
* corners on mobile). scenes should avoid placing critical UI within these
|
|
27
|
+
* insets to ensure it is not occluded. on desktop this is typically (0, 0, 0, 0).
|
|
28
|
+
*/
|
|
29
|
+
screenInsetArea?: BorderRect | undefined;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* @public
|
package/dist-cjs/components/generated/pb/decentraland/sdk/components/ui_canvas_information.gen.js
CHANGED
|
@@ -9,7 +9,7 @@ const minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
|
9
9
|
const border_rect_gen_1 = require("../../common/border_rect.gen");
|
|
10
10
|
const protobufPackageSarasa = "decentraland.sdk.components";
|
|
11
11
|
function createBasePBUiCanvasInformation() {
|
|
12
|
-
return { devicePixelRatio: 0, width: 0, height: 0, interactableArea: undefined };
|
|
12
|
+
return { devicePixelRatio: 0, width: 0, height: 0, interactableArea: undefined, screenInsetArea: undefined };
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
@@ -29,6 +29,9 @@ var PBUiCanvasInformation;
|
|
|
29
29
|
if (message.interactableArea !== undefined) {
|
|
30
30
|
border_rect_gen_1.BorderRect.encode(message.interactableArea, writer.uint32(34).fork()).ldelim();
|
|
31
31
|
}
|
|
32
|
+
if (message.screenInsetArea !== undefined) {
|
|
33
|
+
border_rect_gen_1.BorderRect.encode(message.screenInsetArea, writer.uint32(42).fork()).ldelim();
|
|
34
|
+
}
|
|
32
35
|
return writer;
|
|
33
36
|
}
|
|
34
37
|
PBUiCanvasInformation.encode = encode;
|
|
@@ -63,6 +66,12 @@ var PBUiCanvasInformation;
|
|
|
63
66
|
}
|
|
64
67
|
message.interactableArea = border_rect_gen_1.BorderRect.decode(reader, reader.uint32());
|
|
65
68
|
continue;
|
|
69
|
+
case 5:
|
|
70
|
+
if (tag !== 42) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
message.screenInsetArea = border_rect_gen_1.BorderRect.decode(reader, reader.uint32());
|
|
74
|
+
continue;
|
|
66
75
|
}
|
|
67
76
|
if ((tag & 7) === 4 || tag === 0) {
|
|
68
77
|
break;
|
|
@@ -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
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
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):
|
|
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
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
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(
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
childCompositeResource.src
|
|
141
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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;
|
package/dist-cjs/engine/index.js
CHANGED
|
@@ -265,7 +265,7 @@ function Engine(options) {
|
|
|
265
265
|
const deletedEntites = partialEngine.entityContainer.releaseRemovedEntities();
|
|
266
266
|
await crdtSystem.sendMessages(deletedEntites);
|
|
267
267
|
}
|
|
268
|
-
|
|
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-
|
|
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": "
|
|
37
|
+
"commit": "5d040fd6fe9e018eb005a5c2a85e3419e1ea87a4"
|
|
38
38
|
}
|