@dcl/playground-assets 7.1.4-4502579506.commit-4147243 → 7.1.4-4512634654.commit-0e8d9c4

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/index.js CHANGED
@@ -16330,6 +16330,172 @@
16330
16330
  Font[Font["F_MONOSPACE"] = 2] = "F_MONOSPACE";
16331
16331
  })(exports.Font || (exports.Font = {}));
16332
16332
 
16333
+ /**
16334
+ * @public
16335
+ * @deprecated composite is not being supported so far, please do not use this feature
16336
+ */
16337
+ function getCompositeRootComponent(engine) {
16338
+ const component = engine.getComponentOrNull('composite::root');
16339
+ if (component) {
16340
+ return component;
16341
+ }
16342
+ return engine.defineComponent('composite::root', {
16343
+ id: exports.Schemas.String,
16344
+ entities: exports.Schemas.Array(exports.Schemas.Map({
16345
+ src: exports.Schemas.Entity,
16346
+ dest: exports.Schemas.Entity
16347
+ }))
16348
+ });
16349
+ }
16350
+
16351
+ /** @public */
16352
+ exports.EntityMappingMode = void 0;
16353
+ (function (EntityMappingMode) {
16354
+ EntityMappingMode[EntityMappingMode["EMM_NONE"] = 0] = "EMM_NONE";
16355
+ EntityMappingMode[EntityMappingMode["EMM_NEXT_AVAILABLE"] = 1] = "EMM_NEXT_AVAILABLE";
16356
+ EntityMappingMode[EntityMappingMode["EMM_DIRECT_MAPPING"] = 2] = "EMM_DIRECT_MAPPING";
16357
+ })(exports.EntityMappingMode || (exports.EntityMappingMode = {}));
16358
+ /**
16359
+ * Return the component value from composite data
16360
+ * @internal
16361
+ */
16362
+ function getComponentValue(componentDefinition, component) {
16363
+ if (component.data?.$case === 'json') {
16364
+ return component.data.json;
16365
+ }
16366
+ else {
16367
+ return componentDefinition.schema.deserialize(new ReadWriteByteBuffer(component.data?.binary));
16368
+ }
16369
+ }
16370
+ /**
16371
+ * Return the component definition from composite info
16372
+ * @internal
16373
+ */
16374
+ function getComponentDefinition(engine, component) {
16375
+ const existingComponentDefinition = engine.getComponentOrNull(component.name);
16376
+ if (!existingComponentDefinition) {
16377
+ if (component.jsonSchema) {
16378
+ return engine.defineComponentFromSchema(component.name, exports.Schemas.fromJson(component.jsonSchema));
16379
+ }
16380
+ else if (component.name.startsWith('core::')) {
16381
+ if (component.name in componentDefinitionByName) {
16382
+ return componentDefinitionByName[component.name](engine);
16383
+ }
16384
+ else {
16385
+ throw new Error(`The core component ${component.name} was not found.`);
16386
+ }
16387
+ }
16388
+ else {
16389
+ throw new Error(`${component.name} is not defined and there is no schema to define it.`);
16390
+ }
16391
+ }
16392
+ else {
16393
+ return existingComponentDefinition;
16394
+ }
16395
+ }
16396
+ /**
16397
+ * Return the entity mapping or fail if there is no more
16398
+ * @internal
16399
+ */
16400
+ function getEntityMapping(engine, compositeEntity, mappedEntities, { entityMapping }) {
16401
+ const existingEntity = mappedEntities.get(compositeEntity);
16402
+ if (existingEntity) {
16403
+ return existingEntity;
16404
+ }
16405
+ if (entityMapping?.type === exports.EntityMappingMode.EMM_DIRECT_MAPPING) {
16406
+ const entity = entityMapping.getCompositeEntity(compositeEntity);
16407
+ mappedEntities.set(compositeEntity, entity);
16408
+ return entity;
16409
+ }
16410
+ // This function in runtime can be just `engine.addEntity()`
16411
+ const newEntity = entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE
16412
+ ? entityMapping.getNextAvailableEntity()
16413
+ : engine.addEntity();
16414
+ if (newEntity === null) {
16415
+ throw new Error('There is no more entities to allocate');
16416
+ }
16417
+ mappedEntities.set(compositeEntity, newEntity);
16418
+ return newEntity;
16419
+ }
16420
+ /**
16421
+ * @internal
16422
+ */
16423
+ function instanceComposite(engine, compositeData, compositeProvider, options) {
16424
+ const { rootEntity, alreadyRequestedId: optionalAlreadyRequestedId, entityMapping } = options;
16425
+ const alreadyRequestedId = optionalAlreadyRequestedId || new Set();
16426
+ const TransformComponentNumber = componentNumberFromName('core::Transform');
16427
+ const CompositeRootComponent = getCompositeRootComponent(engine);
16428
+ // Key => EntityNumber from the composite
16429
+ // Value => EntityNumber in current engine
16430
+ const mappedEntities = new Map();
16431
+ const getCompositeEntity = (compositeEntity) => getEntityMapping(engine, compositeEntity, mappedEntities, options);
16432
+ // ## 1 ##
16433
+ // First entity that I want to map, the root entity from the composite to the target entity in the engine
16434
+ // If there is no `rootEntity` passed, we assign one from `getNextAvailableEntity`
16435
+ const compositeRootEntity = rootEntity ?? getCompositeEntity(0);
16436
+ if (rootEntity) {
16437
+ mappedEntities.set(0, rootEntity);
16438
+ }
16439
+ // ## 2 ##
16440
+ // If there are more composite inside this one, we instance first.
16441
+ // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
16442
+ // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
16443
+ const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
16444
+ if (childrenComposite) {
16445
+ for (const [compositeEntity, childComposite] of childrenComposite.data) {
16446
+ const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
16447
+ const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
16448
+ const targetEntity = getCompositeEntity(compositeEntity);
16449
+ if (composite) {
16450
+ if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
16451
+ throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
16452
+ }
16453
+ instanceComposite(engine, composite, compositeProvider, {
16454
+ rootEntity: targetEntity,
16455
+ alreadyRequestedId: new Set(alreadyRequestedId).add(compositeData.id),
16456
+ entityMapping: entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
16457
+ });
16458
+ }
16459
+ }
16460
+ }
16461
+ // ## 3 ##
16462
+ // Then, we copy the all rest of the components (skipping the Composite ones)
16463
+ for (const component of compositeData.components) {
16464
+ // We already instanced the composite
16465
+ if (component.name === CompositeRootComponent.componentName)
16466
+ continue;
16467
+ // ## 3a ##
16468
+ // We find the component definition
16469
+ const componentDefinition = getComponentDefinition(engine, component);
16470
+ // ## 3b ##
16471
+ // Iterating over all the entities with this component and create the replica
16472
+ for (const [entity, compositeComponentValue] of component.data) {
16473
+ const componentValueDeserialized = getComponentValue(componentDefinition, compositeComponentValue);
16474
+ const targetEntity = getCompositeEntity(entity);
16475
+ const componentValue = componentDefinition.create(targetEntity, componentValueDeserialized);
16476
+ // ## 3c ##
16477
+ // All entities referenced in the composite probably has a different resolved EntityNumber
16478
+ // We'll know with the mappedEntityes
16479
+ if (componentDefinition.componentId === TransformComponentNumber) {
16480
+ const transform = componentValue;
16481
+ if (transform.parent) {
16482
+ transform.parent = getCompositeEntity(transform.parent);
16483
+ }
16484
+ // TODO: is it going to be necessary to remap assets? e.g. src param from AudioSource and GltfContainer
16485
+ }
16486
+ }
16487
+ }
16488
+ const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
16489
+ for (const [entitySource, targetEntity] of mappedEntities) {
16490
+ composite.entities.push({
16491
+ src: entitySource,
16492
+ dest: targetEntity
16493
+ });
16494
+ }
16495
+ composite.id = compositeData.id;
16496
+ return compositeRootEntity;
16497
+ }
16498
+
16333
16499
  /* eslint-disable */
16334
16500
  /**
16335
16501
  * `NullValue` is a singleton enumeration to represent the null value for the
@@ -16891,7 +17057,7 @@
16891
17057
  return obj;
16892
17058
  },
16893
17059
  };
16894
- function createBaseComposite() {
17060
+ function createBaseCompositeDefinition() {
16895
17061
  return { id: "", components: [] };
16896
17062
  }
16897
17063
  /**
@@ -16900,7 +17066,7 @@
16900
17066
  /**
16901
17067
  * @internal
16902
17068
  */
16903
- const Composite = {
17069
+ const CompositeDefinition = {
16904
17070
  encode(message, writer = _m0.Writer.create()) {
16905
17071
  if (message.id !== "") {
16906
17072
  writer.uint32(10).string(message.id);
@@ -16913,7 +17079,7 @@
16913
17079
  decode(input, length) {
16914
17080
  const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
16915
17081
  let end = length === undefined ? reader.len : reader.pos + length;
16916
- const message = createBaseComposite();
17082
+ const message = createBaseCompositeDefinition();
16917
17083
  while (reader.pos < end) {
16918
17084
  const tag = reader.uint32();
16919
17085
  switch (tag >>> 3) {
@@ -16997,196 +17163,45 @@
16997
17163
  return value !== null && value !== undefined;
16998
17164
  }
16999
17165
 
17000
- /* @public @deprecated */
17001
- function compositeFromJson(object) {
17002
- return Composite.fromJSON(object);
17003
- }
17004
- /* @public @deprecated */
17005
- function compositeFromBinary(buffer) {
17006
- return Composite.decode(buffer);
17007
- }
17008
- /* @public @deprecated */
17009
- function compositeToJson(composite) {
17010
- return Composite.toJSON(composite);
17011
- }
17012
- /* @public @deprecated */
17013
- function compositeToBinary(composite) {
17014
- return Composite.encode(composite).finish();
17015
- }
17016
-
17017
17166
  /**
17018
17167
  * @public
17019
17168
  * @deprecated composite is not being supported so far, please do not use this feature
17020
17169
  */
17021
- function getCompositeRootComponent(engine) {
17022
- const component = engine.getComponentOrNull('composite::root');
17023
- if (component) {
17024
- return component;
17025
- }
17026
- return engine.defineComponent('composite::root', {
17027
- id: exports.Schemas.String,
17028
- entities: exports.Schemas.Array(exports.Schemas.Map({
17029
- src: exports.Schemas.Entity,
17030
- dest: exports.Schemas.Entity
17031
- }))
17032
- });
17033
- }
17034
-
17035
- // @public
17036
- exports.EntityMappingMode = void 0;
17037
- (function (EntityMappingMode) {
17038
- EntityMappingMode[EntityMappingMode["EMM_NONE"] = 0] = "EMM_NONE";
17039
- EntityMappingMode[EntityMappingMode["EMM_NEXT_AVAILABLE"] = 1] = "EMM_NEXT_AVAILABLE";
17040
- EntityMappingMode[EntityMappingMode["EMM_DIRECT_MAPPING"] = 2] = "EMM_DIRECT_MAPPING";
17041
- })(exports.EntityMappingMode || (exports.EntityMappingMode = {}));
17042
- /**
17043
- * Return the component value from composite data
17044
- * @internal
17045
- */
17046
- function getComponentValue(componentDefinition, component) {
17047
- if (component.data?.$case === 'json') {
17048
- return component.data.json;
17049
- }
17050
- else {
17051
- return componentDefinition.schema.deserialize(new ReadWriteByteBuffer(component.data?.binary));
17052
- }
17053
- }
17054
- /**
17055
- * Return the component definition from composite info
17056
- * @internal
17057
- */
17058
- function getComponentDefinition(engine, component) {
17059
- const existingComponentDefinition = engine.getComponentOrNull(component.name);
17060
- if (!existingComponentDefinition) {
17061
- if (component.jsonSchema) {
17062
- return engine.defineComponentFromSchema(component.name, exports.Schemas.fromJson(component.jsonSchema));
17063
- }
17064
- else if (component.name.startsWith('core::')) {
17065
- if (component.name in componentDefinitionByName) {
17066
- return componentDefinitionByName[component.name](engine);
17067
- }
17068
- else {
17069
- throw new Error(`The core component ${component.name} was not found.`);
17070
- }
17071
- }
17072
- else {
17073
- throw new Error(`${component.name} is not defined and there is no schema to define it.`);
17074
- }
17075
- }
17076
- else {
17077
- return existingComponentDefinition;
17078
- }
17079
- }
17080
- /**
17081
- * Return the entity mapping or fail if there is no more
17082
- * @internal
17083
- */
17084
- function getEntityMapping(engine, compositeEntity, mappedEntities, { entityMapping }) {
17085
- const existingEntity = mappedEntities.get(compositeEntity);
17086
- if (existingEntity) {
17087
- return existingEntity;
17088
- }
17089
- if (entityMapping?.type === exports.EntityMappingMode.EMM_DIRECT_MAPPING) {
17090
- const entity = entityMapping.getCompositeEntity(compositeEntity);
17091
- mappedEntities.set(compositeEntity, entity);
17092
- return entity;
17093
- }
17094
- // This function in runtime can be just `engine.addEntity()`
17095
- const newEntity = entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE
17096
- ? entityMapping.getNextAvailableEntity()
17097
- : engine.addEntity();
17098
- if (newEntity === null) {
17099
- throw new Error('There is no more entities to allocate');
17170
+ exports.Composite = void 0;
17171
+ (function (Composite) {
17172
+ /** @public */
17173
+ function fromJson(object) {
17174
+ return CompositeDefinition.fromJSON(object);
17100
17175
  }
17101
- mappedEntities.set(compositeEntity, newEntity);
17102
- return newEntity;
17103
- }
17104
- /**
17105
- * Instance a composite and returns its root entity
17106
- * @param compositeData state serialized by the CRDT protocol
17107
- * @param getNextAvailableEntity function that gives unused entities
17108
- * @param rootEntity (optional) suggested mapped rootEntity for the composite
17109
- *
17110
- * @public
17111
- * @deprecated composite is not being supported so far, please do not use this feature
17112
- *
17113
- */
17114
-
17115
- function instanceComposite(engine, compositeData, compositeProvider, options = {}) {
17116
- const { rootEntity, alreadyRequestedId: optionalAlreadyRequestedId, entityMapping } = options;
17117
- const alreadyRequestedId = optionalAlreadyRequestedId || new Set();
17118
- const TransformComponentNumber = componentNumberFromName('core::Transform');
17119
- const CompositeRootComponent = getCompositeRootComponent(engine);
17120
- // Key => EntityNumber from the composite
17121
- // Value => EntityNumber in current engine
17122
- const mappedEntities = new Map();
17123
- const getCompositeEntity = (compositeEntity) => getEntityMapping(engine, compositeEntity, mappedEntities, options);
17124
- // ## 1 ##
17125
- // First entity that I want to map, the root entity from the composite to the target entity in the engine
17126
- // If there is no `rootEntity` passed, we assign one from `getNextAvailableEntity`
17127
- const compositeRootEntity = rootEntity ?? getCompositeEntity(0);
17128
- if (rootEntity) {
17129
- mappedEntities.set(0, rootEntity);
17176
+ Composite.fromJson = fromJson;
17177
+ /** @public */
17178
+ function fromBinary(buffer) {
17179
+ return CompositeDefinition.decode(buffer);
17130
17180
  }
17131
- // ## 2 ##
17132
- // If there are more composite inside this one, we instance first.
17133
- // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
17134
- // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
17135
- const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
17136
- if (childrenComposite) {
17137
- for (const [compositeEntity, childComposite] of childrenComposite.data) {
17138
- const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
17139
- const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
17140
- const targetEntity = getCompositeEntity(compositeEntity);
17141
- if (composite) {
17142
- if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
17143
- throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
17144
- }
17145
- instanceComposite(engine, composite, compositeProvider, {
17146
- rootEntity: targetEntity,
17147
- alreadyRequestedId: new Set(alreadyRequestedId).add(compositeData.id),
17148
- entityMapping: entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
17149
- });
17150
- }
17151
- }
17181
+ Composite.fromBinary = fromBinary;
17182
+ /** @public */
17183
+ function toJson(composite) {
17184
+ return CompositeDefinition.toJSON(composite);
17152
17185
  }
17153
- // ## 3 ##
17154
- // Then, we copy the all rest of the components (skipping the Composite ones)
17155
- for (const component of compositeData.components) {
17156
- // We already instanced the composite
17157
- if (component.name === CompositeRootComponent.componentName)
17158
- continue;
17159
- // ## 3a ##
17160
- // We find the component definition
17161
- const componentDefinition = getComponentDefinition(engine, component);
17162
- // ## 3b ##
17163
- // Iterating over all the entities with this component and create the replica
17164
- for (const [entity, compositeComponentValue] of component.data) {
17165
- const componentValueDeserialized = getComponentValue(componentDefinition, compositeComponentValue);
17166
- const targetEntity = getCompositeEntity(entity);
17167
- const componentValue = componentDefinition.create(targetEntity, componentValueDeserialized);
17168
- // ## 3c ##
17169
- // All entities referenced in the composite probably has a different resolved EntityNumber
17170
- // We'll know with the mappedEntityes
17171
- if (componentDefinition.componentId === TransformComponentNumber) {
17172
- const transform = componentValue;
17173
- if (transform.parent) {
17174
- transform.parent = getCompositeEntity(transform.parent);
17175
- }
17176
- // TODO: is it going to be necessary to remap assets? e.g. src param from AudioSource and GltfContainer
17177
- }
17178
- }
17186
+ Composite.toJson = toJson;
17187
+ /** @public */
17188
+ function toBinary(composite) {
17189
+ return CompositeDefinition.encode(composite).finish();
17179
17190
  }
17180
- const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
17181
- for (const [entitySource, targetEntity] of mappedEntities) {
17182
- composite.entities.push({
17183
- src: entitySource,
17184
- dest: targetEntity
17185
- });
17191
+ Composite.toBinary = toBinary;
17192
+ /**
17193
+ * Instance a composite and returns its root entity
17194
+ * @param compositeData - state serialized by the CRDT protocol
17195
+ * @param getNextAvailableEntity - function that gives unused entities
17196
+ * @param rootEntity - (optional) suggested mapped rootEntity for the composite
17197
+ *
17198
+ * @public
17199
+ */
17200
+ function instance(engine, compositeData, compositeProvider, options = {}) {
17201
+ instanceComposite(engine, compositeData, compositeProvider, options);
17186
17202
  }
17187
- composite.id = compositeData.id;
17188
- return compositeRootEntity;
17189
- }
17203
+ Composite.instance = instance;
17204
+ })(exports.Composite || (exports.Composite = {}));
17190
17205
 
17191
17206
  // The order of the following imports matters. Please do not auto-sort
17192
17207
  // export components for global engine
@@ -43858,7 +43873,6 @@
43858
43873
  exports.CRDT_MESSAGE_HEADER_LENGTH = CRDT_MESSAGE_HEADER_LENGTH;
43859
43874
  exports.CameraMode = CameraMode;
43860
43875
  exports.CameraModeArea = CameraModeArea;
43861
- exports.Composite = Composite;
43862
43876
  exports.DEG2RAD = DEG2RAD;
43863
43877
  exports.Dropdown = Dropdown;
43864
43878
  exports.Engine = Engine;
@@ -43948,10 +43962,6 @@
43948
43962
  exports.VisibilityComponent = VisibilityComponent;
43949
43963
  exports.componentDefinitionByName = componentDefinitionByName;
43950
43964
  exports.components = index;
43951
- exports.compositeFromBinary = compositeFromBinary;
43952
- exports.compositeFromJson = compositeFromJson;
43953
- exports.compositeToBinary = compositeToBinary;
43954
- exports.compositeToJson = compositeToJson;
43955
43965
  exports.createEthereumProvider = createEthereumProvider;
43956
43966
  exports.createInputSystem = createInputSystem;
43957
43967
  exports.createPointerEventSystem = createPointerEventSystem;
@@ -43961,8 +43971,8 @@
43961
43971
  exports.deepReadonly = deepReadonly;
43962
43972
  exports.engine = engine;
43963
43973
  exports.executeTask = executeTask;
43974
+ exports.getCompositeRootComponent = getCompositeRootComponent;
43964
43975
  exports.inputSystem = inputSystem;
43965
- exports.instanceComposite = instanceComposite;
43966
43976
  exports.isListener = isListener;
43967
43977
  exports.onCommsMessage = onCommsMessage;
43968
43978
  exports.onEnterScene = onEnterScene;