cocos2d-cli 1.6.1 → 1.6.2
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/cocos2d-cli.js +11 -31
- package/package.json +3 -3
- package/src/commands/screenshot.js +11 -6
- package/src/lib/cc/CCLabel.js +27 -2
- package/src/lib/cc/CCRichText.js +44 -0
- package/src/lib/cc/CCSprite.js +2 -2
- package/src/lib/cc/index.js +3 -1
- package/src/lib/json-parser.js +27 -8
- package/src/lib/screenshot/index.html +1 -1
- package/src/lib/screenshot-core.js +6 -2
package/bin/cocos2d-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
|
*/
|
|
@@ -81,41 +81,21 @@ add 支持的选项:
|
|
|
81
81
|
--string=<文字> Label 文字内容 (配合 --type=label)
|
|
82
82
|
--fontSize=<数值> Label 字体大小 (配合 --type=label)
|
|
83
83
|
|
|
84
|
-
JSON
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
JSON 格式:
|
|
85
|
+
详见 SKILL.md 完整文档。简要示例:
|
|
87
86
|
{
|
|
88
|
-
"name": "
|
|
89
|
-
"width": 400,
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"y": 0,
|
|
93
|
-
"color": "#336699",
|
|
94
|
-
"opacity": 255,
|
|
87
|
+
"name": "Node",
|
|
88
|
+
"width": 400, "height": 300,
|
|
89
|
+
"x": 0, "y": 0,
|
|
90
|
+
"anchorX": 0, "color": "#336699",
|
|
95
91
|
"components": [
|
|
96
|
-
"
|
|
97
|
-
{ "type": "
|
|
98
|
-
{ "type": "label", "string": "Hello", "fontSize": 32 }
|
|
92
|
+
{ "type": "label", "string": "Hello", "horizontalAlign": "left" },
|
|
93
|
+
{ "type": "richText", "string": "<color=#3cb034>绿色</color>" }
|
|
99
94
|
],
|
|
100
95
|
"children": [...]
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
组件写法:
|
|
106
|
-
简写: "sprite" 或 "label"
|
|
107
|
-
完整: { "type": "sprite", "sizeMode": 1 }
|
|
108
|
-
完整: { "type": "label", "string": "文本", "fontSize": 32, "color": "#fff" }
|
|
109
|
-
|
|
110
|
-
组件类型:
|
|
111
|
-
sprite - 精灵(默认白色方块,节点设置什么颜色就显示什么颜色)
|
|
112
|
-
label - 文本,支持 string, fontSize, color(兼容)
|
|
113
|
-
button - 按钮,通常配合 sprite 使用才能看见
|
|
114
|
-
widget - 对齐,支持 top, bottom, left, right
|
|
115
|
-
layout - 布局,自动排列子节点
|
|
116
|
-
canvas - 画布,根节点使用
|
|
117
|
-
camera - 相机
|
|
118
|
-
particle - 粒子效果
|
|
98
|
+
提示:配合 anchorX + horizontalAlign 实现靠左/靠右布局(见 SKILL.md)
|
|
119
99
|
|
|
120
100
|
示例:
|
|
121
101
|
cocos2d-cli tree assets/main.fire
|
|
@@ -141,7 +121,7 @@ JSON 格式 (create-prefab / create-scene):
|
|
|
141
121
|
|
|
142
122
|
# 截图
|
|
143
123
|
cocos2d-cli screenshot data.json
|
|
144
|
-
cocos2d-cli screenshot data.json -o ./screenshots
|
|
124
|
+
cocos2d-cli screenshot data.json -o ./screenshots --width 1080 --height 1920
|
|
145
125
|
`);
|
|
146
126
|
}
|
|
147
127
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "cocos2d-cli",
|
|
3
|
-
"version": "1.6.
|
|
2
|
+
"name": "cocos2d-cli",
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
|
|
5
5
|
"main": "bin/cocos2d-cli.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"cocos2d-cli": "
|
|
7
|
+
"cocos2d-cli": "bin/cocos2d-cli.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* screenshot 命令
|
|
2
|
+
* screenshot 命令
|
|
3
3
|
* 渲染 JSON 数据并截图
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -13,17 +13,19 @@ function showHelp() {
|
|
|
13
13
|
|
|
14
14
|
选项:
|
|
15
15
|
-o, --output <目录> 输出目录,默认当前目录
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
--width <数值> 视口宽度,默认 750(不支持简写)
|
|
17
|
+
--height <数值> 视口高度,默认 1334(不支持简写)
|
|
18
18
|
--full-page 全页截图(默认)
|
|
19
19
|
--no-full-page 仅视口截图
|
|
20
|
+
--debug-bounds 叠加节点边界框和名称,方便定位布局问题
|
|
20
21
|
--timeout <毫秒> 页面加载超时,默认 30000
|
|
21
22
|
--wait <毫秒> 截图前等待时间,默认 1000
|
|
22
23
|
|
|
23
24
|
示例:
|
|
24
25
|
cocos2d-cli screenshot data.json
|
|
25
26
|
cocos2d-cli screenshot data.json -o ./screenshots
|
|
26
|
-
cocos2d-cli screenshot data.json
|
|
27
|
+
cocos2d-cli screenshot data.json --width 1080 --height 1920
|
|
28
|
+
cocos2d-cli screenshot data.json --debug-bounds
|
|
27
29
|
cocos2d-cli screenshot data.json --no-full-page
|
|
28
30
|
`);
|
|
29
31
|
}
|
|
@@ -34,6 +36,7 @@ function parseArgs(args) {
|
|
|
34
36
|
outputDir: '.',
|
|
35
37
|
viewport: { width: 750, height: 1334 },
|
|
36
38
|
fullPage: true,
|
|
39
|
+
debugBounds: false,
|
|
37
40
|
timeout: 30000,
|
|
38
41
|
waitTime: 1000
|
|
39
42
|
};
|
|
@@ -49,14 +52,16 @@ function parseArgs(args) {
|
|
|
49
52
|
|
|
50
53
|
if (arg === '-o' || arg === '--output') {
|
|
51
54
|
options.outputDir = args[++i];
|
|
52
|
-
} else if (arg === '
|
|
55
|
+
} else if (arg === '--width') {
|
|
53
56
|
options.viewport.width = parseInt(args[++i], 10);
|
|
54
|
-
} else if (arg === '
|
|
57
|
+
} else if (arg === '--height') {
|
|
55
58
|
options.viewport.height = parseInt(args[++i], 10);
|
|
56
59
|
} else if (arg === '--full-page') {
|
|
57
60
|
options.fullPage = true;
|
|
58
61
|
} else if (arg === '--no-full-page') {
|
|
59
62
|
options.fullPage = false;
|
|
63
|
+
} else if (arg === '--debug-bounds') {
|
|
64
|
+
options.debugBounds = true;
|
|
60
65
|
} else if (arg === '--timeout') {
|
|
61
66
|
options.timeout = parseInt(args[++i], 10);
|
|
62
67
|
} else if (arg === '--wait') {
|
package/src/lib/cc/CCLabel.js
CHANGED
|
@@ -74,6 +74,31 @@ class CCLabel extends CCComponent {
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* 将语义化对齐字符串转为数字
|
|
79
|
+
* horizontalAlign: left=0, center=1, right=2
|
|
80
|
+
* verticalAlign: top=0, center=1, bottom=2
|
|
81
|
+
*/
|
|
82
|
+
static parseHAlign(value) {
|
|
83
|
+
if (typeof value === 'number') return value;
|
|
84
|
+
switch (String(value).toLowerCase()) {
|
|
85
|
+
case 'left': return 0;
|
|
86
|
+
case 'center': return 1;
|
|
87
|
+
case 'right': return 2;
|
|
88
|
+
default: return 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static parseVAlign(value) {
|
|
93
|
+
if (typeof value === 'number') return value;
|
|
94
|
+
switch (String(value).toLowerCase()) {
|
|
95
|
+
case 'top': return 0;
|
|
96
|
+
case 'center': return 1;
|
|
97
|
+
case 'bottom': return 2;
|
|
98
|
+
default: return 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
/**
|
|
78
103
|
* 设置属性
|
|
79
104
|
*/
|
|
@@ -82,8 +107,8 @@ class CCLabel extends CCComponent {
|
|
|
82
107
|
if (props.fontSize !== undefined) this.setFontSize(props.fontSize);
|
|
83
108
|
if (props.lineHeight !== undefined) this._lineHeight = props.lineHeight;
|
|
84
109
|
if (props.fontFamily !== undefined) this.setFontFamily(props.fontFamily);
|
|
85
|
-
if (props.horizontalAlign !== undefined) this._N$horizontalAlign = props.horizontalAlign;
|
|
86
|
-
if (props.verticalAlign !== undefined) this._N$verticalAlign = props.verticalAlign;
|
|
110
|
+
if (props.horizontalAlign !== undefined) this._N$horizontalAlign = CCLabel.parseHAlign(props.horizontalAlign);
|
|
111
|
+
if (props.verticalAlign !== undefined) this._N$verticalAlign = CCLabel.parseVAlign(props.verticalAlign);
|
|
87
112
|
return this;
|
|
88
113
|
}
|
|
89
114
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const CCComponent = require('./CCComponent');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cocos Creator RichText 组件
|
|
5
|
+
* 支持 BBCode 标签语法:
|
|
6
|
+
* <color=#ff0000>红色</color>
|
|
7
|
+
* <size=30>大字</size>
|
|
8
|
+
* <b>加粗</b> <i>斜体</i> <u>下划线</u>
|
|
9
|
+
* <br/> 换行
|
|
10
|
+
*/
|
|
11
|
+
class CCRichText extends CCComponent {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.__type__ = 'cc.RichText';
|
|
15
|
+
|
|
16
|
+
this._string = '';
|
|
17
|
+
this._horizontalAlign = 0; // 0=LEFT 1=CENTER 2=RIGHT
|
|
18
|
+
this._fontSize = 40;
|
|
19
|
+
this._maxWidth = 0;
|
|
20
|
+
this._lineHeight = 40;
|
|
21
|
+
this._imageAtlas = null;
|
|
22
|
+
this._handleTouchEvent = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
__type__: this.__type__,
|
|
28
|
+
_name: this._name,
|
|
29
|
+
_objFlags: this._objFlags,
|
|
30
|
+
node: this.node,
|
|
31
|
+
_enabled: this._enabled,
|
|
32
|
+
_string: this._string,
|
|
33
|
+
_horizontalAlign: this._horizontalAlign,
|
|
34
|
+
_fontSize: this._fontSize,
|
|
35
|
+
_maxWidth: this._maxWidth,
|
|
36
|
+
_lineHeight: this._lineHeight,
|
|
37
|
+
_imageAtlas: this._imageAtlas,
|
|
38
|
+
_handleTouchEvent: this._handleTouchEvent,
|
|
39
|
+
_id: this._id
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = CCRichText;
|
package/src/lib/cc/CCSprite.js
CHANGED
|
@@ -16,7 +16,7 @@ class CCSprite extends CCComponent {
|
|
|
16
16
|
this._dstBlendFactor = 771;
|
|
17
17
|
this._spriteFrame = null;
|
|
18
18
|
this._type = 0;
|
|
19
|
-
this._sizeMode =
|
|
19
|
+
this._sizeMode = 0;
|
|
20
20
|
this._fillType = 0;
|
|
21
21
|
this._fillCenter = new CCVec2();
|
|
22
22
|
this._fillStart = 0;
|
|
@@ -37,7 +37,7 @@ class CCSprite extends CCComponent {
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* 设置尺寸模式
|
|
40
|
-
* 0: CUSTOM, 1:
|
|
40
|
+
* 0: CUSTOM, 1: TRIMMED, 2: RAW
|
|
41
41
|
*/
|
|
42
42
|
setSizeMode(mode) {
|
|
43
43
|
this._sizeMode = mode;
|
package/src/lib/cc/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const CCCamera = require('./CCCamera');
|
|
|
16
16
|
const CCSprite = require('./CCSprite');
|
|
17
17
|
const CCLabel = require('./CCLabel');
|
|
18
18
|
const CCButton = require('./CCButton');
|
|
19
|
+
const CCRichText = require('./CCRichText');
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
CCObject,
|
|
@@ -36,5 +37,6 @@ module.exports = {
|
|
|
36
37
|
CCCamera,
|
|
37
38
|
CCSprite,
|
|
38
39
|
CCLabel,
|
|
39
|
-
CCButton
|
|
40
|
+
CCButton,
|
|
41
|
+
CCRichText
|
|
40
42
|
};
|
package/src/lib/json-parser.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* 将简化JSON转换为CCNode对象树
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const { CCNode, CCCanvas, CCWidget, CCSprite, CCLabel, CCButton, CCCamera } = require('./cc');
|
|
6
|
+
const { CCNode, CCCanvas, CCWidget, CCSprite, CCLabel, CCButton, CCCamera, CCRichText } = require('./cc');
|
|
7
7
|
const { parseColor } = require('./utils');
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -11,13 +11,14 @@ const { parseColor } = require('./utils');
|
|
|
11
11
|
*/
|
|
12
12
|
function createComponent(type) {
|
|
13
13
|
switch (type.toLowerCase()) {
|
|
14
|
-
case 'canvas':
|
|
15
|
-
case 'widget':
|
|
16
|
-
case 'sprite':
|
|
17
|
-
case 'label':
|
|
18
|
-
case 'button':
|
|
19
|
-
case 'camera':
|
|
20
|
-
|
|
14
|
+
case 'canvas': return new CCCanvas();
|
|
15
|
+
case 'widget': return new CCWidget();
|
|
16
|
+
case 'sprite': return new CCSprite();
|
|
17
|
+
case 'label': return new CCLabel();
|
|
18
|
+
case 'button': return new CCButton();
|
|
19
|
+
case 'camera': return new CCCamera();
|
|
20
|
+
case 'richtext': return new CCRichText();
|
|
21
|
+
default: return null;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -59,7 +60,25 @@ function applyComponentProps(comp, props, node) {
|
|
|
59
60
|
case 'sizeMode':
|
|
60
61
|
if (comp._sizeMode !== undefined) comp._sizeMode = value;
|
|
61
62
|
break;
|
|
63
|
+
case 'horizontalAlign':
|
|
64
|
+
// 支持语义化字符串:left / center / right
|
|
65
|
+
if (comp._N$horizontalAlign !== undefined) {
|
|
66
|
+
comp._N$horizontalAlign = CCLabel.parseHAlign(value);
|
|
67
|
+
} else if (comp._horizontalAlign !== undefined) {
|
|
68
|
+
comp._horizontalAlign = CCLabel.parseHAlign(value);
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
case 'verticalAlign':
|
|
72
|
+
// 支持语义化字符串:top / center / bottom
|
|
73
|
+
if (comp._N$verticalAlign !== undefined) {
|
|
74
|
+
comp._N$verticalAlign = CCLabel.parseVAlign(value);
|
|
75
|
+
} else if (comp._verticalAlign !== undefined) {
|
|
76
|
+
comp._verticalAlign = CCLabel.parseVAlign(value);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
62
79
|
case 'color':
|
|
80
|
+
// 兼容写法:组件内的 color 同步到节点颜色
|
|
81
|
+
// (Cocos 中文字/富文本颜色本质是节点颜色,不是组件属性)
|
|
63
82
|
if (node) {
|
|
64
83
|
const parsed = parseColor(value);
|
|
65
84
|
if (parsed && node._color) {
|