cocos2d-cli 1.1.2 → 1.2.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 +15 -3
- package/package.json +1 -1
- package/src/commands/create-scene.js +14 -2
- package/src/commands/prefab-create.js +14 -2
package/bin/cocos-cli.js
CHANGED
|
@@ -78,7 +78,21 @@ JSON 格式 (create-prefab / create-scene):
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
节点属性: name, width, height, x, y, color, opacity, anchorX, anchorY, rotation, scaleX, scaleY, active
|
|
81
|
-
|
|
81
|
+
|
|
82
|
+
组件类型:
|
|
83
|
+
sprite - 精灵���默认白色方块,节点设置什么颜色就显示什么颜色
|
|
84
|
+
label - 文本,支持 string, fontSize, color(兼容)
|
|
85
|
+
button - 按钮,通常配合 sprite 使用才能看见
|
|
86
|
+
widget - 对齐,支持 top, bottom, left, right
|
|
87
|
+
layout - 布局,自动排列子节点
|
|
88
|
+
canvas - 画布,根节点使用
|
|
89
|
+
camera - 相机
|
|
90
|
+
particle - 粒子效果
|
|
91
|
+
|
|
92
|
+
注意:
|
|
93
|
+
- color 写在节点或 label 组件均可
|
|
94
|
+
- button 需要配合 sprite 才能看见按钮外观
|
|
95
|
+
- 必须通过 JSON 文件输入: type panel.json | cocos2d-cli create-prefab xxx.prefab
|
|
82
96
|
|
|
83
97
|
示例:
|
|
84
98
|
cocos2d-cli tree assets/main.fire
|
|
@@ -91,8 +105,6 @@ JSON 格式 (create-prefab / create-scene):
|
|
|
91
105
|
|
|
92
106
|
# 从 JSON 创建预制体
|
|
93
107
|
type panel.json | cocos2d-cli create-prefab assets/panel.prefab
|
|
94
|
-
|
|
95
|
-
版本: 1.1.0
|
|
96
108
|
`);
|
|
97
109
|
}
|
|
98
110
|
|
package/package.json
CHANGED
|
@@ -96,12 +96,24 @@ function parseComponent(compDef) {
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* 应用组件属性
|
|
99
|
+
* @param comp 组件对象
|
|
100
|
+
* @param props 属性对象
|
|
101
|
+
* @param node 节点对象(可选,用于 label 的 color 设置到节点)
|
|
99
102
|
*/
|
|
100
|
-
function applyComponentProps(comp, props) {
|
|
103
|
+
function applyComponentProps(comp, props, node) {
|
|
101
104
|
if (!props || !comp) return;
|
|
102
105
|
|
|
103
106
|
const type = comp.__type__;
|
|
104
107
|
|
|
108
|
+
// Label 的 color 属性应该设置到节点上
|
|
109
|
+
if (type === 'cc.Label' && props.color && node) {
|
|
110
|
+
const parsed = parseColor(props.color);
|
|
111
|
+
if (parsed) {
|
|
112
|
+
node._color = { "__type__": "cc.Color", ...parsed };
|
|
113
|
+
}
|
|
114
|
+
delete props.color; // 不再在组件中处理
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
// Widget 特殊处理:根据设置的方向计算 alignFlags
|
|
106
118
|
if (type === 'cc.Widget') {
|
|
107
119
|
const ALIGN = {
|
|
@@ -425,7 +437,7 @@ function createSceneData(nodeDefs, sceneName) {
|
|
|
425
437
|
for (const { type, props } of compList) {
|
|
426
438
|
if (Components[type]) {
|
|
427
439
|
const comp = Components[type](nodeIndex);
|
|
428
|
-
applyComponentProps(comp, props);
|
|
440
|
+
applyComponentProps(comp, props, node);
|
|
429
441
|
const compIndex = data.length;
|
|
430
442
|
data.push(comp);
|
|
431
443
|
node._components.push({ "__id__": compIndex });
|
|
@@ -98,12 +98,24 @@ function parseComponent(compDef) {
|
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* 应用组件属性
|
|
101
|
+
* @param comp 组件对象
|
|
102
|
+
* @param props 属性对象
|
|
103
|
+
* @param node 节点对象(可选,用于 label 的 color 设置到节点)
|
|
101
104
|
*/
|
|
102
|
-
function applyComponentProps(comp, props) {
|
|
105
|
+
function applyComponentProps(comp, props, node) {
|
|
103
106
|
if (!props || !comp) return;
|
|
104
107
|
|
|
105
108
|
const type = comp.__type__;
|
|
106
109
|
|
|
110
|
+
// Label 的 color 属性应该设置到节点上
|
|
111
|
+
if (type === 'cc.Label' && props.color && node) {
|
|
112
|
+
const parsed = parseColor(props.color);
|
|
113
|
+
if (parsed) {
|
|
114
|
+
node._color = { "__type__": "cc.Color", ...parsed };
|
|
115
|
+
}
|
|
116
|
+
delete props.color; // 不再在组件中处理
|
|
117
|
+
}
|
|
118
|
+
|
|
107
119
|
// Widget 特殊处理:根据设置的方向计算 alignFlags
|
|
108
120
|
// 位掩码定义 (来自 Cocos Creator 源码)
|
|
109
121
|
// TOP=1, MID(verticalCenter)=2, BOT=4, LEFT=8, CENTER(horizontalCenter)=16, RIGHT=32
|
|
@@ -334,7 +346,7 @@ function createPrefabData(nodeDef) {
|
|
|
334
346
|
if (Components[type]) {
|
|
335
347
|
const comp = Components[type](nodeIndex);
|
|
336
348
|
// 应用组件属性
|
|
337
|
-
applyComponentProps(comp, props);
|
|
349
|
+
applyComponentProps(comp, props, node);
|
|
338
350
|
const compIndex = data.length;
|
|
339
351
|
data.push(comp);
|
|
340
352
|
node._components.push({ "__id__": compIndex });
|