cocos2d-cli 1.6.1 → 1.6.3
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/README.md +429 -80
- package/bin/cocos2d-cli.js +11 -31
- package/package.json +3 -3
- package/src/commands/screenshot.js +17 -9
- 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 +78 -53
|
@@ -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') {
|
|
@@ -84,10 +89,13 @@ async function run(args) {
|
|
|
84
89
|
options.outputDir = path.resolve(options.outputDir);
|
|
85
90
|
|
|
86
91
|
try {
|
|
87
|
-
|
|
88
|
-
console.log(
|
|
92
|
+
await takeScreenshot(options);
|
|
93
|
+
console.log('成功');
|
|
89
94
|
} catch (error) {
|
|
90
|
-
console.error(
|
|
95
|
+
console.error('失败');
|
|
96
|
+
if (error.logDir) {
|
|
97
|
+
console.error(`日志目录: ${error.logDir}`);
|
|
98
|
+
}
|
|
91
99
|
process.exit(1);
|
|
92
100
|
}
|
|
93
101
|
}
|
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) {
|