@dcl/ecs 7.1.2 → 7.1.3-4448471926.commit-264de76

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.
@@ -1,11 +1,51 @@
1
1
  import { componentDefinitionByName } from '../components';
2
2
  import { componentNumberFromName } from '../components/component-number';
3
3
  import { Schemas } from '../schemas';
4
+ import { ReadWriteByteBuffer } from '../serialization/ByteBuffer';
4
5
  import { getCompositeRootComponent } from './components';
6
+ /**
7
+ * Return the component value from composite data
8
+ * @internal
9
+ */
10
+ export function getComponentValue(componentDefinition, component) {
11
+ if (component.data?.$case === 'json') {
12
+ return component.data.json;
13
+ }
14
+ else {
15
+ return componentDefinition.schema.deserialize(new ReadWriteByteBuffer(component.data?.binary));
16
+ }
17
+ }
18
+ /**
19
+ * Return the component definition from composite info
20
+ * @internal
21
+ */
22
+ export function getComponentDefinition(engine, component) {
23
+ const existingComponentDefinition = engine.getComponentOrNull(component.name);
24
+ if (!existingComponentDefinition) {
25
+ if (component.jsonSchema) {
26
+ return engine.defineComponentFromSchema(component.name, Schemas.fromJson(component.jsonSchema));
27
+ }
28
+ else if (component.name.startsWith('core::')) {
29
+ if (component.name in componentDefinitionByName) {
30
+ return componentDefinitionByName[component.name](engine);
31
+ }
32
+ else {
33
+ throw new Error(`The core component ${component.name} was not found.`);
34
+ }
35
+ }
36
+ else {
37
+ throw new Error(`${component.name} is not defined and there is no schema to define it.`);
38
+ }
39
+ }
40
+ else {
41
+ return existingComponentDefinition;
42
+ }
43
+ }
5
44
  /**
6
45
  * Return the entity mapping or fail if there is no more
46
+ * @internal
7
47
  */
8
- function getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity) {
48
+ export function getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity) {
9
49
  const existingEntity = mappedEntities.get(compositeEntity);
10
50
  if (existingEntity) {
11
51
  return existingEntity;
@@ -50,7 +90,7 @@ export function instanceComposite(engine, compositeData, getNextAvailableEntity,
50
90
  const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
51
91
  if (childrenComposite) {
52
92
  for (const [entity, childComposite] of childrenComposite.data) {
53
- const compositeRoot = childComposite;
93
+ const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
54
94
  const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
55
95
  if (composite) {
56
96
  if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
@@ -68,32 +108,13 @@ export function instanceComposite(engine, compositeData, getNextAvailableEntity,
68
108
  continue;
69
109
  // ## 3a ##
70
110
  // We find the component definition
71
- let componentDefinition;
72
- const existingComponentDefinition = engine.getComponentOrNull(component.name);
73
- if (!existingComponentDefinition) {
74
- if (component.schema) {
75
- componentDefinition = engine.defineComponentFromSchema(component.name, Schemas.fromJson(component.schema));
76
- }
77
- else if (component.name.startsWith('core::')) {
78
- if (component.name in componentDefinitionByName) {
79
- componentDefinition = componentDefinitionByName[component.name](engine);
80
- }
81
- else {
82
- throw new Error(`The core component ${component.name} was not found.`);
83
- }
84
- }
85
- else {
86
- throw new Error(`${component.name} is not defined and there is no schema to define it.`);
87
- }
88
- }
89
- else {
90
- componentDefinition = existingComponentDefinition;
91
- }
111
+ const componentDefinition = getComponentDefinition(engine, component);
92
112
  // ## 3b ##
93
113
  // Iterating over all the entities with this component and create the replica
94
114
  for (const [entity, compositeComponentValue] of component.data) {
115
+ const componentValueDeserialized = getComponentValue(componentDefinition, compositeComponentValue);
95
116
  const targetEntity = getCompositeEntity(entity);
96
- const componentValue = componentDefinition.create(targetEntity, compositeComponentValue);
117
+ const componentValue = componentDefinition.create(targetEntity, componentValueDeserialized);
97
118
  // ## 3c ##
98
119
  // All entities referenced in the composite probably has a different resolved EntityNumber
99
120
  // We'll know with the mappedEntityes
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export interface ComponentData {
5
+ data?: {
6
+ $case: "json";
7
+ json: any | undefined;
8
+ } | {
9
+ $case: "binary";
10
+ binary: Uint8Array;
11
+ };
12
+ }
13
+ /**
14
+ * @public
15
+ */
16
+ export interface CompositeComponent {
17
+ name: string;
18
+ jsonSchema: any | undefined;
19
+ data: Map<number, ComponentData>;
20
+ }
21
+ /**
22
+ * @public
23
+ */
24
+ export interface CompositeComponent_DataEntry {
25
+ key: number;
26
+ value: ComponentData | undefined;
27
+ }
28
+ /**
29
+ * @public
30
+ */
31
+ export interface Composite {
32
+ id: string;
33
+ components: CompositeComponent[];
34
+ }
@@ -0,0 +1,290 @@
1
+ /* eslint-disable */
2
+ import _m0 from "protobufjs/minimal";
3
+ import { Value } from "./google/protobuf/struct.gen";
4
+ const protobufPackageSarasa = "";
5
+ function createBaseComponentData() {
6
+ return { data: undefined };
7
+ }
8
+ /**
9
+ * @public
10
+ */
11
+ /**
12
+ * @internal
13
+ */
14
+ export const ComponentData = {
15
+ encode(message, writer = _m0.Writer.create()) {
16
+ if (message.data?.$case === "json") {
17
+ Value.encode(Value.wrap(message.data.json), writer.uint32(10).fork()).ldelim();
18
+ }
19
+ if (message.data?.$case === "binary") {
20
+ writer.uint32(18).bytes(message.data.binary);
21
+ }
22
+ return writer;
23
+ },
24
+ decode(input, length) {
25
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
26
+ let end = length === undefined ? reader.len : reader.pos + length;
27
+ const message = createBaseComponentData();
28
+ while (reader.pos < end) {
29
+ const tag = reader.uint32();
30
+ switch (tag >>> 3) {
31
+ case 1:
32
+ message.data = { $case: "json", json: Value.unwrap(Value.decode(reader, reader.uint32())) };
33
+ break;
34
+ case 2:
35
+ message.data = { $case: "binary", binary: reader.bytes() };
36
+ break;
37
+ default:
38
+ reader.skipType(tag & 7);
39
+ break;
40
+ }
41
+ }
42
+ return message;
43
+ },
44
+ fromJSON(object) {
45
+ return {
46
+ data: isSet(object.json)
47
+ ? { $case: "json", json: object.json }
48
+ : isSet(object.binary)
49
+ ? { $case: "binary", binary: bytesFromBase64(object.binary) }
50
+ : undefined,
51
+ };
52
+ },
53
+ toJSON(message) {
54
+ const obj = {};
55
+ message.data?.$case === "json" && (obj.json = message.data?.json);
56
+ message.data?.$case === "binary" &&
57
+ (obj.binary = message.data?.binary !== undefined ? base64FromBytes(message.data?.binary) : undefined);
58
+ return obj;
59
+ },
60
+ };
61
+ function createBaseCompositeComponent() {
62
+ return { name: "", jsonSchema: undefined, data: new Map() };
63
+ }
64
+ /**
65
+ * @public
66
+ */
67
+ /**
68
+ * @internal
69
+ */
70
+ export const CompositeComponent = {
71
+ encode(message, writer = _m0.Writer.create()) {
72
+ if (message.name !== "") {
73
+ writer.uint32(10).string(message.name);
74
+ }
75
+ if (message.jsonSchema !== undefined) {
76
+ Value.encode(Value.wrap(message.jsonSchema), writer.uint32(18).fork()).ldelim();
77
+ }
78
+ message.data.forEach((value, key) => {
79
+ CompositeComponent_DataEntry.encode({ key: key, value }, writer.uint32(26).fork()).ldelim();
80
+ });
81
+ return writer;
82
+ },
83
+ decode(input, length) {
84
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
85
+ let end = length === undefined ? reader.len : reader.pos + length;
86
+ const message = createBaseCompositeComponent();
87
+ while (reader.pos < end) {
88
+ const tag = reader.uint32();
89
+ switch (tag >>> 3) {
90
+ case 1:
91
+ message.name = reader.string();
92
+ break;
93
+ case 2:
94
+ message.jsonSchema = Value.unwrap(Value.decode(reader, reader.uint32()));
95
+ break;
96
+ case 3:
97
+ const entry3 = CompositeComponent_DataEntry.decode(reader, reader.uint32());
98
+ if (entry3.value !== undefined) {
99
+ message.data.set(entry3.key, entry3.value);
100
+ }
101
+ break;
102
+ default:
103
+ reader.skipType(tag & 7);
104
+ break;
105
+ }
106
+ }
107
+ return message;
108
+ },
109
+ fromJSON(object) {
110
+ return {
111
+ name: isSet(object.name) ? String(object.name) : "",
112
+ jsonSchema: isSet(object?.jsonSchema) ? object.jsonSchema : undefined,
113
+ data: isObject(object.data)
114
+ ? Object.entries(object.data).reduce((acc, [key, value]) => {
115
+ acc.set(Number(key), ComponentData.fromJSON(value));
116
+ return acc;
117
+ }, new Map())
118
+ : new Map(),
119
+ };
120
+ },
121
+ toJSON(message) {
122
+ const obj = {};
123
+ message.name !== undefined && (obj.name = message.name);
124
+ message.jsonSchema !== undefined && (obj.jsonSchema = message.jsonSchema);
125
+ obj.data = {};
126
+ if (message.data) {
127
+ message.data.forEach((v, k) => {
128
+ obj.data[k] = ComponentData.toJSON(v);
129
+ });
130
+ }
131
+ return obj;
132
+ },
133
+ };
134
+ function createBaseCompositeComponent_DataEntry() {
135
+ return { key: 0, value: undefined };
136
+ }
137
+ /**
138
+ * @public
139
+ */
140
+ /**
141
+ * @internal
142
+ */
143
+ export const CompositeComponent_DataEntry = {
144
+ encode(message, writer = _m0.Writer.create()) {
145
+ if (message.key !== 0) {
146
+ writer.uint32(8).int32(message.key);
147
+ }
148
+ if (message.value !== undefined) {
149
+ ComponentData.encode(message.value, writer.uint32(18).fork()).ldelim();
150
+ }
151
+ return writer;
152
+ },
153
+ decode(input, length) {
154
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
155
+ let end = length === undefined ? reader.len : reader.pos + length;
156
+ const message = createBaseCompositeComponent_DataEntry();
157
+ while (reader.pos < end) {
158
+ const tag = reader.uint32();
159
+ switch (tag >>> 3) {
160
+ case 1:
161
+ message.key = reader.int32();
162
+ break;
163
+ case 2:
164
+ message.value = ComponentData.decode(reader, reader.uint32());
165
+ break;
166
+ default:
167
+ reader.skipType(tag & 7);
168
+ break;
169
+ }
170
+ }
171
+ return message;
172
+ },
173
+ fromJSON(object) {
174
+ return {
175
+ key: isSet(object.key) ? Number(object.key) : 0,
176
+ value: isSet(object.value) ? ComponentData.fromJSON(object.value) : undefined,
177
+ };
178
+ },
179
+ toJSON(message) {
180
+ const obj = {};
181
+ message.key !== undefined && (obj.key = Math.round(message.key));
182
+ message.value !== undefined && (obj.value = message.value ? ComponentData.toJSON(message.value) : undefined);
183
+ return obj;
184
+ },
185
+ };
186
+ function createBaseComposite() {
187
+ return { id: "", components: [] };
188
+ }
189
+ /**
190
+ * @public
191
+ */
192
+ /**
193
+ * @internal
194
+ */
195
+ export const Composite = {
196
+ encode(message, writer = _m0.Writer.create()) {
197
+ if (message.id !== "") {
198
+ writer.uint32(10).string(message.id);
199
+ }
200
+ for (const v of message.components) {
201
+ CompositeComponent.encode(v, writer.uint32(18).fork()).ldelim();
202
+ }
203
+ return writer;
204
+ },
205
+ decode(input, length) {
206
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
207
+ let end = length === undefined ? reader.len : reader.pos + length;
208
+ const message = createBaseComposite();
209
+ while (reader.pos < end) {
210
+ const tag = reader.uint32();
211
+ switch (tag >>> 3) {
212
+ case 1:
213
+ message.id = reader.string();
214
+ break;
215
+ case 2:
216
+ message.components.push(CompositeComponent.decode(reader, reader.uint32()));
217
+ break;
218
+ default:
219
+ reader.skipType(tag & 7);
220
+ break;
221
+ }
222
+ }
223
+ return message;
224
+ },
225
+ fromJSON(object) {
226
+ return {
227
+ id: isSet(object.id) ? String(object.id) : "",
228
+ components: Array.isArray(object?.components)
229
+ ? object.components.map((e) => CompositeComponent.fromJSON(e))
230
+ : [],
231
+ };
232
+ },
233
+ toJSON(message) {
234
+ const obj = {};
235
+ message.id !== undefined && (obj.id = message.id);
236
+ if (message.components) {
237
+ obj.components = message.components.map((e) => e ? CompositeComponent.toJSON(e) : undefined);
238
+ }
239
+ else {
240
+ obj.components = [];
241
+ }
242
+ return obj;
243
+ },
244
+ };
245
+ var tsProtoGlobalThis = (() => {
246
+ if (typeof globalThis !== "undefined") {
247
+ return globalThis;
248
+ }
249
+ if (typeof self !== "undefined") {
250
+ return self;
251
+ }
252
+ if (typeof window !== "undefined") {
253
+ return window;
254
+ }
255
+ if (typeof global !== "undefined") {
256
+ return global;
257
+ }
258
+ throw "Unable to locate global object";
259
+ })();
260
+ function bytesFromBase64(b64) {
261
+ if (tsProtoGlobalThis.Buffer) {
262
+ return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64"));
263
+ }
264
+ else {
265
+ const bin = tsProtoGlobalThis.atob(b64);
266
+ const arr = new Uint8Array(bin.length);
267
+ for (let i = 0; i < bin.length; ++i) {
268
+ arr[i] = bin.charCodeAt(i);
269
+ }
270
+ return arr;
271
+ }
272
+ }
273
+ function base64FromBytes(arr) {
274
+ if (tsProtoGlobalThis.Buffer) {
275
+ return tsProtoGlobalThis.Buffer.from(arr).toString("base64");
276
+ }
277
+ else {
278
+ const bin = [];
279
+ arr.forEach((byte) => {
280
+ bin.push(String.fromCharCode(byte));
281
+ });
282
+ return tsProtoGlobalThis.btoa(bin.join(""));
283
+ }
284
+ }
285
+ function isObject(value) {
286
+ return typeof value === "object" && value !== null;
287
+ }
288
+ function isSet(value) {
289
+ return value !== null && value !== undefined;
290
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * `NullValue` is a singleton enumeration to represent the null value for the
3
+ * `Value` type union.
4
+ *
5
+ * The JSON representation for `NullValue` is JSON `null`.
6
+ */
7
+ /**
8
+ * @public
9
+ */
10
+ export declare const enum NullValue {
11
+ /** NULL_VALUE - Null value. */
12
+ NULL_VALUE = 0
13
+ }
14
+ /**
15
+ * @public
16
+ */
17
+ export declare function nullValueFromJSON(object: any): NullValue;
18
+ /**
19
+ * @public
20
+ */
21
+ export declare function nullValueToJSON(object: NullValue): string;
22
+ /**
23
+ * `Struct` represents a structured data value, consisting of fields
24
+ * which map to dynamically typed values. In some languages, `Struct`
25
+ * might be supported by a native representation. For example, in
26
+ * scripting languages like JS a struct is represented as an
27
+ * object. The details of that representation are described together
28
+ * with the proto support for the language.
29
+ *
30
+ * The JSON representation for `Struct` is JSON object.
31
+ */
32
+ /**
33
+ * @public
34
+ */
35
+ export interface Struct {
36
+ /** Unordered map of dynamically typed values. */
37
+ fields: Map<string, any | undefined>;
38
+ }
39
+ /**
40
+ * @public
41
+ */
42
+ export interface Struct_FieldsEntry {
43
+ key: string;
44
+ value: any | undefined;
45
+ }
46
+ /**
47
+ * `Value` represents a dynamically typed value which can be either
48
+ * null, a number, a string, a boolean, a recursive struct value, or a
49
+ * list of values. A producer of value is expected to set one of these
50
+ * variants. Absence of any variant indicates an error.
51
+ *
52
+ * The JSON representation for `Value` is JSON value.
53
+ */
54
+ /**
55
+ * @public
56
+ */
57
+ export interface Value {
58
+ kind?: {
59
+ $case: "nullValue";
60
+ nullValue: NullValue;
61
+ } | {
62
+ $case: "numberValue";
63
+ numberValue: number;
64
+ } | {
65
+ $case: "stringValue";
66
+ stringValue: string;
67
+ } | {
68
+ $case: "boolValue";
69
+ boolValue: boolean;
70
+ } | {
71
+ $case: "structValue";
72
+ structValue: {
73
+ [key: string]: any;
74
+ } | undefined;
75
+ } | {
76
+ $case: "listValue";
77
+ listValue: Array<any> | undefined;
78
+ };
79
+ }
80
+ /**
81
+ * `ListValue` is a wrapper around a repeated field of values.
82
+ *
83
+ * The JSON representation for `ListValue` is JSON array.
84
+ */
85
+ /**
86
+ * @public
87
+ */
88
+ export interface ListValue {
89
+ /** Repeated field of dynamically typed values. */
90
+ values: any[];
91
+ }
@@ -0,0 +1,380 @@
1
+ /* eslint-disable */
2
+ import _m0 from "protobufjs/minimal";
3
+ const protobufPackageSarasa = "google.protobuf";
4
+ /**
5
+ * `NullValue` is a singleton enumeration to represent the null value for the
6
+ * `Value` type union.
7
+ *
8
+ * The JSON representation for `NullValue` is JSON `null`.
9
+ */
10
+ /**
11
+ * @public
12
+ */
13
+ export var NullValue;
14
+ (function (NullValue) {
15
+ /** NULL_VALUE - Null value. */
16
+ NullValue[NullValue["NULL_VALUE"] = 0] = "NULL_VALUE";
17
+ })(NullValue || (NullValue = {}));
18
+ /**
19
+ * @public
20
+ */
21
+ export function nullValueFromJSON(object) {
22
+ switch (object) {
23
+ case 0:
24
+ case "NULL_VALUE":
25
+ return 0 /* NullValue.NULL_VALUE */;
26
+ default:
27
+ throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum NullValue");
28
+ }
29
+ }
30
+ /**
31
+ * @public
32
+ */
33
+ export function nullValueToJSON(object) {
34
+ switch (object) {
35
+ case 0 /* NullValue.NULL_VALUE */:
36
+ return "NULL_VALUE";
37
+ default:
38
+ throw new tsProtoGlobalThis.Error("Unrecognized enum value " + object + " for enum NullValue");
39
+ }
40
+ }
41
+ function createBaseStruct() {
42
+ return { fields: new Map() };
43
+ }
44
+ /**
45
+ * @public
46
+ */
47
+ /**
48
+ * @internal
49
+ */
50
+ export const Struct = {
51
+ encode(message, writer = _m0.Writer.create()) {
52
+ message.fields.forEach((value, key) => {
53
+ if (value !== undefined) {
54
+ Struct_FieldsEntry.encode({ key: key, value }, writer.uint32(10).fork()).ldelim();
55
+ }
56
+ });
57
+ return writer;
58
+ },
59
+ decode(input, length) {
60
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
61
+ let end = length === undefined ? reader.len : reader.pos + length;
62
+ const message = createBaseStruct();
63
+ while (reader.pos < end) {
64
+ const tag = reader.uint32();
65
+ switch (tag >>> 3) {
66
+ case 1:
67
+ const entry1 = Struct_FieldsEntry.decode(reader, reader.uint32());
68
+ if (entry1.value !== undefined) {
69
+ message.fields.set(entry1.key, entry1.value);
70
+ }
71
+ break;
72
+ default:
73
+ reader.skipType(tag & 7);
74
+ break;
75
+ }
76
+ }
77
+ return message;
78
+ },
79
+ fromJSON(object) {
80
+ return {
81
+ fields: isObject(object.fields)
82
+ ? Object.entries(object.fields).reduce((acc, [key, value]) => {
83
+ acc.set(key, value);
84
+ return acc;
85
+ }, new Map())
86
+ : new Map(),
87
+ };
88
+ },
89
+ toJSON(message) {
90
+ const obj = {};
91
+ obj.fields = {};
92
+ if (message.fields) {
93
+ message.fields.forEach((v, k) => {
94
+ obj.fields[k] = v;
95
+ });
96
+ }
97
+ return obj;
98
+ },
99
+ wrap(object) {
100
+ const struct = createBaseStruct();
101
+ if (object !== undefined) {
102
+ Object.keys(object).forEach((key) => {
103
+ struct.fields.set(key, object[key]);
104
+ });
105
+ }
106
+ return struct;
107
+ },
108
+ unwrap(message) {
109
+ const object = {};
110
+ [...message.fields.keys()].forEach((key) => {
111
+ object[key] = message.fields.get(key);
112
+ });
113
+ return object;
114
+ },
115
+ };
116
+ function createBaseStruct_FieldsEntry() {
117
+ return { key: "", value: undefined };
118
+ }
119
+ /**
120
+ * @public
121
+ */
122
+ /**
123
+ * @internal
124
+ */
125
+ export const Struct_FieldsEntry = {
126
+ encode(message, writer = _m0.Writer.create()) {
127
+ if (message.key !== "") {
128
+ writer.uint32(10).string(message.key);
129
+ }
130
+ if (message.value !== undefined) {
131
+ Value.encode(Value.wrap(message.value), writer.uint32(18).fork()).ldelim();
132
+ }
133
+ return writer;
134
+ },
135
+ decode(input, length) {
136
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
137
+ let end = length === undefined ? reader.len : reader.pos + length;
138
+ const message = createBaseStruct_FieldsEntry();
139
+ while (reader.pos < end) {
140
+ const tag = reader.uint32();
141
+ switch (tag >>> 3) {
142
+ case 1:
143
+ message.key = reader.string();
144
+ break;
145
+ case 2:
146
+ message.value = Value.unwrap(Value.decode(reader, reader.uint32()));
147
+ break;
148
+ default:
149
+ reader.skipType(tag & 7);
150
+ break;
151
+ }
152
+ }
153
+ return message;
154
+ },
155
+ fromJSON(object) {
156
+ return { key: isSet(object.key) ? String(object.key) : "", value: isSet(object?.value) ? object.value : undefined };
157
+ },
158
+ toJSON(message) {
159
+ const obj = {};
160
+ message.key !== undefined && (obj.key = message.key);
161
+ message.value !== undefined && (obj.value = message.value);
162
+ return obj;
163
+ },
164
+ };
165
+ function createBaseValue() {
166
+ return { kind: undefined };
167
+ }
168
+ /**
169
+ * @public
170
+ */
171
+ /**
172
+ * @internal
173
+ */
174
+ export const Value = {
175
+ encode(message, writer = _m0.Writer.create()) {
176
+ if (message.kind?.$case === "nullValue") {
177
+ writer.uint32(8).int32(message.kind.nullValue);
178
+ }
179
+ if (message.kind?.$case === "numberValue") {
180
+ writer.uint32(17).double(message.kind.numberValue);
181
+ }
182
+ if (message.kind?.$case === "stringValue") {
183
+ writer.uint32(26).string(message.kind.stringValue);
184
+ }
185
+ if (message.kind?.$case === "boolValue") {
186
+ writer.uint32(32).bool(message.kind.boolValue);
187
+ }
188
+ if (message.kind?.$case === "structValue") {
189
+ Struct.encode(Struct.wrap(message.kind.structValue), writer.uint32(42).fork()).ldelim();
190
+ }
191
+ if (message.kind?.$case === "listValue") {
192
+ ListValue.encode(ListValue.wrap(message.kind.listValue), writer.uint32(50).fork()).ldelim();
193
+ }
194
+ return writer;
195
+ },
196
+ decode(input, length) {
197
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
198
+ let end = length === undefined ? reader.len : reader.pos + length;
199
+ const message = createBaseValue();
200
+ while (reader.pos < end) {
201
+ const tag = reader.uint32();
202
+ switch (tag >>> 3) {
203
+ case 1:
204
+ message.kind = { $case: "nullValue", nullValue: reader.int32() };
205
+ break;
206
+ case 2:
207
+ message.kind = { $case: "numberValue", numberValue: reader.double() };
208
+ break;
209
+ case 3:
210
+ message.kind = { $case: "stringValue", stringValue: reader.string() };
211
+ break;
212
+ case 4:
213
+ message.kind = { $case: "boolValue", boolValue: reader.bool() };
214
+ break;
215
+ case 5:
216
+ message.kind = { $case: "structValue", structValue: Struct.unwrap(Struct.decode(reader, reader.uint32())) };
217
+ break;
218
+ case 6:
219
+ message.kind = { $case: "listValue", listValue: ListValue.unwrap(ListValue.decode(reader, reader.uint32())) };
220
+ break;
221
+ default:
222
+ reader.skipType(tag & 7);
223
+ break;
224
+ }
225
+ }
226
+ return message;
227
+ },
228
+ fromJSON(object) {
229
+ return {
230
+ kind: isSet(object.nullValue)
231
+ ? { $case: "nullValue", nullValue: nullValueFromJSON(object.nullValue) }
232
+ : isSet(object.numberValue)
233
+ ? { $case: "numberValue", numberValue: Number(object.numberValue) }
234
+ : isSet(object.stringValue)
235
+ ? { $case: "stringValue", stringValue: String(object.stringValue) }
236
+ : isSet(object.boolValue)
237
+ ? { $case: "boolValue", boolValue: Boolean(object.boolValue) }
238
+ : isSet(object.structValue)
239
+ ? { $case: "structValue", structValue: object.structValue }
240
+ : isSet(object.listValue)
241
+ ? { $case: "listValue", listValue: [...object.listValue] }
242
+ : undefined,
243
+ };
244
+ },
245
+ toJSON(message) {
246
+ const obj = {};
247
+ message.kind?.$case === "nullValue" &&
248
+ (obj.nullValue = message.kind?.nullValue !== undefined ? nullValueToJSON(message.kind?.nullValue) : undefined);
249
+ message.kind?.$case === "numberValue" && (obj.numberValue = message.kind?.numberValue);
250
+ message.kind?.$case === "stringValue" && (obj.stringValue = message.kind?.stringValue);
251
+ message.kind?.$case === "boolValue" && (obj.boolValue = message.kind?.boolValue);
252
+ message.kind?.$case === "structValue" && (obj.structValue = message.kind?.structValue);
253
+ message.kind?.$case === "listValue" && (obj.listValue = message.kind?.listValue);
254
+ return obj;
255
+ },
256
+ wrap(value) {
257
+ const result = createBaseValue();
258
+ if (value === null) {
259
+ result.kind = { $case: "nullValue", nullValue: 0 /* NullValue.NULL_VALUE */ };
260
+ }
261
+ else if (typeof value === "boolean") {
262
+ result.kind = { $case: "boolValue", boolValue: value };
263
+ }
264
+ else if (typeof value === "number") {
265
+ result.kind = { $case: "numberValue", numberValue: value };
266
+ }
267
+ else if (typeof value === "string") {
268
+ result.kind = { $case: "stringValue", stringValue: value };
269
+ }
270
+ else if (Array.isArray(value)) {
271
+ result.kind = { $case: "listValue", listValue: value };
272
+ }
273
+ else if (typeof value === "object") {
274
+ result.kind = { $case: "structValue", structValue: value };
275
+ }
276
+ else if (typeof value !== "undefined") {
277
+ throw new Error("Unsupported any value type: " + typeof value);
278
+ }
279
+ return result;
280
+ },
281
+ unwrap(message) {
282
+ if (message.kind?.$case === "nullValue") {
283
+ return null;
284
+ }
285
+ else if (message.kind?.$case === "numberValue") {
286
+ return message.kind?.numberValue;
287
+ }
288
+ else if (message.kind?.$case === "stringValue") {
289
+ return message.kind?.stringValue;
290
+ }
291
+ else if (message.kind?.$case === "boolValue") {
292
+ return message.kind?.boolValue;
293
+ }
294
+ else if (message.kind?.$case === "structValue") {
295
+ return message.kind?.structValue;
296
+ }
297
+ else if (message.kind?.$case === "listValue") {
298
+ return message.kind?.listValue;
299
+ }
300
+ else {
301
+ return undefined;
302
+ }
303
+ },
304
+ };
305
+ function createBaseListValue() {
306
+ return { values: [] };
307
+ }
308
+ /**
309
+ * @public
310
+ */
311
+ /**
312
+ * @internal
313
+ */
314
+ export const ListValue = {
315
+ encode(message, writer = _m0.Writer.create()) {
316
+ for (const v of message.values) {
317
+ Value.encode(Value.wrap(v), writer.uint32(10).fork()).ldelim();
318
+ }
319
+ return writer;
320
+ },
321
+ decode(input, length) {
322
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
323
+ let end = length === undefined ? reader.len : reader.pos + length;
324
+ const message = createBaseListValue();
325
+ while (reader.pos < end) {
326
+ const tag = reader.uint32();
327
+ switch (tag >>> 3) {
328
+ case 1:
329
+ message.values.push(Value.unwrap(Value.decode(reader, reader.uint32())));
330
+ break;
331
+ default:
332
+ reader.skipType(tag & 7);
333
+ break;
334
+ }
335
+ }
336
+ return message;
337
+ },
338
+ fromJSON(object) {
339
+ return { values: Array.isArray(object?.values) ? [...object.values] : [] };
340
+ },
341
+ toJSON(message) {
342
+ const obj = {};
343
+ if (message.values) {
344
+ obj.values = message.values.map((e) => e);
345
+ }
346
+ else {
347
+ obj.values = [];
348
+ }
349
+ return obj;
350
+ },
351
+ wrap(value) {
352
+ const result = createBaseListValue();
353
+ result.values = value ?? [];
354
+ return result;
355
+ },
356
+ unwrap(message) {
357
+ return message.values;
358
+ },
359
+ };
360
+ var tsProtoGlobalThis = (() => {
361
+ if (typeof globalThis !== "undefined") {
362
+ return globalThis;
363
+ }
364
+ if (typeof self !== "undefined") {
365
+ return self;
366
+ }
367
+ if (typeof window !== "undefined") {
368
+ return window;
369
+ }
370
+ if (typeof global !== "undefined") {
371
+ return global;
372
+ }
373
+ throw "Unable to locate global object";
374
+ })();
375
+ function isObject(value) {
376
+ return typeof value === "object" && value !== null;
377
+ }
378
+ function isSet(value) {
379
+ return value !== null && value !== undefined;
380
+ }
@@ -1,6 +1,3 @@
1
- import { Composite } from './types';
2
- /**
3
- * @public
4
- * @deprecated composite is not being supported so far, please do not use this feature
5
- */
6
- export declare function compositeFromJson(jsonComposite: any): Composite;
1
+ import { Composite } from './proto/gen/composite.gen';
2
+ export declare function compositeFromJson(object: any): Composite;
3
+ export declare function compositeFromBinary(buffer: Uint8Array): Composite;
@@ -1,36 +1,9 @@
1
- /**
2
- * @public
3
- * @deprecated composite is not being supported so far, please do not use this feature
4
- */
5
- export function compositeFromJson(jsonComposite) {
6
- if (!jsonComposite)
7
- throw new Error('Composite is not well defined');
8
- if (!jsonComposite.id || typeof jsonComposite.id !== 'string')
9
- throw new Error("Composite doesn't have a valid `id` field");
10
- const compositeId = jsonComposite.id;
11
- // TODO: Should be there a .version to identify the schema version?
12
- if (!Array.isArray(jsonComposite.components))
13
- throw new Error(`Composite '${compositeId}' fields 'components' is not an array`);
14
- const composite = {
15
- id: compositeId,
16
- components: []
17
- };
18
- for (const component of jsonComposite.components) {
19
- if (!component.name || typeof component.name !== 'string')
20
- throw new Error(`Composite '${compositeId}': The component doesn't have a valid name`);
21
- const componentName = component.name;
22
- const componentData = new Map();
23
- if (typeof component.data !== 'object' || Array.isArray(component.data))
24
- throw new Error(`Composite '${compositeId}': Invalid data in component '${component.name}'`);
25
- for (const [entityStr, data] of Object.entries(component.data)) {
26
- const entity = parseInt(entityStr);
27
- componentData.set(entity, data);
28
- }
29
- composite.components.push({
30
- name: componentName,
31
- data: componentData,
32
- schema: component.schema
33
- });
34
- }
35
- return composite;
1
+ import { Composite } from './proto/gen/composite.gen';
2
+ /* @public @deprecated */
3
+ export function compositeFromJson(object) {
4
+ return Composite.fromJSON(object);
5
+ }
6
+ /* @public @deprecated */
7
+ export function compositeFromBinary(buffer) {
8
+ return Composite.decode(buffer);
36
9
  }
@@ -1,17 +1,7 @@
1
- import { Entity } from '../engine/entity';
2
- import { JsonSchemaExtended } from '../schemas/ISchema';
3
- /**
4
- * @public
5
- * @deprecated composite is not being supported so far, please do not use this feature
6
- */
7
- export type Composite = {
8
- id: string;
9
- components: {
10
- name: string;
11
- schema?: JsonSchemaExtended;
12
- data: Map<Entity, unknown>;
13
- }[];
14
- };
1
+ import type { ComponentData, CompositeComponent, CompositeComponent_DataEntry } from './proto/gen/composite.gen';
2
+ import { Composite } from './proto/gen/composite.gen';
3
+ export type { ComponentData, CompositeComponent, CompositeComponent_DataEntry };
4
+ export { Composite };
15
5
  /**
16
6
  * @public
17
7
  * @deprecated composite is not being supported so far, please do not use this feature
@@ -1 +1,2 @@
1
- export {};
1
+ import { Composite } from './proto/gen/composite.gen';
2
+ export { Composite };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/ecs",
3
- "version": "7.1.2",
3
+ "version": "7.1.3-4448471926.commit-264de76",
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.2",
30
+ "@dcl/js-runtime": "7.1.3-4448471926.commit-264de76",
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": "4c363ec1e57406326ff3b3d27941d63b44e7d2e2"
43
+ "commit": "264de7682c191f5abc8dbe754ea1b7e5fac96c4c"
44
44
  }