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.
Files changed (42) hide show
  1. package/bin/cocos2d-cli.js +152 -152
  2. package/data/script_map.json +25 -25
  3. package/package.json +33 -33
  4. package/src/commands/add-component.js +112 -112
  5. package/src/commands/add.js +177 -177
  6. package/src/commands/build.js +78 -78
  7. package/src/commands/create-scene.js +181 -181
  8. package/src/commands/get.js +108 -108
  9. package/src/commands/prefab-create.js +110 -110
  10. package/src/commands/remove-component.js +110 -110
  11. package/src/commands/remove.js +99 -99
  12. package/src/commands/screenshot.js +108 -103
  13. package/src/commands/set-component.js +119 -119
  14. package/src/commands/set.js +107 -107
  15. package/src/commands/tree.js +28 -28
  16. package/src/lib/cc/CCButton.js +122 -122
  17. package/src/lib/cc/CCCamera.js +93 -93
  18. package/src/lib/cc/CCCanvas.js +54 -54
  19. package/src/lib/cc/CCColor.js +32 -32
  20. package/src/lib/cc/CCComponent.js +60 -60
  21. package/src/lib/cc/CCLabel.js +146 -146
  22. package/src/lib/cc/CCNode.js +255 -255
  23. package/src/lib/cc/CCObject.js +23 -23
  24. package/src/lib/cc/CCPrefab.js +242 -242
  25. package/src/lib/cc/CCRect.js +32 -32
  26. package/src/lib/cc/CCRichText.js +44 -44
  27. package/src/lib/cc/CCScene.js +42 -42
  28. package/src/lib/cc/CCSceneAsset.js +302 -302
  29. package/src/lib/cc/CCSize.js +26 -26
  30. package/src/lib/cc/CCSprite.js +94 -94
  31. package/src/lib/cc/CCTrs.js +74 -74
  32. package/src/lib/cc/CCVec2.js +26 -26
  33. package/src/lib/cc/CCVec3.js +29 -29
  34. package/src/lib/cc/CCWidget.js +98 -98
  35. package/src/lib/cc/index.js +42 -42
  36. package/src/lib/fire-utils.js +373 -373
  37. package/src/lib/json-parser.js +185 -185
  38. package/src/lib/node-utils.js +395 -395
  39. package/src/lib/screenshot/index.html +29 -29
  40. package/src/lib/screenshot-core.js +285 -286
  41. package/src/lib/templates.js +49 -49
  42. package/src/lib/utils.js +202 -202
@@ -1,303 +1,303 @@
1
- const CCObject = require('./CCObject');
2
- const CCScene = require('./CCScene');
3
- const CCNode = require('./CCNode');
4
- const CCCanvas = require('./CCCanvas');
5
- const CCWidget = require('./CCWidget');
6
- const CCSprite = require('./CCSprite');
7
- const CCLabel = require('./CCLabel');
8
- const CCButton = require('./CCButton');
9
- const CCCamera = require('./CCCamera');
10
- const { generateCompressedUUID } = require('../utils');
11
-
12
- /**
13
- * Cocos Creator 场景资源类
14
- * 场景文件的容器,包含 CCScene 根节点
15
- */
16
- class CCSceneAsset extends CCObject {
17
- constructor() {
18
- super('');
19
- this.__type__ = 'cc.SceneAsset';
20
-
21
- this._native = '';
22
- this._scene = null; // CCScene 引用
23
- }
24
-
25
- /**
26
- * 获取场景根节点
27
- */
28
- getScene() {
29
- return this._scene;
30
- }
31
-
32
- /**
33
- * 通过路径查找节点
34
- */
35
- findNode(path) {
36
- if (!this._scene) return null;
37
- return this._scene.findChild(path);
38
- }
39
-
40
- /**
41
- * 添加节点到场景
42
- */
43
- addNode(node) {
44
- if (!this._scene) return null;
45
-
46
- node._parent = this._scene;
47
- if (!this._scene._children) this._scene._children = [];
48
- this._scene._children.push(node);
49
-
50
- // 场景中的节点需要 _id
51
- node._id = generateCompressedUUID();
52
-
53
- return node;
54
- }
55
-
56
- /**
57
- * 删除节点
58
- */
59
- removeNode(node) {
60
- if (!node || !node._parent) return false;
61
-
62
- const idx = node._parent._children.indexOf(node);
63
- if (idx > -1) {
64
- node._parent._children.splice(idx, 1);
65
- return true;
66
- }
67
- return false;
68
- }
69
-
70
- /**
71
- * 添加组件到节点
72
- */
73
- addComponent(node, component) {
74
- if (!node._components) node._components = [];
75
- component.node = node;
76
- node._components.push(component);
77
- return component;
78
- }
79
-
80
- /**
81
- * 从 JSON 解析
82
- */
83
- static fromJSON(json) {
84
- const asset = new CCSceneAsset();
85
- const objects = [];
86
-
87
- // 第一遍:创建所有对象
88
- json.forEach((item, index) => {
89
- objects[index] = createObject(item);
90
- });
91
-
92
- // 第二遍:建立引用关系
93
- json.forEach((item, index) => {
94
- setupReferences(objects[index], item, objects);
95
- });
96
-
97
- asset._scene = objects[1];
98
- return asset;
99
- }
100
-
101
- /**
102
- * 序列化为 JSON
103
- * 顺序:SceneAsset → Scene → 节点树(节点 → 子节点 → 组件)
104
- */
105
- toJSON() {
106
- const result = [];
107
- const indexMap = new Map();
108
-
109
- // 0: SceneAsset 头
110
- indexMap.set(this, 0);
111
- result.push({
112
- __type__: 'cc.SceneAsset',
113
- _name: '',
114
- _objFlags: 0,
115
- _native: '',
116
- scene: { __id__: 1 }
117
- });
118
-
119
- // 1: Scene
120
- indexMap.set(this._scene, 1);
121
- result.push(null); // 占位
122
-
123
- // 递归处理节点
124
- const processNode = (node) => {
125
- if (!node) return;
126
-
127
- // 添加节点
128
- indexMap.set(node, result.length);
129
- result.push(null); // 占位
130
-
131
- // 递归处理子节点
132
- if (node._children) {
133
- node._children.forEach(child => processNode(child));
134
- }
135
-
136
- // 添加组件
137
- if (node._components) {
138
- node._components.forEach(comp => {
139
- indexMap.set(comp, result.length);
140
- result.push(componentToJSON(comp, indexMap));
141
- });
142
- }
143
-
144
- // 生成节点 JSON
145
- result[indexMap.get(node)] = {
146
- __type__: 'cc.Node',
147
- _name: node._name,
148
- _objFlags: node._objFlags,
149
- _parent: node._parent ? { __id__: indexMap.get(node._parent) } : null,
150
- _children: (node._children || []).map(c => ({ __id__: indexMap.get(c) })),
151
- _active: node._active,
152
- _components: (node._components || []).map(c => ({ __id__: indexMap.get(c) })),
153
- _prefab: null,
154
- _opacity: node._opacity,
155
- _color: node._color.toJSON(),
156
- _contentSize: node._contentSize.toJSON(),
157
- _anchorPoint: node._anchorPoint.toJSON(),
158
- _trs: node._trs.toJSON(),
159
- _eulerAngles: node._eulerAngles.toJSON(),
160
- _skewX: node._skewX,
161
- _skewY: node._skewY,
162
- _is3DNode: node._is3DNode,
163
- _groupIndex: node._groupIndex,
164
- groupIndex: node.groupIndex,
165
- _id: node._id || ''
166
- };
167
- };
168
-
169
- // 处理 Scene 的子节点
170
- if (this._scene && this._scene._children) {
171
- this._scene._children.forEach(child => processNode(child));
172
- }
173
-
174
- // 填充 Scene
175
- result[1] = {
176
- __type__: 'cc.Scene',
177
- _objFlags: this._scene._objFlags,
178
- _parent: null,
179
- _children: (this._scene._children || []).map(c => ({ __id__: indexMap.get(c) })),
180
- _active: this._scene._active,
181
- _components: [],
182
- _prefab: null,
183
- _opacity: this._scene._opacity,
184
- _color: this._scene._color.toJSON(),
185
- _contentSize: this._scene._contentSize.toJSON(),
186
- _anchorPoint: this._scene._anchorPoint.toJSON(),
187
- _trs: this._scene._trs.toJSON(),
188
- _is3DNode: this._scene._is3DNode,
189
- _groupIndex: this._scene._groupIndex,
190
- groupIndex: this._scene.groupIndex,
191
- autoReleaseAssets: this._scene.autoReleaseAssets || false,
192
- _id: this._scene._id || ''
193
- };
194
-
195
- return result;
196
- }
197
- }
198
-
199
- function componentToJSON(comp, indexMap) {
200
- const json = {
201
- __type__: comp.__type__,
202
- _name: comp._name || '',
203
- _objFlags: comp._objFlags || 0,
204
- node: { __id__: indexMap.get(comp.node) },
205
- _enabled: comp._enabled !== false
206
- };
207
-
208
- for (const key of Object.keys(comp)) {
209
- if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
210
- const val = comp[key];
211
- if (val === undefined) continue;
212
- json[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
213
- }
214
-
215
- json._id = comp._id || '';
216
-
217
- return json;
218
- }
219
-
220
- function createObject(item) {
221
- const type = item.__type__;
222
-
223
- if (type === 'cc.SceneAsset') return null; // 跳过,由 fromJSON 处理
224
- if (type === 'cc.Scene') {
225
- const scene = new CCScene();
226
- scene._id = item._id || '';
227
- if (item._active !== undefined) scene._active = item._active;
228
- if (item.autoReleaseAssets !== undefined) scene.autoReleaseAssets = item.autoReleaseAssets;
229
- return scene;
230
- }
231
-
232
- if (type === 'cc.Node') {
233
- const node = new CCNode(item._name || 'Node');
234
- node._id = item._id || '';
235
- copyNodeProps(node, item);
236
- return node;
237
- }
238
-
239
- // 组件 - 创建类实例
240
- const comp = createComponentInstance(type);
241
- if (comp) {
242
- copyComponentProps(comp, item);
243
- return comp;
244
- }
245
-
246
- // 未知类型,返回普通对象
247
- const obj = { __type__: type };
248
- for (const key of Object.keys(item)) {
249
- obj[key] = item[key];
250
- }
251
- return obj;
252
- }
253
-
254
- function createComponentInstance(type) {
255
- switch (type) {
256
- case 'cc.Canvas': return new CCCanvas();
257
- case 'cc.Widget': return new CCWidget();
258
- case 'cc.Sprite': return new CCSprite();
259
- case 'cc.Label': return new CCLabel();
260
- case 'cc.Button': return new CCButton();
261
- case 'cc.Camera': return new CCCamera();
262
- default: return null;
263
- }
264
- }
265
-
266
- function copyComponentProps(comp, item) {
267
- for (const key of Object.keys(item)) {
268
- if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
269
- comp[key] = item[key];
270
- }
271
- if (item._id) comp._id = item._id;
272
- }
273
-
274
- function copyNodeProps(node, item) {
275
- if (item._active !== undefined) node._active = item._active;
276
- if (item._opacity !== undefined) node._opacity = item._opacity;
277
- if (item._is3DNode !== undefined) node._is3DNode = item._is3DNode;
278
- if (item._groupIndex !== undefined) node._groupIndex = item._groupIndex;
279
- if (item.groupIndex !== undefined) node.groupIndex = item.groupIndex;
280
- if (item._skewX !== undefined) node._skewX = item._skewX;
281
- if (item._skewY !== undefined) node._skewY = item._skewY;
282
-
283
- if (item._color) node._color.set(item._color.r, item._color.g, item._color.b, item._color.a);
284
- if (item._contentSize) node._contentSize.set(item._contentSize.width, item._contentSize.height);
285
- if (item._anchorPoint) node._anchorPoint.set(item._anchorPoint.x, item._anchorPoint.y);
286
- if (item._trs?.array) item._trs.array.forEach((v, i) => node._trs.array[i] = v);
287
- if (item._eulerAngles) node._eulerAngles.set(item._eulerAngles.x, item._eulerAngles.y, item._eulerAngles.z);
288
- }
289
-
290
- function setupReferences(obj, item, objects) {
291
- if (!obj) return;
292
-
293
- if (obj.__type__ === 'cc.Scene' || obj.__type__ === 'cc.Node') {
294
- if (item._parent) obj._parent = objects[item._parent.__id__];
295
- if (item._children) obj._children = item._children.map(c => objects[c.__id__]).filter(Boolean);
296
- if (item._components) {
297
- obj._components = item._components.map(c => objects[c.__id__]).filter(Boolean);
298
- obj._components.forEach(c => { if (c) c.node = obj; });
299
- }
300
- }
301
- }
302
-
1
+ const CCObject = require('./CCObject');
2
+ const CCScene = require('./CCScene');
3
+ const CCNode = require('./CCNode');
4
+ const CCCanvas = require('./CCCanvas');
5
+ const CCWidget = require('./CCWidget');
6
+ const CCSprite = require('./CCSprite');
7
+ const CCLabel = require('./CCLabel');
8
+ const CCButton = require('./CCButton');
9
+ const CCCamera = require('./CCCamera');
10
+ const { generateCompressedUUID } = require('../utils');
11
+
12
+ /**
13
+ * Cocos Creator 场景资源类
14
+ * 场景文件的容器,包含 CCScene 根节点
15
+ */
16
+ class CCSceneAsset extends CCObject {
17
+ constructor() {
18
+ super('');
19
+ this.__type__ = 'cc.SceneAsset';
20
+
21
+ this._native = '';
22
+ this._scene = null; // CCScene 引用
23
+ }
24
+
25
+ /**
26
+ * 获取场景根节点
27
+ */
28
+ getScene() {
29
+ return this._scene;
30
+ }
31
+
32
+ /**
33
+ * 通过路径查找节点
34
+ */
35
+ findNode(path) {
36
+ if (!this._scene) return null;
37
+ return this._scene.findChild(path);
38
+ }
39
+
40
+ /**
41
+ * 添加节点到场景
42
+ */
43
+ addNode(node) {
44
+ if (!this._scene) return null;
45
+
46
+ node._parent = this._scene;
47
+ if (!this._scene._children) this._scene._children = [];
48
+ this._scene._children.push(node);
49
+
50
+ // 场景中的节点需要 _id
51
+ node._id = generateCompressedUUID();
52
+
53
+ return node;
54
+ }
55
+
56
+ /**
57
+ * 删除节点
58
+ */
59
+ removeNode(node) {
60
+ if (!node || !node._parent) return false;
61
+
62
+ const idx = node._parent._children.indexOf(node);
63
+ if (idx > -1) {
64
+ node._parent._children.splice(idx, 1);
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * 添加组件到节点
72
+ */
73
+ addComponent(node, component) {
74
+ if (!node._components) node._components = [];
75
+ component.node = node;
76
+ node._components.push(component);
77
+ return component;
78
+ }
79
+
80
+ /**
81
+ * 从 JSON 解析
82
+ */
83
+ static fromJSON(json) {
84
+ const asset = new CCSceneAsset();
85
+ const objects = [];
86
+
87
+ // 第一遍:创建所有对象
88
+ json.forEach((item, index) => {
89
+ objects[index] = createObject(item);
90
+ });
91
+
92
+ // 第二遍:建立引用关系
93
+ json.forEach((item, index) => {
94
+ setupReferences(objects[index], item, objects);
95
+ });
96
+
97
+ asset._scene = objects[1];
98
+ return asset;
99
+ }
100
+
101
+ /**
102
+ * 序列化为 JSON
103
+ * 顺序:SceneAsset → Scene → 节点树(节点 → 子节点 → 组件)
104
+ */
105
+ toJSON() {
106
+ const result = [];
107
+ const indexMap = new Map();
108
+
109
+ // 0: SceneAsset 头
110
+ indexMap.set(this, 0);
111
+ result.push({
112
+ __type__: 'cc.SceneAsset',
113
+ _name: '',
114
+ _objFlags: 0,
115
+ _native: '',
116
+ scene: { __id__: 1 }
117
+ });
118
+
119
+ // 1: Scene
120
+ indexMap.set(this._scene, 1);
121
+ result.push(null); // 占位
122
+
123
+ // 递归处理节点
124
+ const processNode = (node) => {
125
+ if (!node) return;
126
+
127
+ // 添加节点
128
+ indexMap.set(node, result.length);
129
+ result.push(null); // 占位
130
+
131
+ // 递归处理子节点
132
+ if (node._children) {
133
+ node._children.forEach(child => processNode(child));
134
+ }
135
+
136
+ // 添加组件
137
+ if (node._components) {
138
+ node._components.forEach(comp => {
139
+ indexMap.set(comp, result.length);
140
+ result.push(componentToJSON(comp, indexMap));
141
+ });
142
+ }
143
+
144
+ // 生成节点 JSON
145
+ result[indexMap.get(node)] = {
146
+ __type__: 'cc.Node',
147
+ _name: node._name,
148
+ _objFlags: node._objFlags,
149
+ _parent: node._parent ? { __id__: indexMap.get(node._parent) } : null,
150
+ _children: (node._children || []).map(c => ({ __id__: indexMap.get(c) })),
151
+ _active: node._active,
152
+ _components: (node._components || []).map(c => ({ __id__: indexMap.get(c) })),
153
+ _prefab: null,
154
+ _opacity: node._opacity,
155
+ _color: node._color.toJSON(),
156
+ _contentSize: node._contentSize.toJSON(),
157
+ _anchorPoint: node._anchorPoint.toJSON(),
158
+ _trs: node._trs.toJSON(),
159
+ _eulerAngles: node._eulerAngles.toJSON(),
160
+ _skewX: node._skewX,
161
+ _skewY: node._skewY,
162
+ _is3DNode: node._is3DNode,
163
+ _groupIndex: node._groupIndex,
164
+ groupIndex: node.groupIndex,
165
+ _id: node._id || ''
166
+ };
167
+ };
168
+
169
+ // 处理 Scene 的子节点
170
+ if (this._scene && this._scene._children) {
171
+ this._scene._children.forEach(child => processNode(child));
172
+ }
173
+
174
+ // 填充 Scene
175
+ result[1] = {
176
+ __type__: 'cc.Scene',
177
+ _objFlags: this._scene._objFlags,
178
+ _parent: null,
179
+ _children: (this._scene._children || []).map(c => ({ __id__: indexMap.get(c) })),
180
+ _active: this._scene._active,
181
+ _components: [],
182
+ _prefab: null,
183
+ _opacity: this._scene._opacity,
184
+ _color: this._scene._color.toJSON(),
185
+ _contentSize: this._scene._contentSize.toJSON(),
186
+ _anchorPoint: this._scene._anchorPoint.toJSON(),
187
+ _trs: this._scene._trs.toJSON(),
188
+ _is3DNode: this._scene._is3DNode,
189
+ _groupIndex: this._scene._groupIndex,
190
+ groupIndex: this._scene.groupIndex,
191
+ autoReleaseAssets: this._scene.autoReleaseAssets || false,
192
+ _id: this._scene._id || ''
193
+ };
194
+
195
+ return result;
196
+ }
197
+ }
198
+
199
+ function componentToJSON(comp, indexMap) {
200
+ const json = {
201
+ __type__: comp.__type__,
202
+ _name: comp._name || '',
203
+ _objFlags: comp._objFlags || 0,
204
+ node: { __id__: indexMap.get(comp.node) },
205
+ _enabled: comp._enabled !== false
206
+ };
207
+
208
+ for (const key of Object.keys(comp)) {
209
+ if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
210
+ const val = comp[key];
211
+ if (val === undefined) continue;
212
+ json[key] = val && typeof val.toJSON === 'function' ? val.toJSON() : val;
213
+ }
214
+
215
+ json._id = comp._id || '';
216
+
217
+ return json;
218
+ }
219
+
220
+ function createObject(item) {
221
+ const type = item.__type__;
222
+
223
+ if (type === 'cc.SceneAsset') return null; // 跳过,由 fromJSON 处理
224
+ if (type === 'cc.Scene') {
225
+ const scene = new CCScene();
226
+ scene._id = item._id || '';
227
+ if (item._active !== undefined) scene._active = item._active;
228
+ if (item.autoReleaseAssets !== undefined) scene.autoReleaseAssets = item.autoReleaseAssets;
229
+ return scene;
230
+ }
231
+
232
+ if (type === 'cc.Node') {
233
+ const node = new CCNode(item._name || 'Node');
234
+ node._id = item._id || '';
235
+ copyNodeProps(node, item);
236
+ return node;
237
+ }
238
+
239
+ // 组件 - 创建类实例
240
+ const comp = createComponentInstance(type);
241
+ if (comp) {
242
+ copyComponentProps(comp, item);
243
+ return comp;
244
+ }
245
+
246
+ // 未知类型,返回普通对象
247
+ const obj = { __type__: type };
248
+ for (const key of Object.keys(item)) {
249
+ obj[key] = item[key];
250
+ }
251
+ return obj;
252
+ }
253
+
254
+ function createComponentInstance(type) {
255
+ switch (type) {
256
+ case 'cc.Canvas': return new CCCanvas();
257
+ case 'cc.Widget': return new CCWidget();
258
+ case 'cc.Sprite': return new CCSprite();
259
+ case 'cc.Label': return new CCLabel();
260
+ case 'cc.Button': return new CCButton();
261
+ case 'cc.Camera': return new CCCamera();
262
+ default: return null;
263
+ }
264
+ }
265
+
266
+ function copyComponentProps(comp, item) {
267
+ for (const key of Object.keys(item)) {
268
+ if (['__type__', '_name', '_objFlags', 'node', '_enabled', '_id'].includes(key)) continue;
269
+ comp[key] = item[key];
270
+ }
271
+ if (item._id) comp._id = item._id;
272
+ }
273
+
274
+ function copyNodeProps(node, item) {
275
+ if (item._active !== undefined) node._active = item._active;
276
+ if (item._opacity !== undefined) node._opacity = item._opacity;
277
+ if (item._is3DNode !== undefined) node._is3DNode = item._is3DNode;
278
+ if (item._groupIndex !== undefined) node._groupIndex = item._groupIndex;
279
+ if (item.groupIndex !== undefined) node.groupIndex = item.groupIndex;
280
+ if (item._skewX !== undefined) node._skewX = item._skewX;
281
+ if (item._skewY !== undefined) node._skewY = item._skewY;
282
+
283
+ if (item._color) node._color.set(item._color.r, item._color.g, item._color.b, item._color.a);
284
+ if (item._contentSize) node._contentSize.set(item._contentSize.width, item._contentSize.height);
285
+ if (item._anchorPoint) node._anchorPoint.set(item._anchorPoint.x, item._anchorPoint.y);
286
+ if (item._trs?.array) item._trs.array.forEach((v, i) => node._trs.array[i] = v);
287
+ if (item._eulerAngles) node._eulerAngles.set(item._eulerAngles.x, item._eulerAngles.y, item._eulerAngles.z);
288
+ }
289
+
290
+ function setupReferences(obj, item, objects) {
291
+ if (!obj) return;
292
+
293
+ if (obj.__type__ === 'cc.Scene' || obj.__type__ === 'cc.Node') {
294
+ if (item._parent) obj._parent = objects[item._parent.__id__];
295
+ if (item._children) obj._children = item._children.map(c => objects[c.__id__]).filter(Boolean);
296
+ if (item._components) {
297
+ obj._components = item._components.map(c => objects[c.__id__]).filter(Boolean);
298
+ obj._components.forEach(c => { if (c) c.node = obj; });
299
+ }
300
+ }
301
+ }
302
+
303
303
  module.exports = CCSceneAsset;
@@ -1,26 +1,26 @@
1
- /**
2
- * Cocos Creator 尺寸类
3
- */
4
- class CCSize {
5
- constructor(width = 0, height = 0) {
6
- this.__type__ = 'cc.Size';
7
- this.width = width;
8
- this.height = height;
9
- }
10
-
11
- set(width, height) {
12
- this.width = width;
13
- this.height = height;
14
- return this;
15
- }
16
-
17
- toJSON() {
18
- return {
19
- __type__: this.__type__,
20
- width: this.width,
21
- height: this.height
22
- };
23
- }
24
- }
25
-
26
- module.exports = CCSize;
1
+ /**
2
+ * Cocos Creator 尺寸类
3
+ */
4
+ class CCSize {
5
+ constructor(width = 0, height = 0) {
6
+ this.__type__ = 'cc.Size';
7
+ this.width = width;
8
+ this.height = height;
9
+ }
10
+
11
+ set(width, height) {
12
+ this.width = width;
13
+ this.height = height;
14
+ return this;
15
+ }
16
+
17
+ toJSON() {
18
+ return {
19
+ __type__: this.__type__,
20
+ width: this.width,
21
+ height: this.height
22
+ };
23
+ }
24
+ }
25
+
26
+ module.exports = CCSize;