@dcl/ecs 7.1.4-4671625513.commit-bfff9b1 → 7.1.4-4673364598.commit-30c5e9b
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/instance.js +11 -1
- package/dist/engine/component.d.ts +7 -0
- package/dist/engine/lww-element-set-component-definition.js +10 -0
- package/dist/schemas/buildSchema.d.ts +4 -0
- package/dist/schemas/buildSchema.js +34 -0
- package/dist/schemas/index.d.ts +17 -0
- package/dist/schemas/index.js +15 -1
- package/package.json +3 -3
|
@@ -142,10 +142,20 @@ export function instanceComposite(engine, compositeResource, compositeProvider,
|
|
|
142
142
|
if (transform.parent) {
|
|
143
143
|
transform.parent = getCompositeEntity(transform.parent);
|
|
144
144
|
}
|
|
145
|
+
else {
|
|
146
|
+
transform.parent = getCompositeEntity(0);
|
|
147
|
+
}
|
|
145
148
|
// TODO: is it going to be necessary to remap assets? e.g. src param from AudioSource and GltfContainer
|
|
146
149
|
}
|
|
147
150
|
else {
|
|
148
|
-
|
|
151
|
+
Schemas.mutateNestedValues(componentDefinition.schema.jsonSchema, componentValue, (value, valueType) => {
|
|
152
|
+
if (valueType.serializationType === 'entity') {
|
|
153
|
+
return { changed: true, value: getCompositeEntity(value) };
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return { changed: false };
|
|
157
|
+
}
|
|
158
|
+
});
|
|
149
159
|
}
|
|
150
160
|
}
|
|
151
161
|
}
|
|
@@ -115,6 +115,13 @@ export interface LastWriteWinElementSetComponentDefinition<T> extends BaseCompon
|
|
|
115
115
|
* @param entity - Entity to get the component from
|
|
116
116
|
*/
|
|
117
117
|
getMutableOrNull(entity: Entity): T | null;
|
|
118
|
+
/**
|
|
119
|
+
* Get the mutable component of the entity. If the entity doesn't have the component, it's created.
|
|
120
|
+
* - Internal comment: This method adds the <entity,component> to the list to be reviewed next frame
|
|
121
|
+
* @param entity - Entity to get the component from
|
|
122
|
+
* @param val - The initial value if it doesn't exist
|
|
123
|
+
*/
|
|
124
|
+
getOrCreateMutable(entity: Entity, initialValue?: T): T;
|
|
118
125
|
}
|
|
119
126
|
/**
|
|
120
127
|
* @public
|
|
@@ -222,6 +222,16 @@ export function createComponentDefinitionFromSchema(componentName, componentId,
|
|
|
222
222
|
dirtyIterator.add(entity);
|
|
223
223
|
return component;
|
|
224
224
|
},
|
|
225
|
+
getOrCreateMutable(entity, value) {
|
|
226
|
+
const component = data.get(entity);
|
|
227
|
+
if (!component) {
|
|
228
|
+
return this.create(entity, value);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
dirtyIterator.add(entity);
|
|
232
|
+
return component;
|
|
233
|
+
}
|
|
234
|
+
},
|
|
225
235
|
getMutable(entity) {
|
|
226
236
|
const component = this.getMutableOrNull(entity);
|
|
227
237
|
if (component === null) {
|
|
@@ -5,3 +5,7 @@ import { ISchema, JsonSchemaExtended } from './ISchema';
|
|
|
5
5
|
* @returns a ISchema or fail for unsupported json-schema
|
|
6
6
|
*/
|
|
7
7
|
export declare function jsonSchemaToSchema(jsonSchema: JsonSchemaExtended): ISchema<any>;
|
|
8
|
+
export declare function mutateValues(jsonSchema: JsonSchemaExtended, value: unknown, mutateFn: (value: unknown, valueType: JsonSchemaExtended) => {
|
|
9
|
+
changed: boolean;
|
|
10
|
+
value?: any;
|
|
11
|
+
}): void;
|
|
@@ -61,3 +61,37 @@ export function jsonSchemaToSchema(jsonSchema) {
|
|
|
61
61
|
}
|
|
62
62
|
throw new Error(`${jsonSchema.serializationType} is not supported as reverse schema generation.`);
|
|
63
63
|
}
|
|
64
|
+
export function mutateValues(jsonSchema, value, mutateFn) {
|
|
65
|
+
if (jsonSchema.serializationType === 'map') {
|
|
66
|
+
const mapJsonSchema = jsonSchema;
|
|
67
|
+
const mapValue = value;
|
|
68
|
+
for (const key in mapJsonSchema.properties) {
|
|
69
|
+
const valueType = mapJsonSchema.properties[key];
|
|
70
|
+
if (valueType.serializationType === 'array' || valueType.serializationType === 'map') {
|
|
71
|
+
mutateValues(mapJsonSchema.properties[key], mapValue[key], mutateFn);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const newValue = mutateFn(mapValue[key], valueType);
|
|
75
|
+
if (newValue.changed) {
|
|
76
|
+
mapValue[key] = newValue.value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (jsonSchema.serializationType === 'array') {
|
|
82
|
+
const withItemsJsonSchema = jsonSchema;
|
|
83
|
+
const arrayValue = value;
|
|
84
|
+
const nestedMutateValues = withItemsJsonSchema.items.serializationType === 'array' || withItemsJsonSchema.items.serializationType === 'map';
|
|
85
|
+
for (let i = 0, n = arrayValue.length; i < n; i++) {
|
|
86
|
+
if (nestedMutateValues) {
|
|
87
|
+
mutateValues(withItemsJsonSchema.items, arrayValue[i], mutateFn);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const newValue = mutateFn(arrayValue[i], withItemsJsonSchema.items);
|
|
91
|
+
if (newValue.changed) {
|
|
92
|
+
arrayValue[i] = newValue.value;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -55,4 +55,21 @@ export declare namespace Schemas {
|
|
|
55
55
|
* @returns a ISchema or fail for unsupported json-schema
|
|
56
56
|
*/
|
|
57
57
|
const fromJson: (json: JsonSchemaExtended) => ISchema<unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*
|
|
61
|
+
* Traverses and mutates values in a JSON schema-based structure, applying the given mutation function to each value.
|
|
62
|
+
* The function is designed to work with nested maps and arrays, recursively processing each element.
|
|
63
|
+
*
|
|
64
|
+
* @param jsonSchema - The JSON schema object that describes the structure of the value.
|
|
65
|
+
* It must have a serializationType of 'map', 'array', or other custom types like 'entity'.
|
|
66
|
+
* @param value - The value to be mutated, which should conform to the provided JSON schema.
|
|
67
|
+
* @param mutateFn - A function that takes a value and its corresponding valueType (JsonSchemaExtended) as arguments
|
|
68
|
+
* and returns a tuple [boolean, any]. The boolean indicates whether the mutation should be applied,
|
|
69
|
+
* and the second element is the mutated value.
|
|
70
|
+
*/
|
|
71
|
+
const mutateNestedValues: (jsonSchema: JsonSchemaExtended, value: unknown, mutateFn: (value: unknown, valueType: JsonSchemaExtended) => {
|
|
72
|
+
changed: boolean;
|
|
73
|
+
value?: any;
|
|
74
|
+
}) => void;
|
|
58
75
|
}
|
package/dist/schemas/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { QuaternionSchema } from './custom/Quaternion';
|
|
|
11
11
|
import { Vector3Schema } from './custom/Vector3';
|
|
12
12
|
import { IMap } from './Map';
|
|
13
13
|
import { IOptional } from './Optional';
|
|
14
|
-
import { jsonSchemaToSchema } from './buildSchema';
|
|
14
|
+
import { jsonSchemaToSchema, mutateValues } from './buildSchema';
|
|
15
15
|
/**
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
@@ -61,4 +61,18 @@ export var Schemas;
|
|
|
61
61
|
* @returns a ISchema or fail for unsupported json-schema
|
|
62
62
|
*/
|
|
63
63
|
Schemas.fromJson = jsonSchemaToSchema;
|
|
64
|
+
/**
|
|
65
|
+
* @public
|
|
66
|
+
*
|
|
67
|
+
* Traverses and mutates values in a JSON schema-based structure, applying the given mutation function to each value.
|
|
68
|
+
* The function is designed to work with nested maps and arrays, recursively processing each element.
|
|
69
|
+
*
|
|
70
|
+
* @param jsonSchema - The JSON schema object that describes the structure of the value.
|
|
71
|
+
* It must have a serializationType of 'map', 'array', or other custom types like 'entity'.
|
|
72
|
+
* @param value - The value to be mutated, which should conform to the provided JSON schema.
|
|
73
|
+
* @param mutateFn - A function that takes a value and its corresponding valueType (JsonSchemaExtended) as arguments
|
|
74
|
+
* and returns a tuple [boolean, any]. The boolean indicates whether the mutation should be applied,
|
|
75
|
+
* and the second element is the mutated value.
|
|
76
|
+
*/
|
|
77
|
+
Schemas.mutateNestedValues = mutateValues;
|
|
64
78
|
})(Schemas || (Schemas = {}));
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.1.4-
|
|
4
|
+
"version": "7.1.4-4673364598.commit-30c5e9b",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/ecs/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@dcl/js-runtime": "7.1.4-
|
|
8
|
+
"@dcl/js-runtime": "7.1.4-4673364598.commit-30c5e9b"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"ts-proto": "^1.122.0"
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
},
|
|
35
35
|
"types": "./dist/index.d.ts",
|
|
36
36
|
"typings": "./dist/index.d.ts",
|
|
37
|
-
"commit": "
|
|
37
|
+
"commit": "30c5e9bdb5d49948f522d764afee491a5f43576d"
|
|
38
38
|
}
|