cocos2d-cli 1.1.0 → 1.1.1
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.
- package/bin/cocos-cli.js +11 -3
- package/package.json +1 -1
- package/src/commands/create-scene.js +64 -0
- package/src/commands/set.js +19 -0
- package/src/commands/tree.js +2 -2
- package/src/lib/fire-utils.js +3 -3
package/bin/cocos-cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
3
|
* Cocos Creator CLI
|
|
4
4
|
* Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes
|
|
5
5
|
*/
|
|
@@ -54,11 +54,19 @@ Cocos Creator CLI - 场景/预制体操作工具集
|
|
|
54
54
|
--rotation=<角度> 修改旋转角度
|
|
55
55
|
--scaleX=<数值> 修改 X 缩放
|
|
56
56
|
--scaleY=<数值> 修改 Y 缩放
|
|
57
|
+
--string=<文字> 修改 Label 文字内容
|
|
58
|
+
--fontSize=<数值> 修改 Label 字体大小
|
|
59
|
+
--lineHeight=<数值> 修改 Label 行高
|
|
57
60
|
--type=sprite/label/button 添加节点时指定组件类型
|
|
58
61
|
--at=<索引> 添加节点时插入到子节点的指定位置(0=第一个)
|
|
59
62
|
|
|
60
|
-
create-scene
|
|
61
|
-
sprite, label,
|
|
63
|
+
create-scene 组件规则:
|
|
64
|
+
渲染组件(每节点仅一个): sprite, label, particle
|
|
65
|
+
功能组件(可多个共存): button, widget, layout, camera, canvas
|
|
66
|
+
|
|
67
|
+
[错误] BtnConfirm (sprite, label) -- 多个渲染组件
|
|
68
|
+
[正确] BtnConfirm (button, widget)
|
|
69
|
+
└─ BtnText (label)
|
|
62
70
|
|
|
63
71
|
create-scene 节点选项:
|
|
64
72
|
#width=100 设置宽度
|
package/package.json
CHANGED
|
@@ -28,6 +28,60 @@ const COMPONENT_TYPES = {
|
|
|
28
28
|
'particlesystem': 'particleSystem'
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// 渲染组件(一个节点只能有一个)
|
|
32
|
+
const RENDER_COMPONENTS = ['sprite', 'label', 'graphics', 'mask', 'richtext', 'particleSystem'];
|
|
33
|
+
|
|
34
|
+
// 功能组件(可以和渲染组件共存,也可以多个共存)
|
|
35
|
+
const FUNCTIONAL_COMPONENTS = ['button', 'widget', 'layout', 'canvas', 'camera'];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 校验节点的组件配置
|
|
39
|
+
* @returns {object} { valid: boolean, error?: string, warning?: string }
|
|
40
|
+
*/
|
|
41
|
+
function validateNodeComponents(nodeName, components) {
|
|
42
|
+
const renderComps = components.filter(c => RENDER_COMPONENTS.includes(c));
|
|
43
|
+
|
|
44
|
+
if (renderComps.length > 1) {
|
|
45
|
+
return {
|
|
46
|
+
valid: false,
|
|
47
|
+
error: `节点 "${nodeName}" 有多个渲染组件 [${renderComps.join(', ')}],Cocos Creator 不支持。
|
|
48
|
+
|
|
49
|
+
解决方法:将渲染组件拆分到子节点:
|
|
50
|
+
${nodeName} (${components.filter(c => !RENDER_COMPONENTS.includes(c)).join(', ') || '无组件'})
|
|
51
|
+
└─ ${nodeName}Graphic (${renderComps[0]})
|
|
52
|
+
|
|
53
|
+
渲染组件: sprite, label, graphics, mask, richtext, particle
|
|
54
|
+
功能组件: button, widget, layout, canvas, camera (可多个共存)`
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { valid: true };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 递归校验所有节点
|
|
63
|
+
*/
|
|
64
|
+
function validateAllNodes(nodes, path = '') {
|
|
65
|
+
const errors = [];
|
|
66
|
+
|
|
67
|
+
for (const node of nodes) {
|
|
68
|
+
const nodePath = path ? `${path}/${node.name}` : node.name;
|
|
69
|
+
const validation = validateNodeComponents(node.name, node.components);
|
|
70
|
+
|
|
71
|
+
if (!validation.valid) {
|
|
72
|
+
errors.push({ node: nodePath, error: validation.error });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 递归检查子节点
|
|
76
|
+
if (node.children && node.children.length > 0) {
|
|
77
|
+
const childErrors = validateAllNodes(node.children, nodePath);
|
|
78
|
+
errors.push(...childErrors);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return errors;
|
|
83
|
+
}
|
|
84
|
+
|
|
31
85
|
/**
|
|
32
86
|
* 解析树形文本结构
|
|
33
87
|
* 支持格式:
|
|
@@ -456,6 +510,16 @@ function run(args) {
|
|
|
456
510
|
return;
|
|
457
511
|
}
|
|
458
512
|
|
|
513
|
+
// 校验组件配置
|
|
514
|
+
const validationErrors = validateAllNodes(rootNodes);
|
|
515
|
+
if (validationErrors.length > 0) {
|
|
516
|
+
console.log(JSON.stringify({
|
|
517
|
+
error: '组件配置错误',
|
|
518
|
+
details: validationErrors
|
|
519
|
+
}));
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
|
|
459
523
|
// 生成场景数据
|
|
460
524
|
const sceneData = createSceneData(rootNodes, sceneName);
|
|
461
525
|
|
package/src/commands/set.js
CHANGED
|
@@ -261,6 +261,25 @@ function run(args) {
|
|
|
261
261
|
if (options.scaleY !== undefined) node._trs.array[8] = parseFloat(options.scaleY);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
// 修改 Label 文字内容及字体属性
|
|
265
|
+
if (options.string !== undefined || options.fontSize !== undefined || options.lineHeight !== undefined) {
|
|
266
|
+
const labelComp = (node._components || []).map(ref => data[ref.__id__]).find(c => c && c.__type__ === 'cc.Label');
|
|
267
|
+
if (!labelComp) {
|
|
268
|
+
console.log(JSON.stringify({ error: `节点 ${node._name} 没有 cc.Label 组件,无法设置文字属性` }));
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (options.string !== undefined) {
|
|
272
|
+
labelComp._string = options.string;
|
|
273
|
+
labelComp._N$string = options.string;
|
|
274
|
+
}
|
|
275
|
+
if (options.fontSize !== undefined) {
|
|
276
|
+
labelComp._fontSize = parseInt(options.fontSize);
|
|
277
|
+
}
|
|
278
|
+
if (options.lineHeight !== undefined) {
|
|
279
|
+
labelComp._lineHeight = parseInt(options.lineHeight);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
264
283
|
// 保存场景
|
|
265
284
|
saveScene(scenePath, data);
|
|
266
285
|
|
package/src/commands/tree.js
CHANGED
|
@@ -19,9 +19,9 @@ function run(args) {
|
|
|
19
19
|
|
|
20
20
|
// 输出文件类型
|
|
21
21
|
if (prefab) {
|
|
22
|
-
console.log(
|
|
22
|
+
console.log(`[Prefab] ${data[1]._name || 'Root'}\n`);
|
|
23
23
|
} else {
|
|
24
|
-
console.log(
|
|
24
|
+
console.log(`[Scene]\n`);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
console.log(buildTree(data, scriptMap, 1));
|
package/src/lib/fire-utils.js
CHANGED
|
@@ -445,7 +445,7 @@ function buildTree(data, scriptMap, nodeIndex, prefix = '', isLast = true, isRoo
|
|
|
445
445
|
|
|
446
446
|
// 场景根节点特殊处理
|
|
447
447
|
if (isSceneRoot) {
|
|
448
|
-
result = prefix + '
|
|
448
|
+
result = prefix + '[Scene]\n';
|
|
449
449
|
} else {
|
|
450
450
|
result = prefix + (isRoot ? '' : active + ' ') + nodeName + ' #' + nodeIndex;
|
|
451
451
|
|
|
@@ -458,9 +458,9 @@ function buildTree(data, scriptMap, nodeIndex, prefix = '', isLast = true, isRoo
|
|
|
458
458
|
let displayName;
|
|
459
459
|
if (uuidRegex.test(typeName)) {
|
|
460
460
|
const scriptInfo = scriptMap[typeName];
|
|
461
|
-
displayName = (scriptInfo && scriptInfo.name) ? scriptInfo.name : '
|
|
461
|
+
displayName = (scriptInfo && scriptInfo.name) ? scriptInfo.name : '[MissingScript]';
|
|
462
462
|
} else if (typeName === 'MissingScript') {
|
|
463
|
-
displayName = '
|
|
463
|
+
displayName = '[MissingScript]';
|
|
464
464
|
} else {
|
|
465
465
|
displayName = typeName.replace('cc.', '');
|
|
466
466
|
}
|