@dcl/ecs 7.1.3-4479179155.commit-b0d720f → 7.1.3-4479720615.commit-2839aba
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/composite/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { Entity } from '../engine/entity';
|
|
2
2
|
import { IEngine } from '../engine/types';
|
|
3
3
|
import { Composite, CompositeProvider } from './types';
|
|
4
|
+
export declare enum EntityMappingMode {
|
|
5
|
+
EMM_NONE = 0,
|
|
6
|
+
EMM_NEXT_AVAILABLE = 1,
|
|
7
|
+
EMM_DIRECT_MAPPING = 2
|
|
8
|
+
}
|
|
9
|
+
export type InstanceCompositeOptions = {
|
|
10
|
+
entityMapping?: {
|
|
11
|
+
type: EntityMappingMode.EMM_NEXT_AVAILABLE;
|
|
12
|
+
getNextAvailableEntity: () => Entity | null;
|
|
13
|
+
} | {
|
|
14
|
+
type: EntityMappingMode.EMM_DIRECT_MAPPING;
|
|
15
|
+
getCompositeEntity: (compositeEntity: Entity | number) => Entity;
|
|
16
|
+
};
|
|
17
|
+
rootEntity?: Entity;
|
|
18
|
+
alreadyRequestedId?: Set<string>;
|
|
19
|
+
};
|
|
4
20
|
/**
|
|
5
21
|
* Instance a composite and returns its root entity
|
|
6
22
|
* @param compositeData state serialized by the CRDT protocol
|
|
@@ -11,4 +27,4 @@ import { Composite, CompositeProvider } from './types';
|
|
|
11
27
|
* @deprecated composite is not being supported so far, please do not use this feature
|
|
12
28
|
*
|
|
13
29
|
*/
|
|
14
|
-
export declare function instanceComposite(engine: IEngine, compositeData: Composite,
|
|
30
|
+
export declare function instanceComposite(engine: IEngine, compositeData: Composite, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): Entity;
|
|
@@ -3,6 +3,13 @@ import { componentNumberFromName } from '../components/component-number';
|
|
|
3
3
|
import { Schemas } from '../schemas';
|
|
4
4
|
import { ReadWriteByteBuffer } from '../serialization/ByteBuffer';
|
|
5
5
|
import { getCompositeRootComponent } from './components';
|
|
6
|
+
// @public
|
|
7
|
+
export var EntityMappingMode;
|
|
8
|
+
(function (EntityMappingMode) {
|
|
9
|
+
EntityMappingMode[EntityMappingMode["EMM_NONE"] = 0] = "EMM_NONE";
|
|
10
|
+
EntityMappingMode[EntityMappingMode["EMM_NEXT_AVAILABLE"] = 1] = "EMM_NEXT_AVAILABLE";
|
|
11
|
+
EntityMappingMode[EntityMappingMode["EMM_DIRECT_MAPPING"] = 2] = "EMM_DIRECT_MAPPING";
|
|
12
|
+
})(EntityMappingMode || (EntityMappingMode = {}));
|
|
6
13
|
/**
|
|
7
14
|
* Return the component value from composite data
|
|
8
15
|
* @internal
|
|
@@ -45,13 +52,20 @@ export function getComponentDefinition(engine, component) {
|
|
|
45
52
|
* Return the entity mapping or fail if there is no more
|
|
46
53
|
* @internal
|
|
47
54
|
*/
|
|
48
|
-
export function getEntityMapping(compositeEntity, mappedEntities,
|
|
55
|
+
export function getEntityMapping(engine, compositeEntity, mappedEntities, { entityMapping }) {
|
|
49
56
|
const existingEntity = mappedEntities.get(compositeEntity);
|
|
50
57
|
if (existingEntity) {
|
|
51
58
|
return existingEntity;
|
|
52
59
|
}
|
|
60
|
+
if (entityMapping?.type === EntityMappingMode.EMM_DIRECT_MAPPING) {
|
|
61
|
+
const entity = entityMapping.getCompositeEntity(compositeEntity);
|
|
62
|
+
mappedEntities.set(compositeEntity, entity);
|
|
63
|
+
return entity;
|
|
64
|
+
}
|
|
53
65
|
// This function in runtime can be just `engine.addEntity()`
|
|
54
|
-
const newEntity =
|
|
66
|
+
const newEntity = entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE
|
|
67
|
+
? entityMapping.getNextAvailableEntity()
|
|
68
|
+
: engine.addEntity();
|
|
55
69
|
if (newEntity === null) {
|
|
56
70
|
throw new Error('There is no more entities to allocate');
|
|
57
71
|
}
|
|
@@ -69,13 +83,15 @@ export function getEntityMapping(compositeEntity, mappedEntities, getNextAvailab
|
|
|
69
83
|
*
|
|
70
84
|
*/
|
|
71
85
|
/*#__PURE__*/
|
|
72
|
-
export function instanceComposite(engine, compositeData,
|
|
86
|
+
export function instanceComposite(engine, compositeData, compositeProvider, options = {}) {
|
|
87
|
+
const { rootEntity, alreadyRequestedId: optionalAlreadyRequestedId, entityMapping } = options;
|
|
88
|
+
const alreadyRequestedId = optionalAlreadyRequestedId || new Set();
|
|
73
89
|
const TransformComponentNumber = componentNumberFromName('core::Transform');
|
|
74
90
|
const CompositeRootComponent = getCompositeRootComponent(engine);
|
|
75
91
|
// Key => EntityNumber from the composite
|
|
76
92
|
// Value => EntityNumber in current engine
|
|
77
93
|
const mappedEntities = new Map();
|
|
78
|
-
const getCompositeEntity = (compositeEntity) => getEntityMapping(compositeEntity, mappedEntities,
|
|
94
|
+
const getCompositeEntity = (compositeEntity) => getEntityMapping(engine, compositeEntity, mappedEntities, options);
|
|
79
95
|
// ## 1 ##
|
|
80
96
|
// First entity that I want to map, the root entity from the composite to the target entity in the engine
|
|
81
97
|
// If there is no `rootEntity` passed, we assign one from `getNextAvailableEntity`
|
|
@@ -89,14 +105,19 @@ export function instanceComposite(engine, compositeData, getNextAvailableEntity,
|
|
|
89
105
|
// => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
|
|
90
106
|
const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
|
|
91
107
|
if (childrenComposite) {
|
|
92
|
-
for (const [
|
|
108
|
+
for (const [compositeEntity, childComposite] of childrenComposite.data) {
|
|
93
109
|
const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
|
|
94
110
|
const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
|
|
111
|
+
const targetEntity = getCompositeEntity(compositeEntity);
|
|
95
112
|
if (composite) {
|
|
96
113
|
if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
|
|
97
114
|
throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
|
|
98
115
|
}
|
|
99
|
-
instanceComposite(engine, composite,
|
|
116
|
+
instanceComposite(engine, composite, compositeProvider, {
|
|
117
|
+
rootEntity: targetEntity,
|
|
118
|
+
alreadyRequestedId: new Set(alreadyRequestedId).add(compositeData.id),
|
|
119
|
+
entityMapping: entityMapping?.type === EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
|
|
120
|
+
});
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
123
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
|
-
"version": "7.1.3-
|
|
3
|
+
"version": "7.1.3-4479720615.commit-2839aba",
|
|
4
4
|
"description": "Decentraland ECS",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"ts-proto": "^1.112.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@dcl/js-runtime": "7.1.3-
|
|
30
|
+
"@dcl/js-runtime": "7.1.3-4479720615.commit-2839aba",
|
|
31
31
|
"@dcl/protocol": "1.0.0-4408137944.commit-a67c796"
|
|
32
32
|
},
|
|
33
33
|
"files": [
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"displayName": "ECS",
|
|
41
41
|
"tsconfig": "./tsconfig.json"
|
|
42
42
|
},
|
|
43
|
-
"commit": "
|
|
43
|
+
"commit": "2839abac7c9c4f2006b23f770ecba166250c6365"
|
|
44
44
|
}
|