WPrefabParse.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. exports.PrefabParse = void 0;
  23. const fse = __importStar(require("fs-extra"));
  24. const ParseResult_1 = require("../../seek_miss/ParseResult");
  25. const WSimpleParse_1 = require("./WSimpleParse");
  26. const WCustomParse_1 = require("./WCustomParse");
  27. const WParticleParse_1 = require("./WParticleParse");
  28. class PrefabParse {
  29. constructor() {
  30. /**
  31. *
  32. */
  33. this._uuidMissedResult = new ParseResult_1.ParseResult();
  34. this._simpleTypes = new Map();
  35. this._extTypes = new Map();
  36. this._simpleParse = new WSimpleParse_1.SimpleParse();
  37. this._customParse = new WCustomParse_1.CustomParse();
  38. this._particleParse = new WParticleParse_1.ParticleParse();
  39. this._simpleTypes.set('cc.Sprite', true);
  40. this._simpleTypes.set('cc.Label', true);
  41. this._simpleTypes.set('cc.Button', true);
  42. this._simpleTypes.set('cc.MeshRenderer', true);
  43. this._simpleTypes.set('cc.SkinnedMeshRenderer', true);
  44. this._simpleTypes.set('cc.Animation', true);
  45. this._simpleTypes.set('cc.SkeletalAnimation', true);
  46. this._simpleTypes.set('cc.AudioSource', true);
  47. this._simpleTypes.set('cc.Graphics', true);
  48. this._simpleTypes.set('cc.RichText', true);
  49. this._simpleTypes.set('dragonBones.ArmatureDisplay', true);
  50. this._simpleTypes.set('cc.Billboard', true);
  51. this._simpleTypes.set('cc.Line', true);
  52. this._simpleTypes.set('cc.MotionStreak', true);
  53. this._simpleTypes.set('CCPropertyOverrideInfo', true);
  54. this._simpleTypes.set('cc.PrefabInfo', true);
  55. //粒子系统需要额外的处理
  56. // this._simpleTypes.set('cc.ParticleSystem', true);
  57. this._simpleTypes.set('cc.ParticleSystem2D', true);
  58. this._simpleTypes.set('cc.UIStaticBatch', true);
  59. this._simpleTypes.set('cc.SkinnedMeshBatchRenderer', true);
  60. this._simpleTypes.set('cc.BoxCollider', true);
  61. this._simpleTypes.set('sp.Skeleton', true);
  62. this._simpleTypes.set('cc.TiledMap', true);
  63. this._simpleTypes.set('cc.EditBox', true);
  64. this._simpleTypes.set('cc.VideoPlayer', true);
  65. this._extTypes.set('cc.Node', true);
  66. this._extTypes.set('cc.UITransform', true);
  67. this._extTypes.set('cc.RenderRoot2D', true);
  68. this._extTypes.set('cc.BlockInputEvents', true);
  69. this._extTypes.set('cc.DirectionalLight', true);
  70. this._extTypes.set('cc.SphereLight', true);
  71. this._extTypes.set('cc.SpotLight', true);
  72. this._extTypes.set('cc.SubContextView', true);
  73. this._extTypes.set('cc.WebView', true);
  74. this._extTypes.set('cc.RigidBody', true);
  75. this._extTypes.set('cc.Camera', true);
  76. this._extTypes.set('cc.Canvas', true);
  77. this._extTypes.set('cc.LabelOutline', true);
  78. this._extTypes.set('cc.LabelShadow', true);
  79. this._extTypes.set('cc.Layout', true);
  80. this._extTypes.set('cc.Widget', true);
  81. this._extTypes.set('cc.UIMeshRenderer', true);
  82. this._extTypes.set('cc.Toggle', true);
  83. this._extTypes.set('cc.ToggleContainer', true);
  84. this._extTypes.set('cc.UIOpacity', true);
  85. this._extTypes.set('cc.TargetInfo', true);
  86. }
  87. /**
  88. * @zh 检测预制件里是否会有丢失的uuid的引用,
  89. * @param prefabPath 预制件(场景)的完整路径
  90. */
  91. async testPrefab(prefabPath, fullUuid, compressedUuid) {
  92. let string = fse.readFileSync(prefabPath, 'utf-8');
  93. let fatherJson = JSON.parse(string);
  94. for (let nodeJson of fatherJson) {
  95. let type = nodeJson.__type__;
  96. if (type != 'cc.Node')
  97. continue;
  98. let components = nodeJson._components;
  99. if (!components || components.length <= 0)
  100. continue;
  101. for (let each of components) {
  102. if (each && each.__id__) {
  103. let comJson = fatherJson[each.__id__];
  104. if (this._extTypes.has(comJson.__type__))
  105. continue;
  106. let parse;
  107. if (this._simpleTypes.has(comJson.__type__)) {
  108. parse = this._simpleParse;
  109. }
  110. else if (comJson.__type__ == 'cc.ParticleSystem') {
  111. parse = this._particleParse;
  112. }
  113. else {
  114. // parse = this._simpleParse;
  115. parse = this._customParse;
  116. }
  117. let ret = await parse.parse(comJson, fatherJson, fullUuid, compressedUuid);
  118. if (ret.length) {
  119. let prefabInfo = await this._uuidMissedResult.getPrefabInfoByFullPath(prefabPath);
  120. let fullNodePath = this.findFullNodePath(fatherJson, nodeJson);
  121. let comInfo = new ParseResult_1.ComInfo();
  122. comInfo.comName = parse.comName;
  123. comInfo.propertyName = ret.join(', ');
  124. prefabInfo.putNodesInfo(fullNodePath, comInfo);
  125. }
  126. }
  127. }
  128. }
  129. }
  130. /**
  131. *
  132. * @param json prefab的数组json字符串
  133. * @param element json字符串里的某一项组件
  134. * @returns 这个组件在预制件里的完整路径
  135. */
  136. findFullNodePath(json, nodeJson) {
  137. let nodeNames = [];
  138. nodeNames.push(nodeJson._name);
  139. while (nodeJson._parent) {
  140. nodeJson = json[nodeJson._parent.__id__];
  141. nodeNames.push(nodeJson._name);
  142. }
  143. nodeNames = nodeNames.reverse();
  144. return nodeNames.join('/');
  145. }
  146. /**
  147. * 返回测试后所有的丢失了的uuid的路径
  148. */
  149. getResult() {
  150. return this._uuidMissedResult;
  151. }
  152. }
  153. exports.PrefabParse = PrefabParse;