cocos2d-cli 1.6.5 → 2.1.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/data/script_map.json +25 -25
- package/dist/bin/cocos2d-cli.js +64 -0
- package/dist/src/commands/add-component.js +3 -0
- package/dist/src/commands/add.js +3 -0
- package/dist/src/commands/build.js +6 -0
- package/dist/src/commands/create-scene.js +3 -0
- package/dist/src/commands/get.js +3 -0
- package/dist/src/commands/prefab-create.js +109 -0
- package/dist/src/commands/remove-component.js +3 -0
- package/dist/src/commands/remove.js +3 -0
- package/dist/src/commands/screenshot.js +41 -0
- package/dist/src/commands/set-component.js +3 -0
- package/dist/src/commands/set.js +3 -0
- package/dist/src/commands/tree.js +24 -0
- package/{src → dist/src}/lib/cc/CCButton.js +115 -122
- package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
- package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
- package/{src → dist/src}/lib/cc/CCColor.js +30 -32
- package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
- package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
- package/{src → dist/src}/lib/cc/CCNode.js +190 -256
- package/{src → dist/src}/lib/cc/CCObject.js +19 -23
- package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
- package/{src → dist/src}/lib/cc/CCRect.js +30 -32
- package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
- package/{src → dist/src}/lib/cc/CCScene.js +32 -42
- package/dist/src/lib/cc/CCSceneAsset.js +242 -0
- package/{src → dist/src}/lib/cc/CCSize.js +22 -26
- package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
- package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
- package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
- package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
- package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
- package/dist/src/lib/fire-utils.js +86 -0
- package/dist/src/lib/json-parser.js +114 -0
- package/dist/src/lib/node-utils.js +131 -0
- package/{src → dist/src}/lib/screenshot-core.js +242 -285
- package/dist/src/lib/templates.js +17 -0
- package/dist/src/lib/utils.js +81 -0
- package/package.json +40 -33
- package/bin/cocos2d-cli.js +0 -152
- package/src/commands/add-component.js +0 -112
- package/src/commands/add.js +0 -177
- package/src/commands/build.js +0 -78
- package/src/commands/create-scene.js +0 -181
- package/src/commands/get.js +0 -108
- package/src/commands/prefab-create.js +0 -111
- package/src/commands/remove-component.js +0 -111
- package/src/commands/remove.js +0 -99
- package/src/commands/screenshot.js +0 -108
- package/src/commands/set-component.js +0 -119
- package/src/commands/set.js +0 -107
- package/src/commands/tree.js +0 -29
- package/src/lib/cc/CCSceneAsset.js +0 -303
- package/src/lib/cc/index.js +0 -42
- package/src/lib/fire-utils.js +0 -374
- package/src/lib/json-parser.js +0 -185
- package/src/lib/node-utils.js +0 -395
- package/src/lib/screenshot/favicon.ico +0 -0
- package/src/lib/screenshot/index.html +0 -30
- package/src/lib/templates.js +0 -49
- package/src/lib/utils.js +0 -202
|
@@ -1,256 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this._id =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
get
|
|
63
|
-
set
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
module.exports = CCNode;
|
|
1
|
+
import CCObject from './CCObject.js';
|
|
2
|
+
import CCColor from './CCColor.js';
|
|
3
|
+
import CCSize from './CCSize.js';
|
|
4
|
+
import CCVec2 from './CCVec2.js';
|
|
5
|
+
import CCVec3 from './CCVec3.js';
|
|
6
|
+
import CCTrs from './CCTrs.js';
|
|
7
|
+
export default class CCNode extends CCObject {
|
|
8
|
+
_parent;
|
|
9
|
+
_children;
|
|
10
|
+
_active;
|
|
11
|
+
_components;
|
|
12
|
+
_prefab;
|
|
13
|
+
_opacity;
|
|
14
|
+
_color;
|
|
15
|
+
_contentSize;
|
|
16
|
+
_anchorPoint;
|
|
17
|
+
_trs;
|
|
18
|
+
_eulerAngles;
|
|
19
|
+
_skewX;
|
|
20
|
+
_skewY;
|
|
21
|
+
_is3DNode;
|
|
22
|
+
_groupIndex;
|
|
23
|
+
groupIndex;
|
|
24
|
+
_id;
|
|
25
|
+
constructor(name = 'Node') {
|
|
26
|
+
super(name);
|
|
27
|
+
this.__type__ = 'cc.Node';
|
|
28
|
+
this._parent = null;
|
|
29
|
+
this._children = [];
|
|
30
|
+
this._active = true;
|
|
31
|
+
this._components = [];
|
|
32
|
+
this._prefab = null;
|
|
33
|
+
this._opacity = 255;
|
|
34
|
+
this._color = new CCColor();
|
|
35
|
+
this._contentSize = new CCSize();
|
|
36
|
+
this._anchorPoint = new CCVec2(0.5, 0.5);
|
|
37
|
+
this._trs = new CCTrs();
|
|
38
|
+
this._eulerAngles = new CCVec3();
|
|
39
|
+
this._skewX = 0;
|
|
40
|
+
this._skewY = 0;
|
|
41
|
+
this._is3DNode = false;
|
|
42
|
+
this._groupIndex = 0;
|
|
43
|
+
this.groupIndex = 0;
|
|
44
|
+
this._id = '';
|
|
45
|
+
}
|
|
46
|
+
setId(id) {
|
|
47
|
+
this._id = id;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
get x() { return this._trs.x; }
|
|
51
|
+
set x(v) { this._trs.x = v; }
|
|
52
|
+
get y() { return this._trs.y; }
|
|
53
|
+
set y(v) { this._trs.y = v; }
|
|
54
|
+
get scaleX() { return this._trs.scaleX; }
|
|
55
|
+
set scaleX(v) { this._trs.scaleX = v; }
|
|
56
|
+
get scaleY() { return this._trs.scaleY; }
|
|
57
|
+
set scaleY(v) { this._trs.scaleY = v; }
|
|
58
|
+
get width() { return this._contentSize.width; }
|
|
59
|
+
set width(v) { this._contentSize.width = v; }
|
|
60
|
+
get height() { return this._contentSize.height; }
|
|
61
|
+
set height(v) { this._contentSize.height = v; }
|
|
62
|
+
get anchorX() { return this._anchorPoint.x; }
|
|
63
|
+
set anchorX(v) { this._anchorPoint.x = v; }
|
|
64
|
+
get anchorY() { return this._anchorPoint.y; }
|
|
65
|
+
set anchorY(v) { this._anchorPoint.y = v; }
|
|
66
|
+
setPosition(x, y) {
|
|
67
|
+
this._trs.setPosition(x, y);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
setContentSize(width, height) {
|
|
71
|
+
this._contentSize.set(width, height);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
setAnchorPoint(x, y) {
|
|
75
|
+
this._anchorPoint.set(x, y);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
setScale(x, y = x) {
|
|
79
|
+
this._trs.setScale(x, y);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
setRotation(angle) {
|
|
83
|
+
this._trs.rotZ = angle * Math.PI / 180;
|
|
84
|
+
this._eulerAngles.z = angle;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
setColor(r, g, b, a = 255) {
|
|
88
|
+
this._color.set(r, g, b, a);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
setOpacity(opacity) {
|
|
92
|
+
this._opacity = opacity;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
setActive(active) {
|
|
96
|
+
this._active = active;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
setParent(parent) {
|
|
100
|
+
this._parent = typeof parent === 'number' ? { __id__: parent } : parent;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
addChild(child) {
|
|
104
|
+
const childNode = typeof child === 'number' ? { __id__: child } : child;
|
|
105
|
+
this._children.push(childNode);
|
|
106
|
+
if (typeof childNode !== 'number' && childNode._parent !== undefined) {
|
|
107
|
+
childNode._parent = this;
|
|
108
|
+
}
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
addComponent(comp) {
|
|
112
|
+
this._components.push(typeof comp === 'number' ? { __id__: comp } : comp);
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
getProp() {
|
|
116
|
+
const trs = this._trs?.array || [0, 0, 0, 0, 0, 0, 1, 1, 1, 1];
|
|
117
|
+
return {
|
|
118
|
+
name: this._name,
|
|
119
|
+
active: this._active,
|
|
120
|
+
x: trs[0],
|
|
121
|
+
y: trs[1],
|
|
122
|
+
width: this._contentSize?.width ?? 0,
|
|
123
|
+
height: this._contentSize?.height ?? 0,
|
|
124
|
+
anchorX: this._anchorPoint?.x ?? 0.5,
|
|
125
|
+
anchorY: this._anchorPoint?.y ?? 0.5,
|
|
126
|
+
scaleX: trs[7],
|
|
127
|
+
scaleY: trs[8],
|
|
128
|
+
rotation: this._eulerAngles?.z ?? 0,
|
|
129
|
+
opacity: this._opacity ?? 255,
|
|
130
|
+
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'
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
setProp(props) {
|
|
134
|
+
if (props.name !== undefined)
|
|
135
|
+
this._name = props.name;
|
|
136
|
+
if (props.active !== undefined)
|
|
137
|
+
this._active = props.active;
|
|
138
|
+
if (props.x !== undefined)
|
|
139
|
+
this._trs.array[0] = props.x;
|
|
140
|
+
if (props.y !== undefined)
|
|
141
|
+
this._trs.array[1] = props.y;
|
|
142
|
+
if (props.width !== undefined)
|
|
143
|
+
this._contentSize.width = props.width;
|
|
144
|
+
if (props.height !== undefined)
|
|
145
|
+
this._contentSize.height = props.height;
|
|
146
|
+
if (props.anchorX !== undefined)
|
|
147
|
+
this._anchorPoint.x = props.anchorX;
|
|
148
|
+
if (props.anchorY !== undefined)
|
|
149
|
+
this._anchorPoint.y = props.anchorY;
|
|
150
|
+
if (props.scaleX !== undefined)
|
|
151
|
+
this._trs.array[7] = props.scaleX;
|
|
152
|
+
if (props.scaleY !== undefined)
|
|
153
|
+
this._trs.array[8] = props.scaleY;
|
|
154
|
+
if (props.rotation !== undefined) {
|
|
155
|
+
this._trs.array[5] = props.rotation * Math.PI / 180;
|
|
156
|
+
this._eulerAngles.z = props.rotation;
|
|
157
|
+
}
|
|
158
|
+
if (props.opacity !== undefined)
|
|
159
|
+
this._opacity = props.opacity;
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
toJSON(indexMap) {
|
|
163
|
+
const parent = this._parent ? (indexMap ? { __id__: indexMap.get(this._parent) } : this._parent) : null;
|
|
164
|
+
const children = indexMap ? this._children.map(c => ({ __id__: indexMap.get(c) })) : this._children;
|
|
165
|
+
const components = indexMap ? this._components.map(c => ({ __id__: indexMap.get(c) })) : this._components;
|
|
166
|
+
const prefab = this._prefab ? (indexMap ? { __id__: indexMap.get(this._prefab) } : this._prefab) : null;
|
|
167
|
+
return {
|
|
168
|
+
__type__: this.__type__,
|
|
169
|
+
_name: this._name,
|
|
170
|
+
_objFlags: this._objFlags,
|
|
171
|
+
_parent: parent,
|
|
172
|
+
_children: children,
|
|
173
|
+
_active: this._active,
|
|
174
|
+
_components: components,
|
|
175
|
+
_prefab: prefab,
|
|
176
|
+
_opacity: this._opacity,
|
|
177
|
+
_color: this._color.toJSON(),
|
|
178
|
+
_contentSize: this._contentSize.toJSON(),
|
|
179
|
+
_anchorPoint: this._anchorPoint.toJSON(),
|
|
180
|
+
_trs: this._trs.toJSON(),
|
|
181
|
+
_eulerAngles: this._eulerAngles.toJSON(),
|
|
182
|
+
_skewX: this._skewX,
|
|
183
|
+
_skewY: this._skewY,
|
|
184
|
+
_is3DNode: this._is3DNode,
|
|
185
|
+
_groupIndex: this._groupIndex,
|
|
186
|
+
groupIndex: this.groupIndex,
|
|
187
|
+
_id: this._id
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
constructor(name = '') {
|
|
6
|
-
this.__type__ = '';
|
|
7
|
-
this._name = name;
|
|
8
|
-
this._objFlags = 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const obj
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = CCObject;
|
|
1
|
+
export default class CCObject {
|
|
2
|
+
__type__;
|
|
3
|
+
_name;
|
|
4
|
+
_objFlags;
|
|
5
|
+
constructor(name = '') {
|
|
6
|
+
this.__type__ = '';
|
|
7
|
+
this._name = name;
|
|
8
|
+
this._objFlags = 0;
|
|
9
|
+
}
|
|
10
|
+
toJSON() {
|
|
11
|
+
const obj = { ...this };
|
|
12
|
+
for (const key in obj) {
|
|
13
|
+
if (obj[key] === undefined) {
|
|
14
|
+
delete obj[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
}
|