@galacean/engine-loader 2.0.0-alpha.15 → 2.0.0-alpha.17

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/module.js CHANGED
@@ -846,11 +846,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
846
846
  return resource;
847
847
  });
848
848
  } else if (ReflectionParser._isComponentRef(value)) {
849
- var _this__context_components_get;
850
- return Promise.resolve((_this__context_components_get = this._context.components.get(value.componentId)) != null ? _this__context_components_get : null);
849
+ var entity = this._resolveEntityByPath(value.entityPath);
850
+ if (!entity) return Promise.resolve(null);
851
+ var type = Loader.getClass(value.componentType);
852
+ if (!type) return Promise.resolve(null);
853
+ var _entity_getComponents_value_componentIndex;
854
+ return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
851
855
  } else if (ReflectionParser._isEntityRef(value)) {
852
- // entity reference
853
- return Promise.resolve(this._context.entityMap.get(value.entityId));
856
+ return Promise.resolve(this._resolveEntityByPath(value.entityPath));
854
857
  } else if (ReflectionParser._isSignalRef(value)) {
855
858
  return this.parseSignal(value);
856
859
  } else if (originValue) {
@@ -908,6 +911,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
908
911
  return Promise.resolve(entity);
909
912
  }
910
913
  };
914
+ _proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
915
+ var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
916
+ if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
917
+ var entity = entityMap.get(rootIds[entityPath[0]]);
918
+ for(var i = 1; i < entityPath.length; i++){
919
+ if (!entity || entityPath[i] >= entity.children.length) return null;
920
+ entity = entity.children[entityPath[i]];
921
+ }
922
+ return entity;
923
+ };
911
924
  ReflectionParser._isClass = function _isClass(value) {
912
925
  return value["class"] !== undefined;
913
926
  };
@@ -918,10 +931,10 @@ var ReflectionParser = /*#__PURE__*/ function() {
918
931
  return value["url"] !== undefined;
919
932
  };
920
933
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
921
- return value["entityId"] !== undefined;
934
+ return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
922
935
  };
923
936
  ReflectionParser._isComponentRef = function _isComponentRef(value) {
924
- return value["ownerId"] !== undefined && value["componentId"] !== undefined;
937
+ return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
925
938
  };
926
939
  ReflectionParser._isSignalRef = function _isSignalRef(value) {
927
940
  return value["listeners"] !== undefined;
@@ -1158,6 +1171,13 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1158
1171
  for(var i = 0, l = entities.length; i < l; i++){
1159
1172
  entityMap.set(entitiesConfig[i].id, entities[i]);
1160
1173
  }
1174
+ // Build rootIds in serialization order (not async completion order)
1175
+ var rootIds = _this.context.rootIds;
1176
+ for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
1177
+ if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
1178
+ rootIds.push(entitiesConfig[i1].id);
1179
+ }
1180
+ }
1161
1181
  return entities;
1162
1182
  });
1163
1183
  };
@@ -1283,7 +1303,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1283
1303
  _proto._parseEntity = function _parseEntity(entityConfig, engine) {
1284
1304
  var transform = entityConfig.transform;
1285
1305
  var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
1286
- if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
1287
1306
  this._addEntityPlugin(entityConfig.id, entity);
1288
1307
  return Promise.resolve(entity);
1289
1308
  };
@@ -1296,7 +1315,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
1296
1315
  }).then(function(prefabResource) {
1297
1316
  var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
1298
1317
  var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
1299
- if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
1300
1318
  _this._generateInstanceContext(entity, instanceContext, "");
1301
1319
  _this._prefabContextMap.set(entity, instanceContext);
1302
1320
  var cbArray = _this._prefabPromiseMap.get(entityConfig.id);