WCustomParse.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CustomParse = void 0;
  4. const WBaseComParse_1 = require("./WBaseComParse");
  5. class CustomParse extends WBaseComParse_1.BaseComParse {
  6. /**
  7. * 解析预制件数组里的单个项目
  8. * @param json 预制件数组里的一个项目
  9. * @param uuidSeekedMap 已经找到了的uuid的名字
  10. * @param fatherJson 整个预制件的Json
  11. * @param fullUuid 完整的Uuid
  12. * @param compressedUuid 压缩后的uuid
  13. * @returns 返回丢失了uuid的属性的名字
  14. */
  15. async parse(json, fatherJson, fullUuid, compressedUuid) {
  16. let walkedMap = new Map();
  17. let ret = [];
  18. if (Editor.Utils.UUID.isUUID(json.__type__)) {
  19. let uuid = Editor.Utils.UUID.decompressUUID(json.__type__);
  20. let assetInfo = await Editor.Message.request('asset-db', 'query-asset-info', uuid);
  21. this.comName = (assetInfo === null || assetInfo === void 0 ? void 0 : assetInfo.name) || json.__type__;
  22. let type = json.__type__;
  23. if (type.includes(fullUuid) || type.includes(compressedUuid)) {
  24. ret.push(this.comName);
  25. }
  26. }
  27. else {
  28. this.comName = json.__type__;
  29. }
  30. await this.walk(json, ret, '', fatherJson, fullUuid, compressedUuid, walkedMap);
  31. return ret;
  32. }
  33. async walk(json, ret, propPath, fatherJson, fullUuid, compressedUuid, walkedMap) {
  34. if (json instanceof Array) {
  35. for (let i = 0; i < json.length; i++) {
  36. let ele = json[i];
  37. if (ele)
  38. await this.walk(ele, ret, propPath + '[' + i + ']', fatherJson, fullUuid, compressedUuid, walkedMap);
  39. }
  40. }
  41. else if (json instanceof Object) {
  42. if (json.__uuid__) {
  43. let uuid = json.__uuid__;
  44. if (uuid.includes(fullUuid) || uuid.includes(compressedUuid))
  45. ret.push(propPath);
  46. }
  47. else if (json.__id__) {
  48. //引用了其他的json元素
  49. let otherJson = fatherJson[json.__id__];
  50. if (otherJson && !walkedMap.has(json.__id__) && otherJson.__type__ != 'cc.Node') {
  51. walkedMap.set(json.__id__, true);
  52. await this.walk(otherJson, ret, propPath, fatherJson, fullUuid, compressedUuid, walkedMap);
  53. }
  54. }
  55. else {
  56. //迭代
  57. for (let k in json) {
  58. if (json[k]) {
  59. await this.walk(json[k], ret, propPath + '.' + k, fatherJson, fullUuid, compressedUuid, walkedMap);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. exports.CustomParse = CustomParse;