cocos2d-cli 2.1.3 → 2.2.0

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.
@@ -116,7 +116,87 @@ export function deleteNode(node) {
116
116
  return removeFromParent(node);
117
117
  }
118
118
  export function buildTree(data, scriptMap, startIndex) {
119
- return JSON.stringify(data[startIndex], null, 2);
119
+ const root = data[startIndex];
120
+ if (!root)
121
+ return '';
122
+ if (root.__type__ === 'cc.Prefab') {
123
+ const prefabNode = data[1];
124
+ if (!prefabNode)
125
+ return '';
126
+ const prefabActive = prefabNode._active !== false ? '●' : '○';
127
+ let result = prefabActive + ' ' + (prefabNode._name || 'Root');
128
+ result += buildComponentInfo(data, prefabNode, scriptMap);
129
+ result += '\n';
130
+ if (prefabNode._children && prefabNode._children.length > 0) {
131
+ prefabNode._children.forEach((childRef, idx) => {
132
+ const childIsLast = idx === prefabNode._children.length - 1;
133
+ result += buildTreeNode(data, scriptMap, childRef.__id__, '', childIsLast, false);
134
+ });
135
+ }
136
+ return result;
137
+ }
138
+ const sceneRoot = root;
139
+ if (sceneRoot.__type__ === 'cc.Scene') {
140
+ let result = '[Scene]\n';
141
+ if (sceneRoot._children && sceneRoot._children.length > 0) {
142
+ sceneRoot._children.forEach((childRef, idx) => {
143
+ const childIsLast = idx === sceneRoot._children.length - 1;
144
+ result += buildTreeNode(data, scriptMap, childRef.__id__, '', childIsLast, false);
145
+ });
146
+ }
147
+ return result;
148
+ }
149
+ return buildTreeNode(data, scriptMap, startIndex, '', true, true);
150
+ }
151
+ function buildComponentInfo(data, node, scriptMap) {
152
+ if (!node._components || node._components.length === 0)
153
+ return '';
154
+ const uuidRegex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
155
+ const comps = node._components.map((c) => {
156
+ const comp = data[c.__id__];
157
+ if (!comp)
158
+ return '?';
159
+ const typeName = comp.__type__;
160
+ let displayName;
161
+ if (uuidRegex.test(typeName)) {
162
+ const scriptInfo = scriptMap[typeName];
163
+ if (scriptInfo) {
164
+ displayName = scriptInfo;
165
+ }
166
+ else {
167
+ displayName = '[MissingScript]';
168
+ }
169
+ }
170
+ else if (typeName === 'MissingScript') {
171
+ displayName = '[MissingScript]';
172
+ }
173
+ else {
174
+ displayName = typeName.replace('cc.', '');
175
+ }
176
+ return displayName;
177
+ }).join(', ');
178
+ return ` (${comps})`;
179
+ }
180
+ function buildTreeNode(data, scriptMap, nodeIndex, prefix = '', isLast = true, isRoot = true) {
181
+ const node = data[nodeIndex];
182
+ if (!node)
183
+ return '';
184
+ const nodeName = node._name || '(unnamed)';
185
+ const active = node._active !== false ? '●' : '○';
186
+ const uuidRegex = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
187
+ let result = '';
188
+ const connector = isRoot ? '' : (isLast ? '└── ' : '├── ');
189
+ result = prefix + connector + (isRoot ? '' : active + ' ') + nodeName;
190
+ result += buildComponentInfo(data, node, scriptMap);
191
+ result += '\n';
192
+ if (node._children && node._children.length > 0) {
193
+ const childPrefix = prefix + (isRoot ? '' : (isLast ? ' ' : '│ '));
194
+ node._children.forEach((childRef, idx) => {
195
+ const childIsLast = idx === node._children.length - 1;
196
+ result += buildTreeNode(data, scriptMap, childRef.__id__, childPrefix, childIsLast, false);
197
+ });
198
+ }
199
+ return result;
120
200
  }
121
201
  export function detectItemType(item) {
122
202
  if (!item)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cocos2d-cli",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
5
5
  "type": "module",
6
6
  "main": "dist/bin/cocos2d-cli.js",