@galacean/engine-loader 2.0.0-alpha.14 → 2.0.0-alpha.16
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/main.js +54 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +55 -9
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/resource-deserialize/resources/parser/ReflectionParser.d.ts +5 -2
- package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +12 -4
package/dist/main.js
CHANGED
|
@@ -803,6 +803,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
803
803
|
}
|
|
804
804
|
});
|
|
805
805
|
};
|
|
806
|
+
_proto.parseSignal = function parseSignal(signalRef) {
|
|
807
|
+
var _this = this;
|
|
808
|
+
var signal = new engineCore.Signal();
|
|
809
|
+
return Promise.all(signalRef.listeners.map(function(listener) {
|
|
810
|
+
return Promise.all([
|
|
811
|
+
_this.parseBasicType(listener.target),
|
|
812
|
+
listener.arguments ? Promise.all(listener.arguments.map(function(a) {
|
|
813
|
+
return _this.parseBasicType(a);
|
|
814
|
+
})) : Promise.resolve([])
|
|
815
|
+
]).then(function(param) {
|
|
816
|
+
var target = param[0], resolvedArgs = param[1];
|
|
817
|
+
if (target) {
|
|
818
|
+
var _signal;
|
|
819
|
+
(_signal = signal).on.apply(_signal, [].concat([
|
|
820
|
+
target,
|
|
821
|
+
listener.methodName
|
|
822
|
+
], resolvedArgs));
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
})).then(function() {
|
|
826
|
+
return signal;
|
|
827
|
+
});
|
|
828
|
+
};
|
|
806
829
|
_proto.parseBasicType = function parseBasicType(value, originValue) {
|
|
807
830
|
var _this = this;
|
|
808
831
|
if (Array.isArray(value)) {
|
|
@@ -827,11 +850,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
827
850
|
return resource;
|
|
828
851
|
});
|
|
829
852
|
} else if (ReflectionParser._isComponentRef(value)) {
|
|
830
|
-
var
|
|
831
|
-
return Promise.resolve(
|
|
853
|
+
var entity = this._resolveEntityByPath(value.entityPath);
|
|
854
|
+
if (!entity) return Promise.resolve(null);
|
|
855
|
+
var type = engineCore.Loader.getClass(value.componentType);
|
|
856
|
+
if (!type) return Promise.resolve(null);
|
|
857
|
+
var _entity_getComponents_value_componentIndex;
|
|
858
|
+
return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
|
|
832
859
|
} else if (ReflectionParser._isEntityRef(value)) {
|
|
833
|
-
|
|
834
|
-
|
|
860
|
+
return Promise.resolve(this._resolveEntityByPath(value.entityPath));
|
|
861
|
+
} else if (ReflectionParser._isSignalRef(value)) {
|
|
862
|
+
return this.parseSignal(value);
|
|
835
863
|
} else if (originValue) {
|
|
836
864
|
var _this2, _loop = function(key) {
|
|
837
865
|
if (key === "methods") {
|
|
@@ -887,6 +915,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
887
915
|
return Promise.resolve(entity);
|
|
888
916
|
}
|
|
889
917
|
};
|
|
918
|
+
_proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
|
|
919
|
+
var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
|
|
920
|
+
if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
|
|
921
|
+
var entity = entityMap.get(rootIds[entityPath[0]]);
|
|
922
|
+
for(var i = 1; i < entityPath.length; i++){
|
|
923
|
+
if (!entity || entityPath[i] >= entity.children.length) return null;
|
|
924
|
+
entity = entity.children[entityPath[i]];
|
|
925
|
+
}
|
|
926
|
+
return entity;
|
|
927
|
+
};
|
|
890
928
|
ReflectionParser._isClass = function _isClass(value) {
|
|
891
929
|
return value["class"] !== undefined;
|
|
892
930
|
};
|
|
@@ -897,10 +935,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
|
|
|
897
935
|
return value["url"] !== undefined;
|
|
898
936
|
};
|
|
899
937
|
ReflectionParser._isEntityRef = function _isEntityRef(value) {
|
|
900
|
-
return value["
|
|
938
|
+
return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
|
|
901
939
|
};
|
|
902
940
|
ReflectionParser._isComponentRef = function _isComponentRef(value) {
|
|
903
|
-
return value["
|
|
941
|
+
return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
|
|
942
|
+
};
|
|
943
|
+
ReflectionParser._isSignalRef = function _isSignalRef(value) {
|
|
944
|
+
return value["listeners"] !== undefined;
|
|
904
945
|
};
|
|
905
946
|
ReflectionParser._isMethodObject = function _isMethodObject(value) {
|
|
906
947
|
return Array.isArray(value == null ? void 0 : value.params);
|
|
@@ -1134,6 +1175,13 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1134
1175
|
for(var i = 0, l = entities.length; i < l; i++){
|
|
1135
1176
|
entityMap.set(entitiesConfig[i].id, entities[i]);
|
|
1136
1177
|
}
|
|
1178
|
+
// Build rootIds in serialization order (not async completion order)
|
|
1179
|
+
var rootIds = _this.context.rootIds;
|
|
1180
|
+
for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
|
|
1181
|
+
if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
|
|
1182
|
+
rootIds.push(entitiesConfig[i1].id);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1137
1185
|
return entities;
|
|
1138
1186
|
});
|
|
1139
1187
|
};
|
|
@@ -1259,7 +1307,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1259
1307
|
_proto._parseEntity = function _parseEntity(entityConfig, engine) {
|
|
1260
1308
|
var transform = entityConfig.transform;
|
|
1261
1309
|
var entity = new engineCore.Entity(engine, entityConfig.name, transform ? engineCore.Loader.getClass(transform.class) : engineCore.Transform);
|
|
1262
|
-
if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
|
|
1263
1310
|
this._addEntityPlugin(entityConfig.id, entity);
|
|
1264
1311
|
return Promise.resolve(entity);
|
|
1265
1312
|
};
|
|
@@ -1272,7 +1319,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
|
|
|
1272
1319
|
}).then(function(prefabResource) {
|
|
1273
1320
|
var entity = _instanceof(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
|
|
1274
1321
|
var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
|
|
1275
|
-
if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
|
|
1276
1322
|
_this._generateInstanceContext(entity, instanceContext, "");
|
|
1277
1323
|
_this._prefabContextMap.set(entity, instanceContext);
|
|
1278
1324
|
var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
|