cocos2d-cli 2.1.2 → 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.
|
@@ -3,12 +3,14 @@ import { takeScreenshot } from '../lib/screenshot-core.js';
|
|
|
3
3
|
export async function run(args) {
|
|
4
4
|
const jsonFilePath = args[0];
|
|
5
5
|
if (!jsonFilePath) {
|
|
6
|
-
console.log(JSON.stringify({ error: '用法: cocos2d-cli screenshot <json文件> [--width <宽度>] [--height <高度>] [--output
|
|
6
|
+
console.log(JSON.stringify({ error: '用法: cocos2d-cli screenshot <json文件> [--width <宽度>] [--height <高度>] [--output <输出目录>] [--debug-bounds] [--wait <毫秒>]' }));
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
let width = 750;
|
|
10
10
|
let height = 1334;
|
|
11
|
-
let
|
|
11
|
+
let outputDir = process.cwd();
|
|
12
|
+
let debugBounds = false;
|
|
13
|
+
let waitTime = 3000;
|
|
12
14
|
for (let i = 1; i < args.length; i++) {
|
|
13
15
|
const arg = args[i];
|
|
14
16
|
if (arg === '--width' && args[i + 1]) {
|
|
@@ -19,8 +21,15 @@ export async function run(args) {
|
|
|
19
21
|
height = parseInt(args[i + 1]);
|
|
20
22
|
i++;
|
|
21
23
|
}
|
|
22
|
-
else if (arg === '--output' && args[i + 1]) {
|
|
23
|
-
|
|
24
|
+
else if ((arg === '--output' || arg === '-o') && args[i + 1]) {
|
|
25
|
+
outputDir = args[i + 1];
|
|
26
|
+
i++;
|
|
27
|
+
}
|
|
28
|
+
else if (arg === '--debug-bounds') {
|
|
29
|
+
debugBounds = true;
|
|
30
|
+
}
|
|
31
|
+
else if (arg === '--wait' && args[i + 1]) {
|
|
32
|
+
waitTime = parseInt(args[i + 1]);
|
|
24
33
|
i++;
|
|
25
34
|
}
|
|
26
35
|
}
|
|
@@ -28,12 +37,14 @@ export async function run(args) {
|
|
|
28
37
|
const { screenshotPath, logs } = await takeScreenshot({
|
|
29
38
|
jsonPath: jsonFilePath,
|
|
30
39
|
viewport: { width, height },
|
|
31
|
-
outputDir
|
|
40
|
+
outputDir,
|
|
32
41
|
fullPage: true,
|
|
42
|
+
debugBounds,
|
|
33
43
|
timeout: 30000,
|
|
34
|
-
waitTime
|
|
44
|
+
waitTime
|
|
35
45
|
});
|
|
36
|
-
|
|
46
|
+
const filename = path.basename(screenshotPath);
|
|
47
|
+
console.log(JSON.stringify({ success: true, filename }));
|
|
37
48
|
}
|
|
38
49
|
catch (err) {
|
|
39
50
|
console.log(JSON.stringify({ error: err.message }));
|
|
@@ -116,7 +116,87 @@ export function deleteNode(node) {
|
|
|
116
116
|
return removeFromParent(node);
|
|
117
117
|
}
|
|
118
118
|
export function buildTree(data, scriptMap, startIndex) {
|
|
119
|
-
|
|
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)
|