cocos2d-cli 1.6.5 → 2.0.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.
Files changed (61) hide show
  1. package/dist/bin/cocos2d-cli.js +64 -0
  2. package/dist/src/commands/add-component.js +3 -0
  3. package/dist/src/commands/add.js +3 -0
  4. package/dist/src/commands/build.js +6 -0
  5. package/dist/src/commands/create-scene.js +3 -0
  6. package/dist/src/commands/get.js +3 -0
  7. package/dist/src/commands/prefab-create.js +109 -0
  8. package/dist/src/commands/remove-component.js +3 -0
  9. package/dist/src/commands/remove.js +3 -0
  10. package/dist/src/commands/screenshot.js +41 -0
  11. package/dist/src/commands/set-component.js +3 -0
  12. package/dist/src/commands/set.js +3 -0
  13. package/dist/src/commands/tree.js +24 -0
  14. package/{src → dist/src}/lib/cc/CCButton.js +115 -122
  15. package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
  16. package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
  17. package/{src → dist/src}/lib/cc/CCColor.js +30 -32
  18. package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
  19. package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
  20. package/{src → dist/src}/lib/cc/CCNode.js +190 -256
  21. package/{src → dist/src}/lib/cc/CCObject.js +19 -23
  22. package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
  23. package/{src → dist/src}/lib/cc/CCRect.js +30 -32
  24. package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
  25. package/{src → dist/src}/lib/cc/CCScene.js +32 -42
  26. package/dist/src/lib/cc/CCSceneAsset.js +242 -0
  27. package/{src → dist/src}/lib/cc/CCSize.js +22 -26
  28. package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
  29. package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
  30. package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
  31. package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
  32. package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
  33. package/dist/src/lib/fire-utils.js +86 -0
  34. package/dist/src/lib/json-parser.js +114 -0
  35. package/dist/src/lib/node-utils.js +131 -0
  36. package/{src → dist/src}/lib/screenshot-core.js +221 -285
  37. package/dist/src/lib/templates.js +17 -0
  38. package/dist/src/lib/utils.js +81 -0
  39. package/package.json +13 -6
  40. package/bin/cocos2d-cli.js +0 -152
  41. package/src/commands/add-component.js +0 -112
  42. package/src/commands/add.js +0 -177
  43. package/src/commands/build.js +0 -78
  44. package/src/commands/create-scene.js +0 -181
  45. package/src/commands/get.js +0 -108
  46. package/src/commands/prefab-create.js +0 -111
  47. package/src/commands/remove-component.js +0 -111
  48. package/src/commands/remove.js +0 -99
  49. package/src/commands/screenshot.js +0 -108
  50. package/src/commands/set-component.js +0 -119
  51. package/src/commands/set.js +0 -107
  52. package/src/commands/tree.js +0 -29
  53. package/src/lib/cc/CCSceneAsset.js +0 -303
  54. package/src/lib/cc/index.js +0 -42
  55. package/src/lib/fire-utils.js +0 -374
  56. package/src/lib/json-parser.js +0 -185
  57. package/src/lib/node-utils.js +0 -395
  58. package/src/lib/screenshot/favicon.ico +0 -0
  59. package/src/lib/screenshot/index.html +0 -30
  60. package/src/lib/templates.js +0 -49
  61. package/src/lib/utils.js +0 -202
@@ -1,256 +1,190 @@
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
- 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
- * 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
+ 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
+ }