@dcl/playground-assets 7.1.3-4479271193.commit-2d89420 → 7.1.3-4479913205.commit-bfd9912

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/alpha.d.ts CHANGED
@@ -1458,6 +1458,12 @@ export declare type EntityContainer = {
1458
1458
  updateUsedEntity(entity: Entity): boolean;
1459
1459
  };
1460
1460
 
1461
+ export declare enum EntityMappingMode {
1462
+ EMM_NONE = 0,
1463
+ EMM_NEXT_AVAILABLE = 1,
1464
+ EMM_DIRECT_MAPPING = 2
1465
+ }
1466
+
1461
1467
  /**
1462
1468
  * @public
1463
1469
  * Common props to all components
@@ -2028,7 +2034,19 @@ export declare const inputSystem: IInputSystem;
2028
2034
  * @deprecated composite is not being supported so far, please do not use this feature
2029
2035
  *
2030
2036
  */
2031
- export declare function instanceComposite(engine: IEngine, compositeData: Composite, getNextAvailableEntity: () => Entity | null, compositeProvider: CompositeProvider, rootEntity?: Entity, alreadyRequestedId?: Set<string>): Entity;
2037
+ export declare function instanceComposite(engine: IEngine, compositeData: Composite, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): Entity;
2038
+
2039
+ export declare type InstanceCompositeOptions = {
2040
+ entityMapping?: {
2041
+ type: EntityMappingMode.EMM_NEXT_AVAILABLE;
2042
+ getNextAvailableEntity: () => Entity | null;
2043
+ } | {
2044
+ type: EntityMappingMode.EMM_DIRECT_MAPPING;
2045
+ getCompositeEntity: (compositeEntity: Entity | number) => Entity;
2046
+ };
2047
+ rootEntity?: Entity;
2048
+ alreadyRequestedId?: Set<string>;
2049
+ };
2032
2050
 
2033
2051
  /**
2034
2052
  * @public
package/dist/beta.d.ts CHANGED
@@ -1458,6 +1458,12 @@ export declare type EntityContainer = {
1458
1458
  updateUsedEntity(entity: Entity): boolean;
1459
1459
  };
1460
1460
 
1461
+ export declare enum EntityMappingMode {
1462
+ EMM_NONE = 0,
1463
+ EMM_NEXT_AVAILABLE = 1,
1464
+ EMM_DIRECT_MAPPING = 2
1465
+ }
1466
+
1461
1467
  /**
1462
1468
  * @public
1463
1469
  * Common props to all components
@@ -2024,7 +2030,19 @@ export declare const inputSystem: IInputSystem;
2024
2030
  * @deprecated composite is not being supported so far, please do not use this feature
2025
2031
  *
2026
2032
  */
2027
- export declare function instanceComposite(engine: IEngine, compositeData: Composite, getNextAvailableEntity: () => Entity | null, compositeProvider: CompositeProvider, rootEntity?: Entity, alreadyRequestedId?: Set<string>): Entity;
2033
+ export declare function instanceComposite(engine: IEngine, compositeData: Composite, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): Entity;
2034
+
2035
+ export declare type InstanceCompositeOptions = {
2036
+ entityMapping?: {
2037
+ type: EntityMappingMode.EMM_NEXT_AVAILABLE;
2038
+ getNextAvailableEntity: () => Entity | null;
2039
+ } | {
2040
+ type: EntityMappingMode.EMM_DIRECT_MAPPING;
2041
+ getCompositeEntity: (compositeEntity: Entity | number) => Entity;
2042
+ };
2043
+ rootEntity?: Entity;
2044
+ alreadyRequestedId?: Set<string>;
2045
+ };
2028
2046
 
2029
2047
  /**
2030
2048
  * @public
@@ -1458,6 +1458,12 @@ export declare type EntityContainer = {
1458
1458
  updateUsedEntity(entity: Entity): boolean;
1459
1459
  };
1460
1460
 
1461
+ export declare enum EntityMappingMode {
1462
+ EMM_NONE = 0,
1463
+ EMM_NEXT_AVAILABLE = 1,
1464
+ EMM_DIRECT_MAPPING = 2
1465
+ }
1466
+
1461
1467
  /**
1462
1468
  * @public
1463
1469
  * Common props to all components
@@ -2024,7 +2030,19 @@ export declare const inputSystem: IInputSystem;
2024
2030
  * @deprecated composite is not being supported so far, please do not use this feature
2025
2031
  *
2026
2032
  */
2027
- export declare function instanceComposite(engine: IEngine, compositeData: Composite, getNextAvailableEntity: () => Entity | null, compositeProvider: CompositeProvider, rootEntity?: Entity, alreadyRequestedId?: Set<string>): Entity;
2033
+ export declare function instanceComposite(engine: IEngine, compositeData: Composite, compositeProvider: CompositeProvider, options?: InstanceCompositeOptions): Entity;
2034
+
2035
+ export declare type InstanceCompositeOptions = {
2036
+ entityMapping?: {
2037
+ type: EntityMappingMode.EMM_NEXT_AVAILABLE;
2038
+ getNextAvailableEntity: () => Entity | null;
2039
+ } | {
2040
+ type: EntityMappingMode.EMM_DIRECT_MAPPING;
2041
+ getCompositeEntity: (compositeEntity: Entity | number) => Entity;
2042
+ };
2043
+ rootEntity?: Entity;
2044
+ alreadyRequestedId?: Set<string>;
2045
+ };
2028
2046
 
2029
2047
  /**
2030
2048
  * @public
package/dist/index.js CHANGED
@@ -16971,6 +16971,13 @@
16971
16971
  });
16972
16972
  }
16973
16973
 
16974
+ // @public
16975
+ exports.EntityMappingMode = void 0;
16976
+ (function (EntityMappingMode) {
16977
+ EntityMappingMode[EntityMappingMode["EMM_NONE"] = 0] = "EMM_NONE";
16978
+ EntityMappingMode[EntityMappingMode["EMM_NEXT_AVAILABLE"] = 1] = "EMM_NEXT_AVAILABLE";
16979
+ EntityMappingMode[EntityMappingMode["EMM_DIRECT_MAPPING"] = 2] = "EMM_DIRECT_MAPPING";
16980
+ })(exports.EntityMappingMode || (exports.EntityMappingMode = {}));
16974
16981
  /**
16975
16982
  * Return the component value from composite data
16976
16983
  * @internal
@@ -17013,13 +17020,20 @@
17013
17020
  * Return the entity mapping or fail if there is no more
17014
17021
  * @internal
17015
17022
  */
17016
- function getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity) {
17023
+ function getEntityMapping(engine, compositeEntity, mappedEntities, { entityMapping }) {
17017
17024
  const existingEntity = mappedEntities.get(compositeEntity);
17018
17025
  if (existingEntity) {
17019
17026
  return existingEntity;
17020
17027
  }
17028
+ if (entityMapping?.type === exports.EntityMappingMode.EMM_DIRECT_MAPPING) {
17029
+ const entity = entityMapping.getCompositeEntity(compositeEntity);
17030
+ mappedEntities.set(compositeEntity, entity);
17031
+ return entity;
17032
+ }
17021
17033
  // This function in runtime can be just `engine.addEntity()`
17022
- const newEntity = getNextAvailableEntity();
17034
+ const newEntity = entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE
17035
+ ? entityMapping.getNextAvailableEntity()
17036
+ : engine.addEntity();
17023
17037
  if (newEntity === null) {
17024
17038
  throw new Error('There is no more entities to allocate');
17025
17039
  }
@@ -17037,13 +17051,15 @@
17037
17051
  *
17038
17052
  */
17039
17053
 
17040
- function instanceComposite(engine, compositeData, getNextAvailableEntity, compositeProvider, rootEntity, alreadyRequestedId = new Set()) {
17054
+ function instanceComposite(engine, compositeData, compositeProvider, options = {}) {
17055
+ const { rootEntity, alreadyRequestedId: optionalAlreadyRequestedId, entityMapping } = options;
17056
+ const alreadyRequestedId = optionalAlreadyRequestedId || new Set();
17041
17057
  const TransformComponentNumber = componentNumberFromName('core::Transform');
17042
17058
  const CompositeRootComponent = getCompositeRootComponent(engine);
17043
17059
  // Key => EntityNumber from the composite
17044
17060
  // Value => EntityNumber in current engine
17045
17061
  const mappedEntities = new Map();
17046
- const getCompositeEntity = (compositeEntity) => getEntityMapping(compositeEntity, mappedEntities, getNextAvailableEntity);
17062
+ const getCompositeEntity = (compositeEntity) => getEntityMapping(engine, compositeEntity, mappedEntities, options);
17047
17063
  // ## 1 ##
17048
17064
  // First entity that I want to map, the root entity from the composite to the target entity in the engine
17049
17065
  // If there is no `rootEntity` passed, we assign one from `getNextAvailableEntity`
@@ -17057,14 +17073,19 @@
17057
17073
  // => TODO: in the future, the instanciation is first, then the overides (to parameterize Composite, e.g. house with different wall colors)
17058
17074
  const childrenComposite = compositeData.components.find((item) => item.name === CompositeRootComponent.componentName);
17059
17075
  if (childrenComposite) {
17060
- for (const [entity, childComposite] of childrenComposite.data) {
17076
+ for (const [compositeEntity, childComposite] of childrenComposite.data) {
17061
17077
  const compositeRoot = getComponentValue(CompositeRootComponent, childComposite);
17062
17078
  const composite = compositeProvider.getCompositeOrNull(compositeRoot.id);
17079
+ const targetEntity = getCompositeEntity(compositeEntity);
17063
17080
  if (composite) {
17064
17081
  if (alreadyRequestedId.has(compositeRoot.id) || compositeRoot.id === compositeData.id) {
17065
17082
  throw new Error(`Composite ${compositeRoot.id} has a recursive instanciation while try to instance ${compositeData.id}. Previous instances: ${alreadyRequestedId.toString()}`);
17066
17083
  }
17067
- instanceComposite(engine, composite, getNextAvailableEntity, compositeProvider, entity, new Set(alreadyRequestedId).add(compositeData.id));
17084
+ instanceComposite(engine, composite, compositeProvider, {
17085
+ rootEntity: targetEntity,
17086
+ alreadyRequestedId: new Set(alreadyRequestedId).add(compositeData.id),
17087
+ entityMapping: entityMapping?.type === exports.EntityMappingMode.EMM_NEXT_AVAILABLE ? entityMapping : undefined
17088
+ });
17068
17089
  }
17069
17090
  }
17070
17091
  }