cocos2d-cli 1.6.3 → 1.6.5
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 +152 -152
- package/data/script_map.json +25 -25
- package/package.json +33 -33
- package/src/commands/add-component.js +112 -112
- package/src/commands/add.js +177 -177
- package/src/commands/build.js +78 -78
- package/src/commands/create-scene.js +181 -181
- package/src/commands/get.js +108 -108
- package/src/commands/prefab-create.js +110 -110
- package/src/commands/remove-component.js +110 -110
- package/src/commands/remove.js +99 -99
- package/src/commands/screenshot.js +108 -103
- package/src/commands/set-component.js +119 -119
- package/src/commands/set.js +107 -107
- package/src/commands/tree.js +28 -28
- package/src/lib/cc/CCButton.js +122 -122
- package/src/lib/cc/CCCamera.js +93 -93
- package/src/lib/cc/CCCanvas.js +54 -54
- package/src/lib/cc/CCColor.js +32 -32
- package/src/lib/cc/CCComponent.js +60 -60
- package/src/lib/cc/CCLabel.js +146 -146
- package/src/lib/cc/CCNode.js +255 -255
- package/src/lib/cc/CCObject.js +23 -23
- package/src/lib/cc/CCPrefab.js +242 -242
- package/src/lib/cc/CCRect.js +32 -32
- package/src/lib/cc/CCRichText.js +44 -44
- package/src/lib/cc/CCScene.js +42 -42
- package/src/lib/cc/CCSceneAsset.js +302 -302
- package/src/lib/cc/CCSize.js +26 -26
- package/src/lib/cc/CCSprite.js +94 -94
- package/src/lib/cc/CCTrs.js +74 -74
- package/src/lib/cc/CCVec2.js +26 -26
- package/src/lib/cc/CCVec3.js +29 -29
- package/src/lib/cc/CCWidget.js +98 -98
- package/src/lib/cc/index.js +42 -42
- package/src/lib/fire-utils.js +373 -373
- package/src/lib/json-parser.js +185 -185
- package/src/lib/node-utils.js +395 -395
- package/src/lib/screenshot/index.html +29 -29
- package/src/lib/screenshot-core.js +285 -286
- package/src/lib/templates.js +49 -49
- package/src/lib/utils.js +202 -202
package/src/lib/cc/CCNode.js
CHANGED
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
const CCObject = require('./CCObject');
|
|
2
|
-
const CCColor = require('./CCColor');
|
|
3
|
-
const CCSize = require('./CCSize');
|
|
4
|
-
const CCVec2 = require('./CCVec2');
|
|
5
|
-
const CCVec3 = require('./CCVec3');
|
|
6
|
-
const CCTrs = require('./CCTrs');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Cocos Creator 节点类
|
|
10
|
-
*/
|
|
11
|
-
class CCNode extends CCObject {
|
|
12
|
-
constructor(name = 'Node') {
|
|
13
|
-
super(name);
|
|
14
|
-
this.__type__ = 'cc.Node';
|
|
15
|
-
|
|
16
|
-
// 父子关系
|
|
17
|
-
this._parent = null;
|
|
18
|
-
this._children = [];
|
|
19
|
-
|
|
20
|
-
// 激活状态
|
|
21
|
-
this._active = true;
|
|
22
|
-
|
|
23
|
-
// 组件列表
|
|
24
|
-
this._components = [];
|
|
25
|
-
|
|
26
|
-
// 预制体信息
|
|
27
|
-
this._prefab = null;
|
|
28
|
-
|
|
29
|
-
// 显示属性
|
|
30
|
-
this._opacity = 255;
|
|
31
|
-
this._color = new CCColor();
|
|
32
|
-
this._contentSize = new CCSize();
|
|
33
|
-
this._anchorPoint = new CCVec2(0.5, 0.5);
|
|
34
|
-
|
|
35
|
-
// 变换属性
|
|
36
|
-
this._trs = new CCTrs();
|
|
37
|
-
this._eulerAngles = new CCVec3();
|
|
38
|
-
this._skewX = 0;
|
|
39
|
-
this._skewY = 0;
|
|
40
|
-
this._is3DNode = false;
|
|
41
|
-
|
|
42
|
-
// 分组
|
|
43
|
-
this._groupIndex = 0;
|
|
44
|
-
this.groupIndex = 0;
|
|
45
|
-
|
|
46
|
-
// 唯一标识(预制体中为空,场景中生成)
|
|
47
|
-
this._id = '';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 设置 ID
|
|
52
|
-
*/
|
|
53
|
-
setId(id) {
|
|
54
|
-
this._id = id;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Position getters/setters
|
|
59
|
-
get x() { return this._trs.x; }
|
|
60
|
-
set x(v) { this._trs.x = v; }
|
|
61
|
-
|
|
62
|
-
get y() { return this._trs.y; }
|
|
63
|
-
set y(v) { this._trs.y = v; }
|
|
64
|
-
|
|
65
|
-
// Scale getters/setters
|
|
66
|
-
get scaleX() { return this._trs.scaleX; }
|
|
67
|
-
set scaleX(v) { this._trs.scaleX = v; }
|
|
68
|
-
|
|
69
|
-
get scaleY() { return this._trs.scaleY; }
|
|
70
|
-
set scaleY(v) { this._trs.scaleY = v; }
|
|
71
|
-
|
|
72
|
-
// Size getters/setters
|
|
73
|
-
get width() { return this._contentSize.width; }
|
|
74
|
-
set width(v) { this._contentSize.width = v; }
|
|
75
|
-
|
|
76
|
-
get height() { return this._contentSize.height; }
|
|
77
|
-
set height(v) { this._contentSize.height = v; }
|
|
78
|
-
|
|
79
|
-
// Anchor getters/setters
|
|
80
|
-
get anchorX() { return this._anchorPoint.x; }
|
|
81
|
-
set anchorX(v) { this._anchorPoint.x = v; }
|
|
82
|
-
|
|
83
|
-
get anchorY() { return this._anchorPoint.y; }
|
|
84
|
-
set anchorY(v) { this._anchorPoint.y = v; }
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 设置位置
|
|
88
|
-
*/
|
|
89
|
-
setPosition(x, y) {
|
|
90
|
-
this._trs.setPosition(x, y);
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 设置大小
|
|
96
|
-
*/
|
|
97
|
-
setContentSize(width, height) {
|
|
98
|
-
this._contentSize.set(width, height);
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 设置锚点
|
|
104
|
-
*/
|
|
105
|
-
setAnchorPoint(x, y) {
|
|
106
|
-
this._anchorPoint.set(x, y);
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 设置缩放
|
|
112
|
-
*/
|
|
113
|
-
setScale(x, y = x) {
|
|
114
|
-
this._trs.setScale(x, y);
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 设置旋转(角度)
|
|
120
|
-
*/
|
|
121
|
-
setRotation(angle) {
|
|
122
|
-
this._trs.rotZ = angle * Math.PI / 180;
|
|
123
|
-
this._eulerAngles.z = angle;
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 设置颜色
|
|
129
|
-
*/
|
|
130
|
-
setColor(r, g, b, a = 255) {
|
|
131
|
-
this._color.set(r, g, b, a);
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 设置透明度
|
|
137
|
-
*/
|
|
138
|
-
setOpacity(opacity) {
|
|
139
|
-
this._opacity = opacity;
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 设置激活状态
|
|
145
|
-
*/
|
|
146
|
-
setActive(active) {
|
|
147
|
-
this._active = active;
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 设置父节点
|
|
153
|
-
* @param {CCNode|number} parent - 父节点对象或索引
|
|
154
|
-
*/
|
|
155
|
-
setParent(parent) {
|
|
156
|
-
this._parent = typeof parent === 'number' ? { __id__: parent } : parent;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* 添加子节点
|
|
162
|
-
* @param {CCNode|number} child - 子节点对象或索引
|
|
163
|
-
*/
|
|
164
|
-
addChild(child) {
|
|
165
|
-
this._children.push(typeof child === 'number' ? { __id__: child } : child);
|
|
166
|
-
return this;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* 添加组件
|
|
171
|
-
* @param {CCComponent|number} comp - 组件对象或索引
|
|
172
|
-
*/
|
|
173
|
-
addComponent(comp) {
|
|
174
|
-
this._components.push(typeof comp === 'number' ? { __id__: comp } : comp);
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 获取属性
|
|
180
|
-
*/
|
|
181
|
-
getProp() {
|
|
182
|
-
const trs = this._trs?.array || [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
|
|
183
|
-
const result = {
|
|
184
|
-
name: this._name,
|
|
185
|
-
active: this._active,
|
|
186
|
-
x: trs[0],
|
|
187
|
-
y: trs[1],
|
|
188
|
-
width: this._contentSize?.width ?? 0,
|
|
189
|
-
height: this._contentSize?.height ?? 0,
|
|
190
|
-
anchorX: this._anchorPoint?.x ?? 0.5,
|
|
191
|
-
anchorY: this._anchorPoint?.y ?? 0.5,
|
|
192
|
-
scaleX: trs[7],
|
|
193
|
-
scaleY: trs[8],
|
|
194
|
-
rotation: this._eulerAngles?.z ?? 0,
|
|
195
|
-
opacity: this._opacity ?? 255,
|
|
196
|
-
color: this._color ? `#${this._color.r.toString(16).padStart(2, '0')}${this._color.g.toString(16).padStart(2, '0')}${this._color.b.toString(16).padStart(2, '0')}` : '#ffffff'
|
|
197
|
-
};
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 设置属性
|
|
203
|
-
*/
|
|
204
|
-
setProp(props) {
|
|
205
|
-
if (props.name !== undefined) this._name = props.name;
|
|
206
|
-
if (props.active !== undefined) this._active = props.active;
|
|
207
|
-
if (props.x !== undefined) this._trs.array[0] = props.x;
|
|
208
|
-
if (props.y !== undefined) this._trs.array[1] = props.y;
|
|
209
|
-
if (props.width !== undefined) this._contentSize.width = props.width;
|
|
210
|
-
if (props.height !== undefined) this._contentSize.height = props.height;
|
|
211
|
-
if (props.anchorX !== undefined) this._anchorPoint.x = props.anchorX;
|
|
212
|
-
if (props.anchorY !== undefined) this._anchorPoint.y = props.anchorY;
|
|
213
|
-
if (props.scaleX !== undefined) this._trs.array[7] = props.scaleX;
|
|
214
|
-
if (props.scaleY !== undefined) this._trs.array[8] = props.scaleY;
|
|
215
|
-
if (props.rotation !== undefined) {
|
|
216
|
-
this._trs.array[5] = props.rotation * Math.PI / 180;
|
|
217
|
-
this._eulerAngles.z = props.rotation;
|
|
218
|
-
}
|
|
219
|
-
if (props.opacity !== undefined) this._opacity = props.opacity;
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
toJSON(indexMap) {
|
|
224
|
-
// 处理引用
|
|
225
|
-
const parent = this._parent ? (indexMap ? { __id__: indexMap.get(this._parent) } : this._parent) : null;
|
|
226
|
-
const children = indexMap ? this._children.map(c => ({ __id__: indexMap.get(c) })) : this._children;
|
|
227
|
-
const components = indexMap ? this._components.map(c => ({ __id__: indexMap.get(c) })) : this._components;
|
|
228
|
-
const prefab = this._prefab ? (indexMap ? { __id__: indexMap.get(this._prefab) } : this._prefab) : null;
|
|
229
|
-
|
|
230
|
-
// 显式控制属性顺序
|
|
231
|
-
return {
|
|
232
|
-
__type__: this.__type__,
|
|
233
|
-
_name: this._name,
|
|
234
|
-
_objFlags: this._objFlags,
|
|
235
|
-
_parent: parent,
|
|
236
|
-
_children: children,
|
|
237
|
-
_active: this._active,
|
|
238
|
-
_components: components,
|
|
239
|
-
_prefab: prefab,
|
|
240
|
-
_opacity: this._opacity,
|
|
241
|
-
_color: this._color.toJSON(),
|
|
242
|
-
_contentSize: this._contentSize.toJSON(),
|
|
243
|
-
_anchorPoint: this._anchorPoint.toJSON(),
|
|
244
|
-
_trs: this._trs.toJSON(),
|
|
245
|
-
_eulerAngles: this._eulerAngles.toJSON(),
|
|
246
|
-
_skewX: this._skewX,
|
|
247
|
-
_skewY: this._skewY,
|
|
248
|
-
_is3DNode: this._is3DNode,
|
|
249
|
-
_groupIndex: this._groupIndex,
|
|
250
|
-
groupIndex: this.groupIndex,
|
|
251
|
-
_id: this._id
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
1
|
+
const CCObject = require('./CCObject');
|
|
2
|
+
const CCColor = require('./CCColor');
|
|
3
|
+
const CCSize = require('./CCSize');
|
|
4
|
+
const CCVec2 = require('./CCVec2');
|
|
5
|
+
const CCVec3 = require('./CCVec3');
|
|
6
|
+
const CCTrs = require('./CCTrs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Cocos Creator 节点类
|
|
10
|
+
*/
|
|
11
|
+
class CCNode extends CCObject {
|
|
12
|
+
constructor(name = 'Node') {
|
|
13
|
+
super(name);
|
|
14
|
+
this.__type__ = 'cc.Node';
|
|
15
|
+
|
|
16
|
+
// 父子关系
|
|
17
|
+
this._parent = null;
|
|
18
|
+
this._children = [];
|
|
19
|
+
|
|
20
|
+
// 激活状态
|
|
21
|
+
this._active = true;
|
|
22
|
+
|
|
23
|
+
// 组件列表
|
|
24
|
+
this._components = [];
|
|
25
|
+
|
|
26
|
+
// 预制体信息
|
|
27
|
+
this._prefab = null;
|
|
28
|
+
|
|
29
|
+
// 显示属性
|
|
30
|
+
this._opacity = 255;
|
|
31
|
+
this._color = new CCColor();
|
|
32
|
+
this._contentSize = new CCSize();
|
|
33
|
+
this._anchorPoint = new CCVec2(0.5, 0.5);
|
|
34
|
+
|
|
35
|
+
// 变换属性
|
|
36
|
+
this._trs = new CCTrs();
|
|
37
|
+
this._eulerAngles = new CCVec3();
|
|
38
|
+
this._skewX = 0;
|
|
39
|
+
this._skewY = 0;
|
|
40
|
+
this._is3DNode = false;
|
|
41
|
+
|
|
42
|
+
// 分组
|
|
43
|
+
this._groupIndex = 0;
|
|
44
|
+
this.groupIndex = 0;
|
|
45
|
+
|
|
46
|
+
// 唯一标识(预制体中为空,场景中生成)
|
|
47
|
+
this._id = '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 设置 ID
|
|
52
|
+
*/
|
|
53
|
+
setId(id) {
|
|
54
|
+
this._id = id;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Position getters/setters
|
|
59
|
+
get x() { return this._trs.x; }
|
|
60
|
+
set x(v) { this._trs.x = v; }
|
|
61
|
+
|
|
62
|
+
get y() { return this._trs.y; }
|
|
63
|
+
set y(v) { this._trs.y = v; }
|
|
64
|
+
|
|
65
|
+
// Scale getters/setters
|
|
66
|
+
get scaleX() { return this._trs.scaleX; }
|
|
67
|
+
set scaleX(v) { this._trs.scaleX = v; }
|
|
68
|
+
|
|
69
|
+
get scaleY() { return this._trs.scaleY; }
|
|
70
|
+
set scaleY(v) { this._trs.scaleY = v; }
|
|
71
|
+
|
|
72
|
+
// Size getters/setters
|
|
73
|
+
get width() { return this._contentSize.width; }
|
|
74
|
+
set width(v) { this._contentSize.width = v; }
|
|
75
|
+
|
|
76
|
+
get height() { return this._contentSize.height; }
|
|
77
|
+
set height(v) { this._contentSize.height = v; }
|
|
78
|
+
|
|
79
|
+
// Anchor getters/setters
|
|
80
|
+
get anchorX() { return this._anchorPoint.x; }
|
|
81
|
+
set anchorX(v) { this._anchorPoint.x = v; }
|
|
82
|
+
|
|
83
|
+
get anchorY() { return this._anchorPoint.y; }
|
|
84
|
+
set anchorY(v) { this._anchorPoint.y = v; }
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 设置位置
|
|
88
|
+
*/
|
|
89
|
+
setPosition(x, y) {
|
|
90
|
+
this._trs.setPosition(x, y);
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 设置大小
|
|
96
|
+
*/
|
|
97
|
+
setContentSize(width, height) {
|
|
98
|
+
this._contentSize.set(width, height);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 设置锚点
|
|
104
|
+
*/
|
|
105
|
+
setAnchorPoint(x, y) {
|
|
106
|
+
this._anchorPoint.set(x, y);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 设置缩放
|
|
112
|
+
*/
|
|
113
|
+
setScale(x, y = x) {
|
|
114
|
+
this._trs.setScale(x, y);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 设置旋转(角度)
|
|
120
|
+
*/
|
|
121
|
+
setRotation(angle) {
|
|
122
|
+
this._trs.rotZ = angle * Math.PI / 180;
|
|
123
|
+
this._eulerAngles.z = angle;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 设置颜色
|
|
129
|
+
*/
|
|
130
|
+
setColor(r, g, b, a = 255) {
|
|
131
|
+
this._color.set(r, g, b, a);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 设置透明度
|
|
137
|
+
*/
|
|
138
|
+
setOpacity(opacity) {
|
|
139
|
+
this._opacity = opacity;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 设置激活状态
|
|
145
|
+
*/
|
|
146
|
+
setActive(active) {
|
|
147
|
+
this._active = active;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 设置父节点
|
|
153
|
+
* @param {CCNode|number} parent - 父节点对象或索引
|
|
154
|
+
*/
|
|
155
|
+
setParent(parent) {
|
|
156
|
+
this._parent = typeof parent === 'number' ? { __id__: parent } : parent;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* 添加子节点
|
|
162
|
+
* @param {CCNode|number} child - 子节点对象或索引
|
|
163
|
+
*/
|
|
164
|
+
addChild(child) {
|
|
165
|
+
this._children.push(typeof child === 'number' ? { __id__: child } : child);
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* 添加组件
|
|
171
|
+
* @param {CCComponent|number} comp - 组件对象或索引
|
|
172
|
+
*/
|
|
173
|
+
addComponent(comp) {
|
|
174
|
+
this._components.push(typeof comp === 'number' ? { __id__: comp } : comp);
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 获取属性
|
|
180
|
+
*/
|
|
181
|
+
getProp() {
|
|
182
|
+
const trs = this._trs?.array || [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
|
|
183
|
+
const result = {
|
|
184
|
+
name: this._name,
|
|
185
|
+
active: this._active,
|
|
186
|
+
x: trs[0],
|
|
187
|
+
y: trs[1],
|
|
188
|
+
width: this._contentSize?.width ?? 0,
|
|
189
|
+
height: this._contentSize?.height ?? 0,
|
|
190
|
+
anchorX: this._anchorPoint?.x ?? 0.5,
|
|
191
|
+
anchorY: this._anchorPoint?.y ?? 0.5,
|
|
192
|
+
scaleX: trs[7],
|
|
193
|
+
scaleY: trs[8],
|
|
194
|
+
rotation: this._eulerAngles?.z ?? 0,
|
|
195
|
+
opacity: this._opacity ?? 255,
|
|
196
|
+
color: this._color ? `#${this._color.r.toString(16).padStart(2, '0')}${this._color.g.toString(16).padStart(2, '0')}${this._color.b.toString(16).padStart(2, '0')}` : '#ffffff'
|
|
197
|
+
};
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 设置属性
|
|
203
|
+
*/
|
|
204
|
+
setProp(props) {
|
|
205
|
+
if (props.name !== undefined) this._name = props.name;
|
|
206
|
+
if (props.active !== undefined) this._active = props.active;
|
|
207
|
+
if (props.x !== undefined) this._trs.array[0] = props.x;
|
|
208
|
+
if (props.y !== undefined) this._trs.array[1] = props.y;
|
|
209
|
+
if (props.width !== undefined) this._contentSize.width = props.width;
|
|
210
|
+
if (props.height !== undefined) this._contentSize.height = props.height;
|
|
211
|
+
if (props.anchorX !== undefined) this._anchorPoint.x = props.anchorX;
|
|
212
|
+
if (props.anchorY !== undefined) this._anchorPoint.y = props.anchorY;
|
|
213
|
+
if (props.scaleX !== undefined) this._trs.array[7] = props.scaleX;
|
|
214
|
+
if (props.scaleY !== undefined) this._trs.array[8] = props.scaleY;
|
|
215
|
+
if (props.rotation !== undefined) {
|
|
216
|
+
this._trs.array[5] = props.rotation * Math.PI / 180;
|
|
217
|
+
this._eulerAngles.z = props.rotation;
|
|
218
|
+
}
|
|
219
|
+
if (props.opacity !== undefined) this._opacity = props.opacity;
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
toJSON(indexMap) {
|
|
224
|
+
// 处理引用
|
|
225
|
+
const parent = this._parent ? (indexMap ? { __id__: indexMap.get(this._parent) } : this._parent) : null;
|
|
226
|
+
const children = indexMap ? this._children.map(c => ({ __id__: indexMap.get(c) })) : this._children;
|
|
227
|
+
const components = indexMap ? this._components.map(c => ({ __id__: indexMap.get(c) })) : this._components;
|
|
228
|
+
const prefab = this._prefab ? (indexMap ? { __id__: indexMap.get(this._prefab) } : this._prefab) : null;
|
|
229
|
+
|
|
230
|
+
// 显式控制属性顺序
|
|
231
|
+
return {
|
|
232
|
+
__type__: this.__type__,
|
|
233
|
+
_name: this._name,
|
|
234
|
+
_objFlags: this._objFlags,
|
|
235
|
+
_parent: parent,
|
|
236
|
+
_children: children,
|
|
237
|
+
_active: this._active,
|
|
238
|
+
_components: components,
|
|
239
|
+
_prefab: prefab,
|
|
240
|
+
_opacity: this._opacity,
|
|
241
|
+
_color: this._color.toJSON(),
|
|
242
|
+
_contentSize: this._contentSize.toJSON(),
|
|
243
|
+
_anchorPoint: this._anchorPoint.toJSON(),
|
|
244
|
+
_trs: this._trs.toJSON(),
|
|
245
|
+
_eulerAngles: this._eulerAngles.toJSON(),
|
|
246
|
+
_skewX: this._skewX,
|
|
247
|
+
_skewY: this._skewY,
|
|
248
|
+
_is3DNode: this._is3DNode,
|
|
249
|
+
_groupIndex: this._groupIndex,
|
|
250
|
+
groupIndex: this.groupIndex,
|
|
251
|
+
_id: this._id
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
256
|
module.exports = CCNode;
|
package/src/lib/cc/CCObject.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cocos Creator 对象基类
|
|
3
|
-
*/
|
|
4
|
-
class CCObject {
|
|
5
|
-
constructor(name = '') {
|
|
6
|
-
this.__type__ = '';
|
|
7
|
-
this._name = name;
|
|
8
|
-
this._objFlags = 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
toJSON() {
|
|
12
|
-
const obj = { ...this };
|
|
13
|
-
// 移除 undefined 的属性
|
|
14
|
-
for (const key in obj) {
|
|
15
|
-
if (obj[key] === undefined) {
|
|
16
|
-
delete obj[key];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = CCObject;
|
|
1
|
+
/**
|
|
2
|
+
* Cocos Creator 对象基类
|
|
3
|
+
*/
|
|
4
|
+
class CCObject {
|
|
5
|
+
constructor(name = '') {
|
|
6
|
+
this.__type__ = '';
|
|
7
|
+
this._name = name;
|
|
8
|
+
this._objFlags = 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toJSON() {
|
|
12
|
+
const obj = { ...this };
|
|
13
|
+
// 移除 undefined 的属性
|
|
14
|
+
for (const key in obj) {
|
|
15
|
+
if (obj[key] === undefined) {
|
|
16
|
+
delete obj[key];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = CCObject;
|