cocos2d-cli 1.6.4 → 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 -108
  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,29 +1,29 @@
1
- /**
2
- * tree 命令 - 查看节点树(支持场景和预制体)
3
- */
4
-
5
- const { loadScene, loadScriptMap, isPrefab } = require('../lib/fire-utils');
6
- const { buildTree } = require('../lib/node-utils');
7
-
8
- function run(args) {
9
- const filePath = args[0];
10
-
11
- if (!filePath) {
12
- console.log(JSON.stringify({ error: '用法: cocos2d-cli tree <场景.fire | 预制体.prefab>' }));
13
- return;
14
- }
15
-
16
- try {
17
- const data = loadScene(filePath);
18
- const scriptMap = loadScriptMap(filePath);
19
- const prefab = isPrefab(data);
20
-
21
- // Prefab 从索引 0 开始,Scene 从索引 1 开始
22
- const startIndex = prefab ? 0 : 1;
23
- console.log(buildTree(data, scriptMap, startIndex).trim());
24
- } catch (err) {
25
- console.log(JSON.stringify({ error: err.message }));
26
- }
27
- }
28
-
1
+ /**
2
+ * tree 命令 - 查看节点树(支持场景和预制体)
3
+ */
4
+
5
+ const { loadScene, loadScriptMap, isPrefab } = require('../lib/fire-utils');
6
+ const { buildTree } = require('../lib/node-utils');
7
+
8
+ function run(args) {
9
+ const filePath = args[0];
10
+
11
+ if (!filePath) {
12
+ console.log(JSON.stringify({ error: '用法: cocos2d-cli tree <场景.fire | 预制体.prefab>' }));
13
+ return;
14
+ }
15
+
16
+ try {
17
+ const data = loadScene(filePath);
18
+ const scriptMap = loadScriptMap(filePath);
19
+ const prefab = isPrefab(data);
20
+
21
+ // Prefab 从索引 0 开始,Scene 从索引 1 开始
22
+ const startIndex = prefab ? 0 : 1;
23
+ console.log(buildTree(data, scriptMap, startIndex).trim());
24
+ } catch (err) {
25
+ console.log(JSON.stringify({ error: err.message }));
26
+ }
27
+ }
28
+
29
29
  module.exports = { run };
@@ -1,122 +1,122 @@
1
- const CCComponent = require('./CCComponent');
2
- const CCColor = require('./CCColor');
3
-
4
- /**
5
- * Cocos Creator Button 组件
6
- */
7
- class CCButton extends CCComponent {
8
- constructor() {
9
- super();
10
- this.__type__ = 'cc.Button';
11
-
12
- this._normalMaterial = null;
13
- this._grayMaterial = null;
14
- this.duration = 0.1;
15
- this.zoomScale = 1.2;
16
- this.clickEvents = [];
17
- this._N$interactable = true;
18
- this._N$enableAutoGrayEffect = false;
19
- this._N$transition = 3;
20
- this.transition = 3;
21
- this._N$normalColor = new CCColor();
22
- this._N$pressedColor = new CCColor(200, 200, 200, 255);
23
- this.pressedColor = new CCColor(200, 200, 200, 255);
24
- this._N$hoverColor = new CCColor();
25
- this.hoverColor = new CCColor();
26
- this._N$disabledColor = new CCColor(120, 120, 120, 200);
27
- this._N$normalSprite = null;
28
- this._N$pressedSprite = null;
29
- this.pressedSprite = null;
30
- this._N$hoverSprite = null;
31
- this.hoverSprite = null;
32
- this._N$disabledSprite = null;
33
- this._N$target = null;
34
- }
35
-
36
- /**
37
- * 设置缩放
38
- */
39
- setZoomScale(scale) {
40
- this.zoomScale = scale;
41
- return this;
42
- }
43
-
44
- /**
45
- * 设置过渡类型
46
- * 0: NONE, 1: COLOR, 2: SPRITE, 3: SCALE
47
- */
48
- setTransition(type) {
49
- this._N$transition = type;
50
- this.transition = type;
51
- return this;
52
- }
53
-
54
- /**
55
- * 设置正常精灵
56
- */
57
- setNormalSprite(uuid) {
58
- this._N$normalSprite = { __uuid__: uuid };
59
- return this;
60
- }
61
-
62
- /**
63
- * 设置点击事件
64
- */
65
- addClickEvent(component, handler, target = null) {
66
- this.clickEvents.push({
67
- target: target,
68
- component: component,
69
- handler: handler
70
- });
71
- return this;
72
- }
73
-
74
- /**
75
- * 转换为属性面板显示格式
76
- */
77
- toPanelJSON() {
78
- const TRANSITION = ['NONE', 'COLOR', 'SPRITE', 'SCALE'];
79
- return {
80
- ...super.toPanelJSON(),
81
- interactable: this._N$interactable,
82
- transition: TRANSITION[this._N$transition] || this._N$transition,
83
- zoomScale: this.zoomScale,
84
- duration: this.duration
85
- };
86
- }
87
-
88
- toJSON() {
89
- return {
90
- __type__: this.__type__,
91
- _name: this._name,
92
- _objFlags: this._objFlags,
93
- node: this.node,
94
- _enabled: this._enabled,
95
- _normalMaterial: this._normalMaterial,
96
- _grayMaterial: this._grayMaterial,
97
- duration: this.duration,
98
- zoomScale: this.zoomScale,
99
- clickEvents: this.clickEvents,
100
- _N$interactable: this._N$interactable,
101
- _N$enableAutoGrayEffect: this._N$enableAutoGrayEffect,
102
- _N$transition: this._N$transition,
103
- transition: this.transition,
104
- _N$normalColor: this._N$normalColor.toJSON(),
105
- _N$pressedColor: this._N$pressedColor.toJSON(),
106
- pressedColor: this.pressedColor.toJSON(),
107
- _N$hoverColor: this._N$hoverColor.toJSON(),
108
- hoverColor: this.hoverColor.toJSON(),
109
- _N$disabledColor: this._N$disabledColor.toJSON(),
110
- _N$normalSprite: this._N$normalSprite,
111
- _N$pressedSprite: this._N$pressedSprite,
112
- pressedSprite: this.pressedSprite,
113
- _N$hoverSprite: this._N$hoverSprite,
114
- hoverSprite: this.hoverSprite,
115
- _N$disabledSprite: this._N$disabledSprite,
116
- _N$target: this._N$target,
117
- _id: this._id
118
- };
119
- }
120
- }
121
-
122
- module.exports = CCButton;
1
+ const CCComponent = require('./CCComponent');
2
+ const CCColor = require('./CCColor');
3
+
4
+ /**
5
+ * Cocos Creator Button 组件
6
+ */
7
+ class CCButton extends CCComponent {
8
+ constructor() {
9
+ super();
10
+ this.__type__ = 'cc.Button';
11
+
12
+ this._normalMaterial = null;
13
+ this._grayMaterial = null;
14
+ this.duration = 0.1;
15
+ this.zoomScale = 1.2;
16
+ this.clickEvents = [];
17
+ this._N$interactable = true;
18
+ this._N$enableAutoGrayEffect = false;
19
+ this._N$transition = 3;
20
+ this.transition = 3;
21
+ this._N$normalColor = new CCColor();
22
+ this._N$pressedColor = new CCColor(200, 200, 200, 255);
23
+ this.pressedColor = new CCColor(200, 200, 200, 255);
24
+ this._N$hoverColor = new CCColor();
25
+ this.hoverColor = new CCColor();
26
+ this._N$disabledColor = new CCColor(120, 120, 120, 200);
27
+ this._N$normalSprite = null;
28
+ this._N$pressedSprite = null;
29
+ this.pressedSprite = null;
30
+ this._N$hoverSprite = null;
31
+ this.hoverSprite = null;
32
+ this._N$disabledSprite = null;
33
+ this._N$target = null;
34
+ }
35
+
36
+ /**
37
+ * 设置缩放
38
+ */
39
+ setZoomScale(scale) {
40
+ this.zoomScale = scale;
41
+ return this;
42
+ }
43
+
44
+ /**
45
+ * 设置过渡类型
46
+ * 0: NONE, 1: COLOR, 2: SPRITE, 3: SCALE
47
+ */
48
+ setTransition(type) {
49
+ this._N$transition = type;
50
+ this.transition = type;
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * 设置正常精灵
56
+ */
57
+ setNormalSprite(uuid) {
58
+ this._N$normalSprite = { __uuid__: uuid };
59
+ return this;
60
+ }
61
+
62
+ /**
63
+ * 设置点击事件
64
+ */
65
+ addClickEvent(component, handler, target = null) {
66
+ this.clickEvents.push({
67
+ target: target,
68
+ component: component,
69
+ handler: handler
70
+ });
71
+ return this;
72
+ }
73
+
74
+ /**
75
+ * 转换为属性面板显示格式
76
+ */
77
+ toPanelJSON() {
78
+ const TRANSITION = ['NONE', 'COLOR', 'SPRITE', 'SCALE'];
79
+ return {
80
+ ...super.toPanelJSON(),
81
+ interactable: this._N$interactable,
82
+ transition: TRANSITION[this._N$transition] || this._N$transition,
83
+ zoomScale: this.zoomScale,
84
+ duration: this.duration
85
+ };
86
+ }
87
+
88
+ toJSON() {
89
+ return {
90
+ __type__: this.__type__,
91
+ _name: this._name,
92
+ _objFlags: this._objFlags,
93
+ node: this.node,
94
+ _enabled: this._enabled,
95
+ _normalMaterial: this._normalMaterial,
96
+ _grayMaterial: this._grayMaterial,
97
+ duration: this.duration,
98
+ zoomScale: this.zoomScale,
99
+ clickEvents: this.clickEvents,
100
+ _N$interactable: this._N$interactable,
101
+ _N$enableAutoGrayEffect: this._N$enableAutoGrayEffect,
102
+ _N$transition: this._N$transition,
103
+ transition: this.transition,
104
+ _N$normalColor: this._N$normalColor.toJSON(),
105
+ _N$pressedColor: this._N$pressedColor.toJSON(),
106
+ pressedColor: this.pressedColor.toJSON(),
107
+ _N$hoverColor: this._N$hoverColor.toJSON(),
108
+ hoverColor: this.hoverColor.toJSON(),
109
+ _N$disabledColor: this._N$disabledColor.toJSON(),
110
+ _N$normalSprite: this._N$normalSprite,
111
+ _N$pressedSprite: this._N$pressedSprite,
112
+ pressedSprite: this.pressedSprite,
113
+ _N$hoverSprite: this._N$hoverSprite,
114
+ hoverSprite: this.hoverSprite,
115
+ _N$disabledSprite: this._N$disabledSprite,
116
+ _N$target: this._N$target,
117
+ _id: this._id
118
+ };
119
+ }
120
+ }
121
+
122
+ module.exports = CCButton;
@@ -1,93 +1,93 @@
1
- const CCComponent = require('./CCComponent');
2
- const CCColor = require('./CCColor');
3
- const CCRect = require('./CCRect');
4
-
5
- /**
6
- * Cocos Creator Camera 组件
7
- */
8
- class CCCamera extends CCComponent {
9
- constructor() {
10
- super();
11
- this.__type__ = 'cc.Camera';
12
-
13
- this._cullingMask = 4294967295;
14
- this._clearFlags = 7;
15
- this._backgroundColor = new CCColor(0, 0, 0, 255);
16
- this._depth = -1;
17
- this._zoomRatio = 1;
18
- this._targetTexture = null;
19
- this._fov = 60;
20
- this._orthoSize = 10;
21
- this._nearClip = 1;
22
- this._farClip = 4096;
23
- this._ortho = true;
24
- this._rect = new CCRect(0, 0, 1, 1);
25
- this._renderStages = 1;
26
- this._alignWithScreen = true;
27
- }
28
-
29
- /**
30
- * 设置正交大小
31
- */
32
- setOrthoSize(size) {
33
- this._orthoSize = size;
34
- return this;
35
- }
36
-
37
- /**
38
- * 设置深度
39
- */
40
- setDepth(depth) {
41
- this._depth = depth;
42
- return this;
43
- }
44
-
45
- /**
46
- * 设置背景颜色
47
- */
48
- setBackgroundColor(r, g, b, a = 255) {
49
- this._backgroundColor.set(r, g, b, a);
50
- return this;
51
- }
52
-
53
- /**
54
- * 转换为属性面板显示格式
55
- */
56
- toPanelJSON() {
57
- return {
58
- ...super.toPanelJSON(),
59
- depth: this._depth,
60
- zoomRatio: this._zoomRatio,
61
- ortho: this._ortho,
62
- orthoSize: this._orthoSize,
63
- backgroundColor: this._backgroundColor ? `#${this._backgroundColor.r.toString(16).padStart(2,'0')}${this._backgroundColor.g.toString(16).padStart(2,'0')}${this._backgroundColor.b.toString(16).padStart(2,'0')}` : '#000000'
64
- };
65
- }
66
-
67
- toJSON() {
68
- return {
69
- __type__: this.__type__,
70
- _name: this._name,
71
- _objFlags: this._objFlags,
72
- node: this.node,
73
- _enabled: this._enabled,
74
- _cullingMask: this._cullingMask,
75
- _clearFlags: this._clearFlags,
76
- _backgroundColor: this._backgroundColor.toJSON(),
77
- _depth: this._depth,
78
- _zoomRatio: this._zoomRatio,
79
- _targetTexture: this._targetTexture,
80
- _fov: this._fov,
81
- _orthoSize: this._orthoSize,
82
- _nearClip: this._nearClip,
83
- _farClip: this._farClip,
84
- _ortho: this._ortho,
85
- _rect: this._rect.toJSON(),
86
- _renderStages: this._renderStages,
87
- _alignWithScreen: this._alignWithScreen,
88
- _id: this._id
89
- };
90
- }
91
- }
92
-
93
- module.exports = CCCamera;
1
+ const CCComponent = require('./CCComponent');
2
+ const CCColor = require('./CCColor');
3
+ const CCRect = require('./CCRect');
4
+
5
+ /**
6
+ * Cocos Creator Camera 组件
7
+ */
8
+ class CCCamera extends CCComponent {
9
+ constructor() {
10
+ super();
11
+ this.__type__ = 'cc.Camera';
12
+
13
+ this._cullingMask = 4294967295;
14
+ this._clearFlags = 7;
15
+ this._backgroundColor = new CCColor(0, 0, 0, 255);
16
+ this._depth = -1;
17
+ this._zoomRatio = 1;
18
+ this._targetTexture = null;
19
+ this._fov = 60;
20
+ this._orthoSize = 10;
21
+ this._nearClip = 1;
22
+ this._farClip = 4096;
23
+ this._ortho = true;
24
+ this._rect = new CCRect(0, 0, 1, 1);
25
+ this._renderStages = 1;
26
+ this._alignWithScreen = true;
27
+ }
28
+
29
+ /**
30
+ * 设置正交大小
31
+ */
32
+ setOrthoSize(size) {
33
+ this._orthoSize = size;
34
+ return this;
35
+ }
36
+
37
+ /**
38
+ * 设置深度
39
+ */
40
+ setDepth(depth) {
41
+ this._depth = depth;
42
+ return this;
43
+ }
44
+
45
+ /**
46
+ * 设置背景颜色
47
+ */
48
+ setBackgroundColor(r, g, b, a = 255) {
49
+ this._backgroundColor.set(r, g, b, a);
50
+ return this;
51
+ }
52
+
53
+ /**
54
+ * 转换为属性面板显示格式
55
+ */
56
+ toPanelJSON() {
57
+ return {
58
+ ...super.toPanelJSON(),
59
+ depth: this._depth,
60
+ zoomRatio: this._zoomRatio,
61
+ ortho: this._ortho,
62
+ orthoSize: this._orthoSize,
63
+ backgroundColor: this._backgroundColor ? `#${this._backgroundColor.r.toString(16).padStart(2,'0')}${this._backgroundColor.g.toString(16).padStart(2,'0')}${this._backgroundColor.b.toString(16).padStart(2,'0')}` : '#000000'
64
+ };
65
+ }
66
+
67
+ toJSON() {
68
+ return {
69
+ __type__: this.__type__,
70
+ _name: this._name,
71
+ _objFlags: this._objFlags,
72
+ node: this.node,
73
+ _enabled: this._enabled,
74
+ _cullingMask: this._cullingMask,
75
+ _clearFlags: this._clearFlags,
76
+ _backgroundColor: this._backgroundColor.toJSON(),
77
+ _depth: this._depth,
78
+ _zoomRatio: this._zoomRatio,
79
+ _targetTexture: this._targetTexture,
80
+ _fov: this._fov,
81
+ _orthoSize: this._orthoSize,
82
+ _nearClip: this._nearClip,
83
+ _farClip: this._farClip,
84
+ _ortho: this._ortho,
85
+ _rect: this._rect.toJSON(),
86
+ _renderStages: this._renderStages,
87
+ _alignWithScreen: this._alignWithScreen,
88
+ _id: this._id
89
+ };
90
+ }
91
+ }
92
+
93
+ module.exports = CCCamera;
@@ -1,54 +1,54 @@
1
- const CCComponent = require('./CCComponent');
2
- const CCSize = require('./CCSize');
3
-
4
- /**
5
- * Cocos Creator Canvas 组件
6
- */
7
- class CCCanvas extends CCComponent {
8
- constructor() {
9
- super();
10
- this.__type__ = 'cc.Canvas';
11
-
12
- this._designResolution = new CCSize(960, 640);
13
- this._fitWidth = false;
14
- this._fitHeight = true;
15
- }
16
-
17
- setProp(props) {
18
- super.setProp(props);
19
- if (props.designResolution) {
20
- this._designResolution = new CCSize(props.designResolution.width, props.designResolution.height);
21
- }
22
- if (props.fitWidth !== undefined) this._fitWidth = props.fitWidth;
23
- if (props.fitHeight !== undefined) this._fitHeight = props.fitHeight;
24
- return this;
25
- }
26
-
27
- getProp() {
28
- return {
29
- ...super.getProp(),
30
- designResolution: {
31
- width: this._designResolution?.width ?? 960,
32
- height: this._designResolution?.height ?? 640
33
- },
34
- fitWidth: this._fitWidth,
35
- fitHeight: this._fitHeight
36
- };
37
- }
38
-
39
- toJSON() {
40
- return {
41
- __type__: this.__type__,
42
- _name: this._name,
43
- _objFlags: this._objFlags,
44
- node: this.node,
45
- _enabled: this._enabled,
46
- _designResolution: this._designResolution.toJSON(),
47
- _fitWidth: this._fitWidth,
48
- _fitHeight: this._fitHeight,
49
- _id: this._id
50
- };
51
- }
52
- }
53
-
54
- module.exports = CCCanvas;
1
+ const CCComponent = require('./CCComponent');
2
+ const CCSize = require('./CCSize');
3
+
4
+ /**
5
+ * Cocos Creator Canvas 组件
6
+ */
7
+ class CCCanvas extends CCComponent {
8
+ constructor() {
9
+ super();
10
+ this.__type__ = 'cc.Canvas';
11
+
12
+ this._designResolution = new CCSize(960, 640);
13
+ this._fitWidth = false;
14
+ this._fitHeight = true;
15
+ }
16
+
17
+ setProp(props) {
18
+ super.setProp(props);
19
+ if (props.designResolution) {
20
+ this._designResolution = new CCSize(props.designResolution.width, props.designResolution.height);
21
+ }
22
+ if (props.fitWidth !== undefined) this._fitWidth = props.fitWidth;
23
+ if (props.fitHeight !== undefined) this._fitHeight = props.fitHeight;
24
+ return this;
25
+ }
26
+
27
+ getProp() {
28
+ return {
29
+ ...super.getProp(),
30
+ designResolution: {
31
+ width: this._designResolution?.width ?? 960,
32
+ height: this._designResolution?.height ?? 640
33
+ },
34
+ fitWidth: this._fitWidth,
35
+ fitHeight: this._fitHeight
36
+ };
37
+ }
38
+
39
+ toJSON() {
40
+ return {
41
+ __type__: this.__type__,
42
+ _name: this._name,
43
+ _objFlags: this._objFlags,
44
+ node: this.node,
45
+ _enabled: this._enabled,
46
+ _designResolution: this._designResolution.toJSON(),
47
+ _fitWidth: this._fitWidth,
48
+ _fitHeight: this._fitHeight,
49
+ _id: this._id
50
+ };
51
+ }
52
+ }
53
+
54
+ module.exports = CCCanvas;
@@ -1,32 +1,32 @@
1
- /**
2
- * Cocos Creator 颜色类
3
- */
4
- class CCColor {
5
- constructor(r = 255, g = 255, b = 255, a = 255) {
6
- this.__type__ = 'cc.Color';
7
- this.r = r;
8
- this.g = g;
9
- this.b = b;
10
- this.a = a;
11
- }
12
-
13
- set(r, g, b, a = 255) {
14
- this.r = r;
15
- this.g = g;
16
- this.b = b;
17
- this.a = a;
18
- return this;
19
- }
20
-
21
- toJSON() {
22
- return {
23
- __type__: this.__type__,
24
- r: this.r,
25
- g: this.g,
26
- b: this.b,
27
- a: this.a
28
- };
29
- }
30
- }
31
-
32
- module.exports = CCColor;
1
+ /**
2
+ * Cocos Creator 颜色类
3
+ */
4
+ class CCColor {
5
+ constructor(r = 255, g = 255, b = 255, a = 255) {
6
+ this.__type__ = 'cc.Color';
7
+ this.r = r;
8
+ this.g = g;
9
+ this.b = b;
10
+ this.a = a;
11
+ }
12
+
13
+ set(r, g, b, a = 255) {
14
+ this.r = r;
15
+ this.g = g;
16
+ this.b = b;
17
+ this.a = a;
18
+ return this;
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ __type__: this.__type__,
24
+ r: this.r,
25
+ g: this.g,
26
+ b: this.b,
27
+ a: this.a
28
+ };
29
+ }
30
+ }
31
+
32
+ module.exports = CCColor;