cocos2d-cli 1.1.2 → 1.4.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.
- package/bin/{cocos-cli.js → cocos2d-cli.js} +29 -12
- package/package.json +3 -3
- package/src/commands/add-component.js +23 -54
- package/src/commands/add.js +31 -114
- package/src/commands/build.js +1 -1
- package/src/commands/create-scene.js +93 -455
- package/src/commands/get.js +5 -154
- package/src/commands/prefab-create.js +108 -368
- package/src/commands/remove.js +123 -59
- package/src/commands/set.js +12 -245
- package/src/commands/tree.js +4 -3
- package/src/lib/components/button.js +137 -0
- package/src/lib/components/camera.js +107 -0
- package/src/lib/components/canvas.js +89 -0
- package/src/lib/components/index.js +157 -0
- package/src/lib/components/label.js +120 -0
- package/src/lib/components/layout.js +110 -0
- package/src/lib/components/particle-system.js +160 -0
- package/src/lib/components/sprite.js +98 -0
- package/src/lib/components/widget.js +122 -0
- package/src/lib/fire-utils.js +58 -392
- package/src/lib/node-utils.js +359 -0
- package/src/lib/templates.js +212 -0
- package/src/lib/utils.js +139 -0
- package/src/commands/delete.js +0 -74
- package/src/commands/remove-component.js +0 -63
- package/src/lib/components.js +0 -404
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cc.ParticleSystem 组件
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { generateId } = require('../utils');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_MATERIAL = { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" };
|
|
8
|
+
const PARTICLE_FILE = { "__uuid__": "b2687ac4-099e-403c-a192-ff477686f4f5" };
|
|
9
|
+
const PARTICLE_SPRITE = { "__uuid__": "472df5d3-35e7-4184-9e6c-7f41bee65ee3" };
|
|
10
|
+
|
|
11
|
+
// 属性映射
|
|
12
|
+
const PROP_MAP = {
|
|
13
|
+
'playOnLoad': 'playOnLoad',
|
|
14
|
+
'autoRemoveOnFinish': 'autoRemoveOnFinish',
|
|
15
|
+
'totalParticles': 'totalParticles',
|
|
16
|
+
'duration': 'duration',
|
|
17
|
+
'emissionRate': 'emissionRate',
|
|
18
|
+
'life': 'life',
|
|
19
|
+
'angle': 'angle',
|
|
20
|
+
'speed': 'speed'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 创建 ParticleSystem 组件
|
|
25
|
+
* @param {number} nodeId - 节点索引
|
|
26
|
+
* @returns {object} 组件数据
|
|
27
|
+
*/
|
|
28
|
+
function create(nodeId) {
|
|
29
|
+
return {
|
|
30
|
+
"__type__": "cc.ParticleSystem",
|
|
31
|
+
"_name": "",
|
|
32
|
+
"_objFlags": 0,
|
|
33
|
+
"node": { "__id__": nodeId },
|
|
34
|
+
"_enabled": true,
|
|
35
|
+
"_materials": [DEFAULT_MATERIAL],
|
|
36
|
+
"_srcBlendFactor": 770,
|
|
37
|
+
"_dstBlendFactor": 1,
|
|
38
|
+
"_custom": false,
|
|
39
|
+
"_file": PARTICLE_FILE,
|
|
40
|
+
"_spriteFrame": PARTICLE_SPRITE,
|
|
41
|
+
"_texture": null,
|
|
42
|
+
"_stopped": true,
|
|
43
|
+
"playOnLoad": true,
|
|
44
|
+
"autoRemoveOnFinish": false,
|
|
45
|
+
"totalParticles": 200,
|
|
46
|
+
"duration": -1,
|
|
47
|
+
"emissionRate": 999.999985098839,
|
|
48
|
+
"life": 0.20000000298023224,
|
|
49
|
+
"lifeVar": 0.5,
|
|
50
|
+
"_startColor": {
|
|
51
|
+
"__type__": "cc.Color",
|
|
52
|
+
"r": 202,
|
|
53
|
+
"g": 200,
|
|
54
|
+
"b": 86,
|
|
55
|
+
"a": 163
|
|
56
|
+
},
|
|
57
|
+
"_startColorVar": {
|
|
58
|
+
"__type__": "cc.Color",
|
|
59
|
+
"r": 229,
|
|
60
|
+
"g": 255,
|
|
61
|
+
"b": 173,
|
|
62
|
+
"a": 198
|
|
63
|
+
},
|
|
64
|
+
"_endColor": {
|
|
65
|
+
"__type__": "cc.Color",
|
|
66
|
+
"r": 173,
|
|
67
|
+
"g": 161,
|
|
68
|
+
"b": 19,
|
|
69
|
+
"a": 214
|
|
70
|
+
},
|
|
71
|
+
"_endColorVar": {
|
|
72
|
+
"__type__": "cc.Color",
|
|
73
|
+
"r": 107,
|
|
74
|
+
"g": 249,
|
|
75
|
+
"b": 249,
|
|
76
|
+
"a": 188
|
|
77
|
+
},
|
|
78
|
+
"angle": 360,
|
|
79
|
+
"angleVar": 360,
|
|
80
|
+
"startSize": 3.369999885559082,
|
|
81
|
+
"startSizeVar": 50,
|
|
82
|
+
"endSize": 30.31999969482422,
|
|
83
|
+
"endSizeVar": 0,
|
|
84
|
+
"startSpin": -47.369998931884766,
|
|
85
|
+
"startSpinVar": 0,
|
|
86
|
+
"endSpin": -47.369998931884766,
|
|
87
|
+
"endSpinVar": -142.11000061035156,
|
|
88
|
+
"sourcePos": {
|
|
89
|
+
"__type__": "cc.Vec2",
|
|
90
|
+
"x": 0,
|
|
91
|
+
"y": 0
|
|
92
|
+
},
|
|
93
|
+
"posVar": {
|
|
94
|
+
"__type__": "cc.Vec2",
|
|
95
|
+
"x": 7,
|
|
96
|
+
"y": 7
|
|
97
|
+
},
|
|
98
|
+
"_positionType": 1,
|
|
99
|
+
"positionType": 1,
|
|
100
|
+
"emitterMode": 0,
|
|
101
|
+
"gravity": {
|
|
102
|
+
"__type__": "cc.Vec2",
|
|
103
|
+
"x": 0.25,
|
|
104
|
+
"y": 0.8600000143051147
|
|
105
|
+
},
|
|
106
|
+
"speed": 0,
|
|
107
|
+
"speedVar": 190.7899932861328,
|
|
108
|
+
"tangentialAccel": -92.11000061035156,
|
|
109
|
+
"tangentialAccelVar": 65.79000091552734,
|
|
110
|
+
"radialAccel": -671.0499877929688,
|
|
111
|
+
"radialAccelVar": 65.79000091552734,
|
|
112
|
+
"rotationIsDir": false,
|
|
113
|
+
"startRadius": 0,
|
|
114
|
+
"startRadiusVar": 0,
|
|
115
|
+
"endRadius": 0,
|
|
116
|
+
"endRadiusVar": 0,
|
|
117
|
+
"rotatePerS": 0,
|
|
118
|
+
"rotatePerSVar": 0,
|
|
119
|
+
"_N$preview": true,
|
|
120
|
+
"_id": generateId()
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 应用属性
|
|
126
|
+
* @param {object} comp - 组件对象
|
|
127
|
+
* @param {object} props - 属性对象
|
|
128
|
+
*/
|
|
129
|
+
function applyProps(comp, props) {
|
|
130
|
+
if (!props) return;
|
|
131
|
+
|
|
132
|
+
for (const [key, value] of Object.entries(props)) {
|
|
133
|
+
const compKey = PROP_MAP[key];
|
|
134
|
+
if (compKey) {
|
|
135
|
+
comp[compKey] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 提取属性(用于显示)
|
|
142
|
+
* @param {object} comp - 组件对象
|
|
143
|
+
* @returns {object} 提取的属性
|
|
144
|
+
*/
|
|
145
|
+
function extractProps(comp) {
|
|
146
|
+
return {
|
|
147
|
+
playOnLoad: comp.playOnLoad,
|
|
148
|
+
totalParticles: comp.totalParticles,
|
|
149
|
+
duration: comp.duration
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = {
|
|
154
|
+
type: 'particleSystem',
|
|
155
|
+
ccType: 'cc.ParticleSystem',
|
|
156
|
+
create,
|
|
157
|
+
applyProps,
|
|
158
|
+
extractProps,
|
|
159
|
+
PROP_MAP
|
|
160
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cc.Sprite 组件
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { generateId } = require('../utils');
|
|
6
|
+
|
|
7
|
+
const DEFAULT_MATERIAL = { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" };
|
|
8
|
+
const SPLASH_SPRITE_FRAME = { "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" };
|
|
9
|
+
|
|
10
|
+
// 属性映射
|
|
11
|
+
const PROP_MAP = {
|
|
12
|
+
'sizeMode': '_sizeMode',
|
|
13
|
+
'fillType': '_fillType',
|
|
14
|
+
'fillCenter': '_fillCenter',
|
|
15
|
+
'fillStart': '_fillStart',
|
|
16
|
+
'fillRange': '_fillRange',
|
|
17
|
+
'trim': '_isTrimmedMode',
|
|
18
|
+
'spriteFrame': '_spriteFrame',
|
|
19
|
+
'type': '_type'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 枚举值
|
|
23
|
+
const ENUMS = {
|
|
24
|
+
sizeMode: ['CUSTOM', 'TRIMMED', 'RAW'],
|
|
25
|
+
spriteType: ['SIMPLE', 'SLICED', 'TILED', 'FILLED', 'MESH']
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 创建 Sprite 组件
|
|
30
|
+
* @param {number} nodeId - 节点索引
|
|
31
|
+
* @returns {object} 组件数据
|
|
32
|
+
*/
|
|
33
|
+
function create(nodeId) {
|
|
34
|
+
return {
|
|
35
|
+
"__type__": "cc.Sprite",
|
|
36
|
+
"_name": "",
|
|
37
|
+
"_objFlags": 0,
|
|
38
|
+
"node": { "__id__": nodeId },
|
|
39
|
+
"_enabled": true,
|
|
40
|
+
"_materials": [DEFAULT_MATERIAL],
|
|
41
|
+
"_srcBlendFactor": 770,
|
|
42
|
+
"_dstBlendFactor": 771,
|
|
43
|
+
"_spriteFrame": SPLASH_SPRITE_FRAME,
|
|
44
|
+
"_type": 0,
|
|
45
|
+
"_sizeMode": 0,
|
|
46
|
+
"_fillType": 0,
|
|
47
|
+
"_fillCenter": { "__type__": "cc.Vec2", "x": 0, "y": 0 },
|
|
48
|
+
"_fillStart": 0,
|
|
49
|
+
"_fillRange": 0,
|
|
50
|
+
"_isTrimmedMode": true,
|
|
51
|
+
"_atlas": null,
|
|
52
|
+
"_id": generateId()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 应用属性
|
|
58
|
+
* @param {object} comp - 组件对象
|
|
59
|
+
* @param {object} props - 属性对象
|
|
60
|
+
*/
|
|
61
|
+
function applyProps(comp, props) {
|
|
62
|
+
if (!props) return;
|
|
63
|
+
|
|
64
|
+
for (const [key, value] of Object.entries(props)) {
|
|
65
|
+
const compKey = PROP_MAP[key];
|
|
66
|
+
if (compKey) {
|
|
67
|
+
if (key === 'fillCenter' && Array.isArray(value)) {
|
|
68
|
+
comp[compKey] = { "__type__": "cc.Vec2", "x": value[0], "y": value[1] };
|
|
69
|
+
} else {
|
|
70
|
+
comp[compKey] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 提取属性(用于显示)
|
|
78
|
+
* @param {object} comp - 组件对象
|
|
79
|
+
* @returns {object} 提取的属性
|
|
80
|
+
*/
|
|
81
|
+
function extractProps(comp) {
|
|
82
|
+
return {
|
|
83
|
+
spriteFrame: comp._spriteFrame?.__uuid__ || null,
|
|
84
|
+
sizeMode: ENUMS.sizeMode[comp._sizeMode] || comp._sizeMode,
|
|
85
|
+
spriteType: ENUMS.spriteType[comp._type] || comp._type,
|
|
86
|
+
trim: comp._isTrimmedMode
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = {
|
|
91
|
+
type: 'sprite',
|
|
92
|
+
ccType: 'cc.Sprite',
|
|
93
|
+
create,
|
|
94
|
+
applyProps,
|
|
95
|
+
extractProps,
|
|
96
|
+
PROP_MAP,
|
|
97
|
+
ENUMS
|
|
98
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cc.Widget 组件
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { generateId } = require('../utils');
|
|
6
|
+
|
|
7
|
+
// 属性映射
|
|
8
|
+
const PROP_MAP = {
|
|
9
|
+
'left': '_left',
|
|
10
|
+
'right': '_right',
|
|
11
|
+
'top': '_top',
|
|
12
|
+
'bottom': '_bottom',
|
|
13
|
+
'horizontalCenter': '_horizontalCenter',
|
|
14
|
+
'verticalCenter': '_verticalCenter',
|
|
15
|
+
'isAbsLeft': '_isAbsLeft',
|
|
16
|
+
'isAbsRight': '_isAbsRight',
|
|
17
|
+
'isAbsTop': '_isAbsTop',
|
|
18
|
+
'isAbsBottom': '_isAbsBottom',
|
|
19
|
+
'alignMode': 'alignMode'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 对齐方向位掩码
|
|
23
|
+
const ALIGN_FLAGS = {
|
|
24
|
+
top: 1,
|
|
25
|
+
verticalCenter: 2,
|
|
26
|
+
bottom: 4,
|
|
27
|
+
left: 8,
|
|
28
|
+
horizontalCenter: 16,
|
|
29
|
+
right: 32
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 枚举值
|
|
33
|
+
const ENUMS = {
|
|
34
|
+
alignMode: ['ONCE', 'ON_WINDOW_RESIZE', 'ALWAYS']
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 创建 Widget 组件
|
|
39
|
+
* @param {number} nodeId - 节点索引
|
|
40
|
+
* @returns {object} 组件数据
|
|
41
|
+
*/
|
|
42
|
+
function create(nodeId) {
|
|
43
|
+
return {
|
|
44
|
+
"__type__": "cc.Widget",
|
|
45
|
+
"_name": "",
|
|
46
|
+
"_objFlags": 0,
|
|
47
|
+
"node": { "__id__": nodeId },
|
|
48
|
+
"_enabled": true,
|
|
49
|
+
"alignMode": 1,
|
|
50
|
+
"_target": null,
|
|
51
|
+
"_alignFlags": 0,
|
|
52
|
+
"_left": 0,
|
|
53
|
+
"_right": 0,
|
|
54
|
+
"_top": 0,
|
|
55
|
+
"_bottom": 0,
|
|
56
|
+
"_verticalCenter": 0,
|
|
57
|
+
"_horizontalCenter": 0,
|
|
58
|
+
"_isAbsLeft": true,
|
|
59
|
+
"_isAbsRight": true,
|
|
60
|
+
"_isAbsTop": true,
|
|
61
|
+
"_isAbsBottom": true,
|
|
62
|
+
"_isAbsHorizontalCenter": true,
|
|
63
|
+
"_isAbsVerticalCenter": true,
|
|
64
|
+
"_originalWidth": 0,
|
|
65
|
+
"_originalHeight": 0,
|
|
66
|
+
"_id": generateId()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 应用属性
|
|
72
|
+
* @param {object} comp - 组件对象
|
|
73
|
+
* @param {object} props - 属性对象
|
|
74
|
+
*/
|
|
75
|
+
function applyProps(comp, props) {
|
|
76
|
+
if (!props) return;
|
|
77
|
+
|
|
78
|
+
// 计算对齐标志
|
|
79
|
+
let alignFlags = 0;
|
|
80
|
+
for (const dir of ['top', 'bottom', 'left', 'right', 'horizontalCenter', 'verticalCenter']) {
|
|
81
|
+
if (props[dir] !== undefined && props[dir] !== null) {
|
|
82
|
+
alignFlags |= ALIGN_FLAGS[dir];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (alignFlags > 0) {
|
|
86
|
+
comp._alignFlags = alignFlags;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 应用其他属性
|
|
90
|
+
for (const [key, value] of Object.entries(props)) {
|
|
91
|
+
const compKey = PROP_MAP[key];
|
|
92
|
+
if (compKey) {
|
|
93
|
+
comp[compKey] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 提取属性(用于显示)
|
|
100
|
+
* @param {object} comp - 组件对象
|
|
101
|
+
* @returns {object} 提取的属性
|
|
102
|
+
*/
|
|
103
|
+
function extractProps(comp) {
|
|
104
|
+
return {
|
|
105
|
+
alignMode: ENUMS.alignMode[comp.alignMode] || comp.alignMode,
|
|
106
|
+
left: comp._left,
|
|
107
|
+
right: comp._right,
|
|
108
|
+
top: comp._top,
|
|
109
|
+
bottom: comp._bottom
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
type: 'widget',
|
|
115
|
+
ccType: 'cc.Widget',
|
|
116
|
+
create,
|
|
117
|
+
applyProps,
|
|
118
|
+
extractProps,
|
|
119
|
+
PROP_MAP,
|
|
120
|
+
ENUMS,
|
|
121
|
+
ALIGN_FLAGS
|
|
122
|
+
};
|