@dcl/playground-assets 7.1.2-4415683908.commit-0a210fd → 7.1.2-4426178080.commit-9504360

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
@@ -12939,6 +12939,38 @@
12939
12939
  /** @public */ const UiTransform$1 = engine => engine.defineComponentFromSchema("core::UiTransform", UiTransformSchema);
12940
12940
  /** @public */ const VideoPlayer$1 = engine => engine.defineComponentFromSchema("core::VideoPlayer", VideoPlayerSchema);
12941
12941
  /** @public */ const VisibilityComponent$1 = engine => engine.defineComponentFromSchema("core::VisibilityComponent", VisibilityComponentSchema);
12942
+ /** public */
12943
+ const componentDefinitionByName = {
12944
+ "core::Animator": Animator$2,
12945
+ "core::AudioSource": AudioSource$1,
12946
+ "core::AudioStream": AudioStream$1,
12947
+ "core::AvatarAttach": AvatarAttach$1,
12948
+ "core::AvatarModifierArea": AvatarModifierArea$1,
12949
+ "core::AvatarShape": AvatarShape$1,
12950
+ "core::Billboard": Billboard$1,
12951
+ "core::CameraMode": CameraMode$1,
12952
+ "core::CameraModeArea": CameraModeArea$1,
12953
+ "core::GltfContainer": GltfContainer$1,
12954
+ "core::Material": Material$2,
12955
+ "core::MeshCollider": MeshCollider$2,
12956
+ "core::MeshRenderer": MeshRenderer$2,
12957
+ "core::NftShape": NftShape$1,
12958
+ "core::PointerEvents": PointerEvents$1,
12959
+ "core::PointerEventsResult": PointerEventsResult$1,
12960
+ "core::PointerLock": PointerLock$1,
12961
+ "core::Raycast": Raycast$1,
12962
+ "core::RaycastResult": RaycastResult$1,
12963
+ "core::TextShape": TextShape$1,
12964
+ "core::UiBackground": UiBackground$1,
12965
+ "core::UiDropdown": UiDropdown$1,
12966
+ "core::UiDropdownResult": UiDropdownResult$1,
12967
+ "core::UiInput": UiInput$1,
12968
+ "core::UiInputResult": UiInputResult$1,
12969
+ "core::UiText": UiText$1,
12970
+ "core::UiTransform": UiTransform$1,
12971
+ "core::VideoPlayer": VideoPlayer$1,
12972
+ "core::VisibilityComponent": VisibilityComponent$1,
12973
+ };
12942
12974
 
12943
12975
  function defineAnimatorComponent(engine) {
12944
12976
  const theComponent = Animator$2(engine);
@@ -13322,7 +13354,8 @@
13322
13354
  get YGOverflow () { return exports.YGOverflow; },
13323
13355
  get YGPositionType () { return exports.YGPositionType; },
13324
13356
  get YGUnit () { return exports.YGUnit; },
13325
- get YGWrap () { return exports.YGWrap; }
13357
+ get YGWrap () { return exports.YGWrap; },
13358
+ componentDefinitionByName: componentDefinitionByName
13326
13359
  });
13327
13360
 
13328
13361
  /**
@@ -13931,6 +13964,57 @@
13931
13964
  };
13932
13965
  };
13933
13966
 
13967
+ const primitiveSchemas = {
13968
+ [Bool.jsonSchema.serializationType]: Bool,
13969
+ [EcsString.jsonSchema.serializationType]: EcsString,
13970
+ [Float32.jsonSchema.serializationType]: Float32,
13971
+ [Float64.jsonSchema.serializationType]: Float64,
13972
+ [Int8.jsonSchema.serializationType]: Int8,
13973
+ [Int16.jsonSchema.serializationType]: Int16,
13974
+ [Int32.jsonSchema.serializationType]: Int32,
13975
+ [Int64.jsonSchema.serializationType]: Int64,
13976
+ [Vector3Schema.jsonSchema.serializationType]: Vector3Schema,
13977
+ [QuaternionSchema.jsonSchema.serializationType]: QuaternionSchema,
13978
+ [Color3Schema.jsonSchema.serializationType]: Color3Schema,
13979
+ [Color4Schema.jsonSchema.serializationType]: Color4Schema,
13980
+ [EntitySchema.jsonSchema.serializationType]: EntitySchema
13981
+ };
13982
+ /**
13983
+ * Create an ISchema object from the json-schema
13984
+ * @param jsonSchema
13985
+ * @returns a ISchema or fail for unsupported json-schema
13986
+ */
13987
+ function jsonSchemaToSchema(jsonSchema) {
13988
+ if (primitiveSchemas[jsonSchema.serializationType]) {
13989
+ return primitiveSchemas[jsonSchema.serializationType];
13990
+ }
13991
+ if (jsonSchema.serializationType === 'map') {
13992
+ const mapJsonSchema = jsonSchema;
13993
+ const spec = {};
13994
+ for (const key in mapJsonSchema.properties) {
13995
+ spec[key] = jsonSchemaToSchema(mapJsonSchema.properties[key]);
13996
+ }
13997
+ return IMap(spec);
13998
+ }
13999
+ if (jsonSchema.serializationType === 'optional') {
14000
+ const withItemsJsonSchema = jsonSchema;
14001
+ return IOptional(jsonSchemaToSchema(withItemsJsonSchema.optionalJsonSchema));
14002
+ }
14003
+ if (jsonSchema.serializationType === 'array') {
14004
+ const withItemsJsonSchema = jsonSchema;
14005
+ return IArray(jsonSchemaToSchema(withItemsJsonSchema.items));
14006
+ }
14007
+ if (jsonSchema.serializationType === 'enum-int') {
14008
+ const enumJsonSchema = jsonSchema;
14009
+ return IntEnum(enumJsonSchema.enumObject, enumJsonSchema.default);
14010
+ }
14011
+ if (jsonSchema.serializationType === 'enum-string') {
14012
+ const enumJsonSchema = jsonSchema;
14013
+ return StringEnum(enumJsonSchema.enumObject, enumJsonSchema.default);
14014
+ }
14015
+ throw new Error(`${jsonSchema.serializationType} is not supported as reverse schema generation.`);
14016
+ }
14017
+
13934
14018
  /**
13935
14019
  * @public
13936
14020
  */
@@ -13974,6 +14058,12 @@
13974
14058
  Schemas.Map = IMap;
13975
14059
  /** @public */
13976
14060
  Schemas.Optional = IOptional;
14061
+ /**
14062
+ * @public Create an ISchema object from the json-schema
14063
+ * @param jsonSchema
14064
+ * @returns a ISchema or fail for unsupported json-schema
14065
+ */
14066
+ Schemas.fromJson = jsonSchemaToSchema;
13977
14067
  })(exports.Schemas || (exports.Schemas = {}));
13978
14068
 
13979
14069
  /**
@@ -15756,14 +15846,16 @@
15756
15846
  componentsDefinition.set(componentId, newComponent);
15757
15847
  return newComponent;
15758
15848
  }
15759
- function getComponent(componentId) {
15849
+ function getComponent(componentIdOrName) {
15850
+ const componentId = typeof componentIdOrName === 'number' ? componentIdOrName : componentNumberFromName(componentIdOrName);
15760
15851
  const component = componentsDefinition.get(componentId);
15761
15852
  if (!component) {
15762
15853
  throw new Error(`Component ${componentId} not found. You need to declare the components at the beginnig of the engine declaration`);
15763
15854
  }
15764
15855
  return component;
15765
15856
  }
15766
- function getComponentOrNull(componentId) {
15857
+ function getComponentOrNull(componentIdOrName) {
15858
+ const componentId = typeof componentIdOrName === 'number' ? componentIdOrName : componentNumberFromName(componentIdOrName);
15767
15859
  return (componentsDefinition.get(componentId) ??
15768
15860
  /* istanbul ignore next */
15769
15861
  null);
@@ -15794,7 +15886,10 @@
15794
15886
  function componentsIter() {
15795
15887
  return componentsDefinition.values();
15796
15888
  }
15797
- function removeComponentDefinition(componentId) {
15889
+ function removeComponentDefinition(componentIdOrName) {
15890
+ if (sealed)
15891
+ throw new Error('Engine is already sealed. No components can be removed at this stage');
15892
+ const componentId = typeof componentIdOrName === 'number' ? componentIdOrName : componentNumberFromName(componentIdOrName);
15798
15893
  componentsDefinition.delete(componentId);
15799
15894
  }
15800
15895
  const Transform = Transform$1({ defineComponentFromSchema });
@@ -16182,6 +16277,176 @@
16182
16277
  Font[Font["F_MONOSPACE"] = 2] = "F_MONOSPACE";
16183
16278
  })(exports.Font || (exports.Font = {}));
16184
16279
 
16280
+ /**
16281
+ * @public
16282
+ * @deprecated composite is not being supported so far, please do not use this feature
16283
+ */
16284
+ function compositeFromJson(jsonComposite) {
16285
+ if (!jsonComposite)
16286
+ throw new Error('Composite is not well defined');
16287
+ if (!jsonComposite.id || typeof jsonComposite.id !== 'string')
16288
+ throw new Error("Composite doesn't have a valid `id` field");
16289
+ const compositeId = jsonComposite.id;
16290
+ // TODO: Should be there a .version to identify the schema version?
16291
+ if (!Array.isArray(jsonComposite.components))
16292
+ throw new Error(`Composite '${compositeId}' fields 'components' is not an array`);
16293
+ const composite = {
16294
+ id: compositeId,
16295
+ components: []
16296
+ };
16297
+ for (const component of jsonComposite.components) {
16298
+ if (!component.name || typeof component.name !== 'string')
16299
+ throw new Error(`Composite '${compositeId}': The component doesn't have a valid name`);
16300
+ const componentName = component.name;
16301
+ const componentData = new Map();
16302
+ if (typeof component.data !== 'object' || Array.isArray(component.data))
16303
+ throw new Error(`Composite '${compositeId}': Invalid data in component '${component.name}'`);
16304
+ for (const [entityStr, data] of Object.entries(component.data)) {
16305
+ const entity = parseInt(entityStr);
16306
+ componentData.set(entity, data);
16307
+ }
16308
+ composite.components.push({
16309
+ name: componentName,
16310
+ data: componentData,
16311
+ schema: component.schema
16312
+ });
16313
+ }
16314
+ return composite;
16315
+ }
16316
+
16317
+ /**
16318
+ * @public
16319
+ * @deprecated composite is not being supported so far, please do not use this feature
16320
+ */
16321
+ function getCompositeRootComponent(engine) {
16322
+ const component = engine.getComponentOrNull('composite::root');
16323
+ if (component) {
16324
+ return component;
16325
+ }
16326
+ return engine.defineComponent('composite::root', {
16327
+ id: exports.Schemas.String,
16328
+ entities: exports.Schemas.Array(exports.Schemas.Map({
16329
+ src: exports.Schemas.Entity,
16330
+ dest: exports.Schemas.Entity
16331
+ }))
16332
+ });
16333
+ }
16334
+
16335
+ /**
16336
+ * Return the entity mapping or fail if there is no more
16337
+ */
16338
+ function getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity) {
16339
+ const existingEntity = mappedEntities.get(compositeEntity);
16340
+ if (existingEntity) {
16341
+ return existingEntity;
16342
+ }
16343
+ // This function in runtime can be just `engine.addEntity()`
16344
+ const newEntity = getNextAvailableEntity();
16345
+ if (newEntity === null) {
16346
+ throw new Error('There is no more entities to allocate');
16347
+ }
16348
+ mappedEntities.set(compositeEntity, newEntity);
16349
+ return newEntity;
16350
+ }
16351
+ /**
16352
+ * Instance a composite and returns its root entity
16353
+ * @param compositeData state serialized by the CRDT protocol
16354
+ * @param getNextAvailableEntity function that gives unused entities
16355
+ * @param rootEntity (optional) suggested mapped rootEntity for the composite
16356
+ *
16357
+ * @public
16358
+ * @deprecated composite is not being supported so far, please do not use this feature
16359
+ *
16360
+ */
16361
+
16362
+ function instanceComposite(engine, compositeData, getNextAvailableEntity, compositeProvider, rootEntity, alreadyRequestedId = new Set()) {
16363
+ const TransformComponentNumber = componentNumberFromName('core::Transform');
16364
+ const CompositeRootComponent = getCompositeRootComponent(engine);
16365
+ // Key => EntityNumber from the composite
16366
+ // Value => EntityNumber in current engine
16367
+ const mappedEntities = new Map();
16368
+ const getCompositeEntity = (compositeEntity) => getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity);
16369
+ // ## 1 ##
16370
+ // First entity that I want to map, the root entity from the composite to the target entity in the engine
16371
+ // If there is no `rootEntity` passed, we assign one from `getNextAvailableEntity`
16372
+ const compositeRootEntity = rootEntity ?? getCompositeEntity(0);
16373
+ if (rootEntity) {
16374
+ mappedEntities.set(0, rootEntity);
16375
+ }
16376
+ // ## 2 ##
16377
+ // If there are more composite inside this one, we instance first.
16378
+ // => This is not only a copy, we need to instance. Otherwise, we'd be missing that branches
16379
+ // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
16380
+ const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
16381
+ if (childrenComposite) {
16382
+ for (const [entity, childComposite] of childrenComposite.data) {
16383
+ const compositeRoot = childComposite;
16384
+ const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
16385
+ if (composite) {
16386
+ if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
16387
+ throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
16388
+ }
16389
+ instanceComposite(engine, composite, getNextAvailableEntity, compositeProvider, entity, new Set(alreadyRequestedId).add(compositeData.id));
16390
+ }
16391
+ }
16392
+ }
16393
+ // ## 3 ##
16394
+ // Then, we copy the all rest of the components (skipping the Composite ones)
16395
+ for (const component of compositeData.components) {
16396
+ // We already instanced the composite
16397
+ if (component.name === CompositeRootComponent.componentName)
16398
+ continue;
16399
+ // ## 3a ##
16400
+ // We find the component definition
16401
+ let componentDefinition;
16402
+ const existingComponentDefinition = engine.getComponentOrNull(component.name);
16403
+ if (!existingComponentDefinition) {
16404
+ if (component.schema) {
16405
+ componentDefinition = engine.defineComponentFromSchema(component.name, exports.Schemas.fromJson(component.schema));
16406
+ }
16407
+ else if (component.name.startsWith('core::')) {
16408
+ if (component.name in componentDefinitionByName) {
16409
+ componentDefinition = componentDefinitionByName[component.name](engine);
16410
+ }
16411
+ else {
16412
+ throw new Error(`The core component ${component.name} was not found.`);
16413
+ }
16414
+ }
16415
+ else {
16416
+ throw new Error(`${component.name} is not defined and there is no schema to define it.`);
16417
+ }
16418
+ }
16419
+ else {
16420
+ componentDefinition = existingComponentDefinition;
16421
+ }
16422
+ // ## 3b ##
16423
+ // Iterating over all the entities with this component and create the replica
16424
+ for (const [entity, compositeComponentValue] of component.data) {
16425
+ const targetEntity = getCompositeEntity(entity);
16426
+ const componentValue = componentDefinition.create(targetEntity, compositeComponentValue);
16427
+ // ## 3c ##
16428
+ // All entities referenced in the composite probably has a different resolved EntityNumber
16429
+ // We'll know with the mappedEntityes
16430
+ if (componentDefinition.componentId === TransformComponentNumber) {
16431
+ const transform = componentValue;
16432
+ if (transform.parent) {
16433
+ transform.parent = getCompositeEntity(transform.parent);
16434
+ }
16435
+ // TODO: is it going to be necessary to remap assets? e.g. src param from AudioSource and GltfContainer
16436
+ }
16437
+ }
16438
+ }
16439
+ const composite = CompositeRootComponent.getMutableOrNull(compositeRootEntity) || CompositeRootComponent.create(compositeRootEntity);
16440
+ for (const [entitySource, targetEntity] of mappedEntities) {
16441
+ composite.entities.push({
16442
+ src: entitySource,
16443
+ dest: targetEntity
16444
+ });
16445
+ }
16446
+ composite.id = compositeData.id;
16447
+ return compositeRootEntity;
16448
+ }
16449
+
16185
16450
  // The order of the following imports matters. Please do not auto-sort
16186
16451
  // export components for global engine
16187
16452
  const Transform = Transform$1(engine);
@@ -42935,7 +43200,9 @@
42935
43200
  exports.VideoPlayer = VideoPlayer;
42936
43201
  exports.VideoTexture = VideoTexture;
42937
43202
  exports.VisibilityComponent = VisibilityComponent;
43203
+ exports.componentDefinitionByName = componentDefinitionByName;
42938
43204
  exports.components = index;
43205
+ exports.compositeFromJson = compositeFromJson;
42939
43206
  exports.createEthereumProvider = createEthereumProvider;
42940
43207
  exports.createInputSystem = createInputSystem;
42941
43208
  exports.createPointerEventSystem = createPointerEventSystem;
@@ -42946,6 +43213,7 @@
42946
43213
  exports.engine = engine;
42947
43214
  exports.executeTask = executeTask;
42948
43215
  exports.inputSystem = inputSystem;
43216
+ exports.instanceComposite = instanceComposite;
42949
43217
  exports.isListener = isListener;
42950
43218
  exports.onCommsMessage = onCommsMessage;
42951
43219
  exports.onEnterScene = onEnterScene;