PrefabParse.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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("../ParseResult");
  25. const SimpleParse_1 = require("./SimpleParse");
  26. const CustomParse_1 = require("./CustomParse");
  27. const ParticleParse_1 = require("./ParticleParse");
  28. class PrefabParse {
  29. constructor() {
  30. /**
  31. * @zh 本次寻找过程中已经需找到了的uuid会存储在这里,而不会再次寻找
  32. */
  33. this._uuidSeekedMap = new Map();
  34. /**
  35. *
  36. */
  37. this._uuidMissedResult = new ParseResult_1.ParseResult();
  38. this._simpleTypes = new Map();
  39. this._extTypes = new Map();
  40. this._simpleParse = new SimpleParse_1.SimpleParse();
  41. this._customParse = new CustomParse_1.CustomParse();
  42. this._particleParse = new ParticleParse_1.ParticleParse();
  43. this._simpleTypes.set('cc.Sprite', true);
  44. this._simpleTypes.set('cc.Label', true);
  45. this._simpleTypes.set('cc.Button', true);
  46. this._simpleTypes.set('cc.MeshRenderer', true);
  47. this._simpleTypes.set('cc.SkinnedMeshRenderer', true);
  48. this._simpleTypes.set('cc.Animation', true);
  49. this._simpleTypes.set('cc.SkeletalAnimation', true);
  50. this._simpleTypes.set('cc.AudioSource', true);
  51. this._simpleTypes.set('cc.Graphics', true);
  52. this._simpleTypes.set('cc.RichText', true);
  53. this._simpleTypes.set('dragonBones.ArmatureDisplay', true);
  54. this._simpleTypes.set('cc.Billboard', true);
  55. this._simpleTypes.set('cc.Line', true);
  56. this._simpleTypes.set('cc.MotionStreak', true);
  57. this._simpleTypes.set('CCPropertyOverrideInfo', true);
  58. this._simpleTypes.set('cc.PrefabInfo', true);
  59. //粒子系统需要额外的处理
  60. // this._simpleTypes.set('cc.ParticleSystem', true);
  61. this._simpleTypes.set('cc.ParticleSystem2D', true);
  62. this._simpleTypes.set('cc.UIStaticBatch', true);
  63. this._simpleTypes.set('cc.SkinnedMeshBatchRenderer', true);
  64. this._simpleTypes.set('cc.BoxCollider', true);
  65. this._simpleTypes.set('sp.Skeleton', true);
  66. this._simpleTypes.set('cc.TiledMap', true);
  67. this._simpleTypes.set('cc.EditBox', true);
  68. this._simpleTypes.set('cc.VideoPlayer', true);
  69. this._extTypes.set('cc.Node', true);
  70. this._extTypes.set('cc.UITransform', true);
  71. this._extTypes.set('cc.RenderRoot2D', true);
  72. this._extTypes.set('cc.BlockInputEvents', true);
  73. this._extTypes.set('cc.DirectionalLight', true);
  74. this._extTypes.set('cc.SphereLight', true);
  75. this._extTypes.set('cc.SpotLight', true);
  76. this._extTypes.set('cc.SubContextView', true);
  77. this._extTypes.set('cc.WebView', true);
  78. this._extTypes.set('cc.RigidBody', true);
  79. this._extTypes.set('cc.Camera', true);
  80. this._extTypes.set('cc.Canvas', true);
  81. this._extTypes.set('cc.LabelOutline', true);
  82. this._extTypes.set('cc.LabelShadow', true);
  83. this._extTypes.set('cc.Layout', true);
  84. this._extTypes.set('cc.Widget', true);
  85. this._extTypes.set('cc.UIMeshRenderer', true);
  86. this._extTypes.set('cc.Toggle', true);
  87. this._extTypes.set('cc.ToggleContainer', true);
  88. this._extTypes.set('cc.UIOpacity', true);
  89. this._extTypes.set('cc.TargetInfo', true);
  90. }
  91. /**
  92. * @zh 检测预制件里是否会有丢失的uuid的引用,
  93. * @param prefabPath 预制件(场景)的完整路径
  94. */
  95. async testPrefab(prefabPath) {
  96. let string = fse.readFileSync(prefabPath, 'utf-8');
  97. let fatherJson = JSON.parse(string);
  98. for (let nodeJson of fatherJson) {
  99. let type = nodeJson.__type__;
  100. if (type != 'cc.Node')
  101. continue;
  102. // console.log('node Name: ', nodeJson._name);
  103. let components = nodeJson._components;
  104. if (!components || components.length <= 0)
  105. continue;
  106. for (let each of components) {
  107. if (each && each.__id__) {
  108. let comJson = fatherJson[each.__id__];
  109. if (this._extTypes.has(comJson.__type__))
  110. continue;
  111. let parse;
  112. if (this._simpleTypes.has(comJson.__type__)) {
  113. parse = this._simpleParse;
  114. }
  115. else if (comJson.__type__ == 'cc.ParticleSystem') {
  116. parse = this._particleParse;
  117. }
  118. else {
  119. // parse = this._simpleParse;
  120. parse = this._customParse;
  121. }
  122. let ret = await parse.parse(comJson, this._uuidSeekedMap, fatherJson);
  123. if (ret.length) {
  124. let prefabInfo = await this._uuidMissedResult.getPrefabInfoByFullPath(prefabPath);
  125. let fullNodePath = this.findFullNodePath(fatherJson, nodeJson);
  126. let comInfo = new ParseResult_1.ComInfo();
  127. comInfo.comName = parse.comName;
  128. comInfo.propertyName = ret.join(', ');
  129. prefabInfo.putNodesInfo(fullNodePath, comInfo);
  130. }
  131. }
  132. }
  133. }
  134. }
  135. /**
  136. *
  137. * @param json prefab的数组json字符串
  138. * @param element json字符串里的某一项组件
  139. * @returns 这个组件在预制件里的完整路径
  140. */
  141. findFullNodePath(json, nodeJson) {
  142. let nodeNames = [];
  143. nodeNames.push(nodeJson._name);
  144. while (nodeJson._parent) {
  145. nodeJson = json[nodeJson._parent.__id__];
  146. nodeNames.push(nodeJson._name);
  147. }
  148. nodeNames = nodeNames.reverse();
  149. return nodeNames.join('/');
  150. }
  151. /**
  152. * 返回测试后所有的丢失了的uuid的路径
  153. */
  154. getResult() {
  155. return this._uuidMissedResult;
  156. }
  157. }
  158. exports.PrefabParse = PrefabParse;